Project

General

Profile

Actions

Bug #31141

closed

Pootle: Multi-line labels are not rendered properly

Added by Xavier Perseguers over 12 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Must have
Category:
-
Target version:
Start date:
2011-10-20
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
4.6
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Problematic

While trying to fix the multi-line label issue with #31109, we found out that the XLIFF localization files missed an additional property

xml:space="preserve" 

to ask Pootle to preserve whitespaces (including new lines). The documentation states that having this attribute on the <file> element is valid for the whole file.

However, it turns out that this work (partially) only for new projects. For existing ones, the "update" is not performed. So instead this attribute should be put on the <trans-unit> element. In order to prevent side effect with developers forgetting to set this attribute, we prefer having this attribute on each and every <trans-unit> element, even if it is not (yet?) used by the underlying label. In addition, the synchronization script on the translation server will make sure to add this attribute on-the-fly whenever it is missing.

Having it set in TYPO3 Core ensures that external tools will stick to preserving white spaces, which would not be the case if the fix was only done on the translation server.

Solution

What should be done:

1) for each and every XLF localization file, remove any existing xml:space attribute and add it to each and every <trans-unit> element:

xmlstarlet ed -d "/xliff/file[@xml:space]/@xml:space" locallang.xlf \
    | xmlstarlet ed -d "/xliff/file/body/trans-unit[@xml:space]/@xml:space" 
    |  xmlstarlet ed --insert "/xliff/file/body/trans-unit" --type attr -n xml:space -v preserve

2) Reindent the file by making sure the </source> attribute is not on a separate line:

xmlindent -t -nbe locallang.xlf

3) Fix additional multi-line label's indent introduced by xmlindent with the lookahead regular expression already used by #31109#note-4:

Search for: ^\t+(?![<\t])
Replace by:
For: *.xlf

4) Remove empty lines at the end of the label, whenever it exists with regular expression

Command Summary

$ cd /path/to/TYPO3_master
$ for f in $(find . -name \*.xlf); do \
      xmlstarlet ed -d "/xliff/file[@xml:space]/@xml:space" $f | \
      xmlstarlet ed -d "/xliff/file/body/trans-unit[@xml:space]/@xml:space" | \
      xmlstarlet ed --insert "/xliff/file/body/trans-unit" --type attr -n xml:space -v preserve | \
      xmlindent -t -nbe > $f.new;
      mv $f.new $f
done

In PhpStorm

  • Use the lookahead regular expression ^\t+(?![<\t]) to remove extra tabs in multi-line labels (1801 occurences replaced)
  • Use regular expression <source>\n\t* to prevent labels from starting with an empty line (~10 occurences replaced)
  • Use regular expression \n\t+</source> to replace </source> elements on their own line and put them at the end of the label instead (563 occurences replaced)

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #31109: XLIFF: Indent with new lines causes invalid outputClosedXavier Perseguers2011-10-19

Actions
Actions #1

Updated by Mr. Hudson over 12 years ago

  • Status changed from New to Under Review

Patch set 1 of change I74dbf92196b649b96023b329eb12ad98dac7be49 has been pushed to the review server.
It is available at http://review.typo3.org/6121

Actions #2

Updated by Xavier Perseguers over 12 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #3

Updated by Riccardo De Contardi over 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF