src/Serializer.php
protected function addTransUnit($key, $element, $targetLang) {
    $this->startElement('xlf:group');
    $this->writeAttribute('id', $key);
    $this->writeAttribute('resname', $key);
    $this->writeAttribute('restype', 'x-eggs-n-cereal-field');

    //escape named html entities prior to conversion
    $list = get_html_translation_table(HTML_ENTITIES);
    $namedTable = array();
    foreach($list as $k=>$v){
      $namedTable[$v]= "&amp;".str_replace('&', '',$v);
    }
    $element['#text'] = strtr($element['#text'], $namedTable);

    try {
      $converter = new Converter($element['#text'], $this->sourceLang, $targetLang);
      if ($this->logger) {
        $converter->setLogger($this->logger);
      }
      $this->writeRaw($converter->toXLIFF());
    }
    catch (\Exception $e) {
      $this->startElement('trans-unit');
      $this->writeAttribute('id', uniqid('text-'));
      $this->writeAttribute('restype', 'x-eggs-n-cereal-failure');
      $this->startElement('source');
      $this->writeAttribute('xml:lang', $this->sourceLang);
      $this->text($element['#text']);
      $this->endElement();

      $this->startElement('target');
      $this->writeAttribute('xml:lang', $targetLang);
      $this->text($element['#text']);
      $this->endElement();
      $this->endElement();
    }
    if (isset($element['#label'])) {
      $this->writeElement('note', $element['#label']);
    }
    $this->endElement();
  }
protected function addTransUnit($key, $element, $targetLang) {
    $this->startElement('xlf:group');
    $this->writeAttribute('id', $key);
    $this->writeAttribute('resname', $key);
    $this->writeAttribute('restype', 'x-eggs-n-cereal-field');

    //escape named html entities prior to conversion
    $list = get_html_translation_table(HTML_ENTITIES);
    $namedTable = array();
    foreach($list as $k=>$v){
      $namedTable[$v]= "&amp;".str_replace('&', '',$v);
    }
    $element['#text'] = strtr($element['#text'], $namedTable);

    try {
      $converter = new Converter($element['#text'], $this->sourceLang, $targetLang);
      if ($this->logger) {
        $converter->setLogger($this->logger);
      }
      $this->writeRaw($converter->toXLIFF());
    }
    catch (\Exception $e) {
      $this->startElement('trans-unit');
      $this->writeAttribute('id', uniqid('text-'));
      $this->writeAttribute('restype', 'x-eggs-n-cereal-failure');
      $this->startElement('source');
      $this->writeAttribute('xml:lang', $this->sourceLang);
      $this->text($element['#text']);
      $this->endElement();

      $this->startElement('target');
      $this->writeAttribute('xml:lang', $targetLang);
      $this->text($element['#text']);
      $this->endElement();
      $this->endElement();
    }
    if (isset($element['#label'])) {
      $this->writeElement('note', $element['#label']);
    }
    $this->endElement();
  }
protected function addTransUnit ( $ key , $ element , $ targetLang ) { $ this -> startElement ( 'xlf:group' ) ; $ this -> writeAttribute ( 'id' , $ key ) ; $ this -> writeAttribute ( 'resname' , $ key ) ; $ this -> writeAttribute ( 'restype' , 'x-eggs-n-cereal-field' ) ; //escape named html entities prior to conversion $ list = get_html_translation_table ( HTML_ENTITIES ) ; $ namedTable = array ( ) ; foreach ( $ list as $ k => $ v ) { $ namedTable [ $ v ] = "&amp;" . str_replace ( '&' , '' , $ v ) ; } $ element [ '#text' ] = strtr ( $ element [ '#text' ] , $ namedTable ) ; try { $ converter = new Converter ( $ element [ '#text' ] , $ this -> sourceLang , $ targetLang ) ; if ( $ this -> logger ) { $ converter -> setLogger ( $ this -> logger ) ; } $ this -> writeRaw ( $ converter -> toXLIFF ( ) ) ; } catch ( \ Exception $ e ) { $ this -> startElement ( 'trans-unit' ) ; $ this -> writeAttribute ( 'id' , uniqid ( 'text-' ) ) ; $ this -> writeAttribute ( 'restype' , 'x-eggs-n-cereal-failure' ) ; $ this -> startElement ( 'source' ) ; $ this -> writeAttribute ( 'xml:lang' , $ this -> sourceLang ) ; $ this -> text ( $ element [ '#text' ] ) ; $ this -> endElement ( ) ; $ this -> startElement ( 'target' ) ; $ this -> writeAttribute ( 'xml:lang' , $ targetLang ) ; $ this -> text ( $ element [ '#text' ] ) ; $ this -> endElement ( ) ; $ this -> endElement ( ) ; } if ( isset ( $ element [ '#label' ] ) ) { $ this -> writeElement ( 'note' , $ element [ '#label' ] ) ; } $ this -> endElement ( ) ; }
Adds a single translation unit for a data element.

@param string $key
The unique identifier for this data element.

@param string $element
An element array with the following properties:
- #text: The text string to be translated.
- #label: (Optional) Label, intended for translators, that provides more
context around the translated string.

@param string $targetLang
The target language of the translatable.

@return string
The generated XML.
Adds a single translation unit for a data element .