Problem/Motivation

In version 1.4.34 long HTML text fields do not contain their text value after the translation. Debugging shows, that in the functions translateHtmlWithAdvancedMethod and translateHtmlWithSimpleMethod the condition
elseif (isset($match[2])) { can never be reached. The whole condition is:

if (isset($match[1])) {
  // HTML tag - keep as is
  $result .= $match[1];
} elseif (isset($match[2])) {
  // Text content - replace with translation if available
  if (isset($segment_mapping[$index])) {
 $segment_idx = $segment_mapping[$index];
  $segment = $segments[$segment_idx];
   $translated = $translated_segments[$segment_idx];
  .......

The required logic is to check if $match[1] is empty, not if it exists. If $match[2] is set, then $match[1] always exists too. Therefore the code in the elseif condition which appends the text to the result is never executed.

Proposed resolution

Replace isset($match[1]) with !empty($match[1])
I am attaching a corresponding patch.

Comments

martin mayer created an issue. See original summary.

bigbabert’s picture

Status: Active » Needs review

Hi @martin mayer,

this is alredy fixed in 1.5.0 (could you confirm?) that is new stable release candidate, so 1.4.x will be dismissed.

Best regards

martin mayer’s picture

I tested auto_translation 1.5 beta. It did not translate the HTML text. The text remained in the original language. So I had to revert to 1.4.34 and apply the patch to it. In that version it works again.

  • bigbabert committed a327fca0 on 1.0.x
    Issue #3538533 by martin mayer: In 1.4.34 HTML fields return an empty...
bigbabert’s picture

Version: 1.4.34 » 1.4.35
Status: Needs review » Fixed

Hi @martin mayer,

thanks to review, added the fix to both versions 1.4.x and 1.5.x.

Thanks for the contribution.

Best regards

bigbabert’s picture

Status: Fixed » Closed (fixed)