<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Detect type of field in translator implementation</title>
  <link rel="self" href="https://liferay.dev/de/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121905923" />
  <subtitle>Detect type of field in translator implementation</subtitle>
  <id>https://liferay.dev/de/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121905923</id>
  <updated>2026-06-21T18:23:18Z</updated>
  <dc:date>2026-06-21T18:23:18Z</dc:date>
  <entry>
    <title>Detect type of field in translator implementation</title>
    <link rel="alternate" href="https://liferay.dev/de/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121905922" />
    <author>
      <name>Matthias Bläsing</name>
    </author>
    <id>https://liferay.dev/de/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121905922</id>
    <updated>2023-07-07T01:32:45Z</updated>
    <published>2023-07-06T06:17:17Z</published>
    <summary type="html">&lt;p&gt;While fixing a problem in the DeepL translator and then testing the
  fix in our staging environment I noticed a problem in the translator
  integration. DeepL has special modes to handle XML and HTML. If they
  are not used, you can get broken output for HTML text.&lt;/p&gt;
&lt;p&gt;Consider this input:&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;{
    &amp;quot;tag_handling&amp;quot;: &amp;quot;html&amp;quot;,
    &amp;quot;text&amp;quot;: [
        &amp;quot;&amp;lt;h4&amp;gt;AAAA-Bahn-Nutzung&amp;lt;/h4&amp;gt;\n&amp;lt;p&amp;gt;Zusammen mit einem amtlichen Lichtbildausweis kann YYYYY als Berechtigung zur Nutzung der AAAAA-Bahn genutzt werden.&amp;lt;/p&amp;gt;&amp;quot;
    ],
    &amp;quot;source_lang&amp;quot;: &amp;quot;de&amp;quot;,
    &amp;quot;target_lang&amp;quot;: &amp;quot;en&amp;quot;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Without the flag &amp;quot;tag_handling&amp;quot; you'll get this:&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-javascript"&gt;{
    &amp;quot;translations&amp;quot;: [
        {
            &amp;quot;detected_source_language&amp;quot;: &amp;quot;DE&amp;quot;,
            &amp;quot;text&amp;quot;: &amp;quot;&amp;lt;h4&amp;gt;AAAA Railroad Use&amp;lt;/h4&amp;gt;.\n&amp;lt;p&amp;gt;When used in conjunction with a government-issued photo ID, YYYY may be used as authorization to use the AAAAA railroad.&amp;lt;/p&amp;gt;&amp;quot;
        }
    ]
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With that flag you'll get:&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-javascript"&gt;{
    &amp;quot;translations&amp;quot;: [
        {
            &amp;quot;detected_source_language&amp;quot;: &amp;quot;DE&amp;quot;,
            &amp;quot;text&amp;quot;: &amp;quot;&amp;lt;h4&amp;gt;AAAA-Bahn use&amp;lt;/h4&amp;gt;\n&amp;lt;p&amp;gt;Together with an official photo ID, YYYY can be used as authorization to use the AAAAA-Bahn.&amp;lt;/p&amp;gt;&amp;quot;
        }
    ]
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem is not easy to spot, you'll have to have a look at the
  end of the h4 Tag. Without the tag_handling info, an additonal
  fullstop is inserted after the closing tag. It would be ok, if the
  fullstop inside the element, but this way the html structure is damaged.&lt;/p&gt;
&lt;p&gt;I extracted this into standalone sample, but the same situation
  happens inside liferay when you try to translate a field with html content.&lt;/p&gt;
&lt;p&gt;The TranslatorPacket passed to does not hold enough information to
  decide. At this point I think the only option is to detect html tags
  by searching for &amp;quot;closing&amp;quot; tags and use that to switch to
  html mode.&lt;/p&gt;
&lt;p&gt;Question 1: So does anyone have ideas?&lt;br&gt; ​​​​​​​Question 2: Please
  create a tracking issue for this.&lt;/p&gt;</summary>
    <dc:creator>Matthias Bläsing</dc:creator>
    <dc:date>2023-07-06T06:17:17Z</dc:date>
  </entry>
</feed>
