I tried to export in both html and xlf.

HTML returned blank translations after replacing text (or what else should I do?!).

XLF returned xml formatted text. Example:

Imported xlf file source text:
<source xml:lang="en">&lt;p&gt;&lt;strong&gt;PAYMENT METHODS&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Online&amp;nbsp;with Paypal&lt;/p&gt; &lt;ul&gt; &lt;li&gt;all major electronic cards&lt;/li&gt; &lt;li&gt;immediate processing&lt;/li&gt; &lt;li&gt;secure &amp;amp;&amp;nbsp;guaranteed&lt;/li&gt; &lt;li&gt;no additional costs&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;​Offline&amp;nbsp;with Cash on Delivery (COD)&lt;/p&gt; &lt;ul&gt; &lt;li&gt;pay the courier at your door&lt;/li&gt; &lt;li&gt;extra charge of 5€ at checkout&lt;/li&gt; &lt;/ul&gt;</source>

Imported xlf file target text (note that there is no difference apart from pure translation):
<target xml:lang="it" state="translated">&lt;p&gt;&lt;strong&gt;METODI DI PAGAMENTO&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Online con Paypal&lt;/p&gt; &lt;ul&gt; &lt;li&gt;tutte le principali carte elettroniche&lt;/li&gt; &lt;li&gt;elaborazione immediata&lt;/li&gt; &lt;li&gt;sicuro e garantito&lt;/li&gt; &lt;li&gt;nessun costo aggiuntivo&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;​OOffline con contrassegno&lt;/p&gt; &lt;ul&gt; &lt;li&gt;paga il corriere alla consegna&lt;/li&gt; &lt;li&gt;costo aggiuntivo di 5€ alla cassa&lt;/li&gt; &lt;/ul&gt;</target>

Returned this on translator interface:
Source:

<p><strong>DELIVERY&nbsp;INFO</strong></p>
<p>Ready to ship in 7 days.</p>
<ul>
	<li>Express courier</li>
	<li>1-2 days in Europe</li>
	<li>Live tracking</li>
</ul>

Translation:
&lt;p&gt;&lt;strong&gt;CONSEGNA&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Pronto per la spedizione in 7 giorni&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Corriere espresso&lt;/li&gt; &lt;li&gt;1-2 giorni in Europa&lt;/li&gt; &lt;li&gt;Tracciamento in tempo reale&lt;/li&gt; &lt;/ul&gt;

And this on translated product display (I mean, html tags are shown to the user!):
<p><strong>CONSEGNA</strong></p> <p>Pronto per la spedizione in 7 giorni</p> <ul> <li>Corriere espresso</li> <li>1-2 giorni in Europa</li> <li>Tracciamento in tempo reale</li> </ul>

I am working with entity translation, and of course trying to translate a Filtered html text.

Also, the workflow is not efficient at all in XLF manual translation because the target tag is not prepopulated! If it was, we could just replace all text at once with a text editor like Sublime Text 2.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kopeboy’s picture

Issue summary: View changes
kopeboy’s picture

Issue summary: View changes
Matroschker’s picture

It seems this is the same as my new item (https://drupal.org/node/2279265) - I created today, sorry!

You can work around us (at least for XLIFF) if enabling 'Extended XLIFF processing', but in this case I got problems with my image tags - it seems that some free XLIFF tools doesn't support this. The result is, that my images disappear on my page after accepting.

Matroschker

Matroschker’s picture

Any update here?
I checked this issue again with
TMGMT: Last updated: June 27, 2014 - 18:13, Last packaged version: 7.x-1.0-rc1+7-dev

If 'Extended XLIFF processing' is disabled, if translation was imported the HTML tags are shown to the user not the interpreted html code.
If 'Extended XLIFF processing' is enabled, the HTML code is well interpreted, but now my images are moved to another place on the site, eg if the image was within a table, now it is outside.

That means: no changes

Matroschker

dasginganinja’s picture

Subscribing. I've got the same issue going on. I'm thinking about creating my own module that extends the file translator plugin and just decodes the entities to get around it. I guess the real question is what is the proper way of doing this in the long run?

molenick’s picture

+1

jonnydev13’s picture

I'm still seeming to have this issue.

When I try to import an xliff file after creating a job in xliff and translating it, it just tells me there was an error with no more details about what the error was.

When I try to import an html file after creating a job in html and translating it, it says it succeeds but the translated page has no content when I try to review it. This is probably a different issue, but the translated content was part of a drupal book and both the original and the translated one now show up in the book outline.

Is there anybody who has done coding on this module who can give any direction to all of the people on this thread?

dragonfire353’s picture

Here's a quick fix for new translation imports for 7.x1.0-rc1.

Add this to entity/tmgmt.entity.job_item.inc on line 630 or if that isn't right in function addTranslatedDataRecursive near the end before $this->updateData:

$values['#translation']['#text'] = str_replace('&lt;', '<', $values['#translation']['#text']);
$values['#translation']['#text'] = str_replace('&gt;', '>', $values['#translation']['#text']);

Again, quick fix so use at your own risk.

Bram Tassyns’s picture

We also had this problem for html export.
I fixed our issues by changing the import function in tmgmt_file.format.html
(basically, don't just take the text content, but convert all encountered elements back to xml as well)

public function import($imported_file) {
    $dom = new DOMDocument();
    $dom->preserveWhiteSpace = true;
    $dom->formatOutput = false;
    $dom->loadHTMLFile($imported_file);
    $xpath = new DOMXPath($dom);

    $data = array();
    foreach ($xpath->query("//div[@class='atom']") as $atom) {
      // Assets are our strings (eq fields in nodes).
      $key = $this->decodeIdSafeBase64((string) $atom->getAttribute('id'));
      // The content of the node might include html so we need all children
      // (not just the text content).
      $content='';
      foreach($atom->childNodes as $child) {
        $content .= $child->ownerDocument->saveXML($child);
      }
      // Compensate for DOM's conversion of the '\r' part of windows line endings.
      $content = str_replace('&#13;',"\r", $content);
      $data[$key]['#text'] = (string) $content;
    }
    return tmgmt_unflatten_data($data);
  }
Say_Ten’s picture

Same issue here and the same solution with html_entities_decode(). My concern would be if there's import systems that don't mess it up, would this function be aware or should it be handled in the XLIFF file_format code?

Leksat’s picture

Status: Active » Needs review
FileSize
660 bytes

The following works well for many of our company clients since middle 2015:

 -      return $translation;
 +      return decode_entities($translation);

We had no issues with this code.

Leksat’s picture

Just found that #2279265: Without 'Extended XLIFF processing' review shows eg '&lt;' instead of '<' has the same patch, but not sure which issue should be marked as duplicate :/

sri@re’s picture

Hi am new to drupal .I just select file translator and i import html file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="de-CH" lang="de-CH" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="JobID" content="3" />
    <meta name="languageSource" content="en" />
    <meta name="languageTarget" content="zh-hans" />

    <title>Job ID 3</title>
  </head>
  <body>
          <div class="asset" id="3">
                  <div class="atom" id="bM11bbm9kZV90aXRsZQ">szdfszcs</div>
              </div>
      </body>
</html>

but am getting this error "Failed to validate file, import aborted. " can anyone please clarify?

Kristen Pol’s picture

Tried code in #9 above and it didn't work in my case so I used this which is a bit hacky and could be better but seems to work so we can keep moving:

  /**
   * {@inheritdoc}
   */
  public function import($imported_file) {
    $dom = new DOMDocument();
    $dom->loadHTMLFile($imported_file);
    $xml = simplexml_import_dom($dom);
    $data = array();
    foreach ($xml->xpath("//div[@class='atom']") as $atom) {
      // Assets are our strings (eq fields in nodes).
      $key = $this->decodeIdSafeBase64((string) $atom['id']);
      // This is for plain text.
      $content = (string) $atom;
      foreach ($atom->children() as $child) {
        // This is for HTML.
        $content .= $child->asXML();
      }
      // Get rid of some Windows characters.
      $content = str_replace('&#13;', '', $content);
      $content = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $content);
      $data[$key]['#text'] = $content;
    }
    return tmgmt_unflatten_data($data);
  }

lobodakyrylo’s picture

Code #9 and #14 don't work for RC3

This is my code:

/**
   * {@inheritdoc}
   */
  public function import($imported_file, $is_file = TRUE) {
    $dom = new DOMDocument();
    $dom->loadHTMLFile($imported_file);
    $xml = simplexml_import_dom($dom);

    $data = array();
    foreach ($xml->xpath("//div[@class='atom']") as $atom) {
      // Assets are our strings (eq fields in nodes).
      $key = $this->decodeIdSafeBase64((string) $atom['id']);
      
      // This is for plain text.
      $content = (string) $atom;
      foreach ($atom->children() as $child) {
        // This is for HTML.
        $content .= $child->asXML();
      }
      // Get rid of some Windows characters.
      $content = str_replace('&#13;', '', $content);
      $content = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $content);
      $data[$key]['#text'] = $content;
    }
    return tmgmt_unflatten_data($data);
  }
liberatr’s picture

Here is a version of the last comment as a patch.

liberatr’s picture

NOTE if your translated content contains CSS in a style tag you will get output like this:

<style type="text/css"><![CDATA[.some-css-selector{
    display: inline-block;
    width: 100%;
  }
  ]]></style>

Fix (if this matters to you):
$content = str_replace(array('<![CDATA[', ']]>'), '', $content);

liberatr’s picture

Status: Needs review » Reviewed & tested by the community