You are here

function _svg_embed_translate in SVG Embed 7

Helper function called recursively to translate all strings in an SVG file.

Parameters

SimpleXMLElement $xml: the SVG graphic code

string $langcode: the language code to which we need to translate

1 call to _svg_embed_translate()
_svg_embed_get_svg in ./svg_embed.module
Helper function to read the SCG, localise it and prepare it for output.

File

./svg_embed.module, line 316
SVG Embed. Provides a filter for text formats that includes and on the fly translates SVG files into text fields.

Code

function _svg_embed_translate($xml, $langcode) {
  foreach ($xml as $child) {
    _svg_embed_translate($child, $langcode);
    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)) {
          $query = db_select('locales_source', 's');
          $query
            ->leftJoin('locales_target', 't', 's.lid = t.lid');
          $translation = $query
            ->fields('t', array(
            'translation',
          ))
            ->condition('s.source', $string)
            ->condition('s.textgroup', 'svg_embed')
            ->condition('t.language', $langcode)
            ->execute()
            ->fetchField();
          $text[$i][0] = empty($translation) ? $string : $translation;
        }
        $i++;
      }
    }
  }
}