function _svg_embed_extract in SVG Embed 7
Helper function to find all strings and all their existing translations, prepared to export all to a po file.
Parameters
SimpleXMLElement $xml: the svg graphic code
array $strings: array containing all strings and translations
1 call to _svg_embed_extract()
- svg_embed_manage_po_files in ./
svg_embed.module - Form to download and upload PO files for embedded SVG files.
File
- ./
svg_embed.module, line 361 - SVG Embed. Provides a filter for text formats that includes and on the fly translates SVG files into text fields.
Code
function _svg_embed_extract($xml, &$strings) {
$all_languages = language_list('enabled');
$languages = array_shift($all_languages);
foreach ($xml as $child) {
_svg_embed_extract($child, $strings);
if (isset($child->text) || isset($child->tspan)) {
if (isset($child->text->tspan)) {
$text = $child->text->tspan;
}
elseif (isset($child->tspan)) {
$text = $child->tspan;
}
else {
$text = $child->text;
}
$i = 0;
while (TRUE) {
$string = (string) $text[$i];
if (empty($string)) {
break;
}
$string = trim($string);
if (!empty($string)) {
if (empty($strings[$string])) {
$strings[$string] = array();
foreach ($languages as $langcode => $language) {
$strings[$string][$langcode] = '';
}
$query = db_select('locales_source', 's');
$query
->leftJoin('locales_target', 't', 's.lid = t.lid');
$translations = $query
->fields('t', array(
'translation',
'language',
))
->condition('s.source', $string)
->condition('s.textgroup', 'svg_embed')
->condition('t.language', 'en', '<>')
->execute()
->fetchAll();
foreach ($translations as $translation) {
$strings[$string][$translation->language] = $translation->translation;
}
}
}
$i++;
}
}
}
}