[TASK] Add support for English XLIFF template files
authorDominique Feyer <dominique.feyer@reelpeek.net>
Mon, 17 Oct 2011 19:50:13 +0000 (21:50 +0200)
committerXavier Perseguers <xavier@typo3.org>
Tue, 18 Oct 2011 13:40:53 +0000 (15:40 +0200)
Currently the XLIFF files provided with the Core are "en" -> "en" translation files,
and this is a wrong design.

English XLIFF files must be template files (XLIFF files without target element) and
as such, the parser needs to be adjusted not to return an empty label.

Change-Id: I7181872ebd9ff7a89ec66558aa6de9a9608f72c7
Resolves: #30916
Releases: 4.6
Reviewed-on: http://review.typo3.org/5914
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Björn Pedersen
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
t3lib/l10n/parser/class.t3lib_l10n_parser_xliff.php

index 4d70503..30259d8 100644 (file)
@@ -48,11 +48,19 @@ class t3lib_l10n_parser_Xliff extends t3lib_l10n_parser_AbstractXml {
                        if ($translationElement->getName() === 'trans-unit' && !isset($translationElement['restype'])) {
                                        // If restype would be set, it could be metadata from Gettext to XLIFF conversion (and we don't need this data)
 
-                                       // @todo Support "approved" attribute
-                               $parsedData[(string)$translationElement['id']][0] = array(
-                                       'source' => (string)$translationElement->source,
-                                       'target' => (string)$translationElement->target,
-                               );
+                               if ($this->languageKey === 'default') {
+                                               // Default language coming from an XLIFF template (no target element)
+                                       $parsedData[(string)$translationElement['id']][0] = array(
+                                               'source' => (string)$translationElement->source,
+                                               'target' => (string)$translationElement->source,
+                                       );
+                               } else {
+                                               // @todo Support "approved" attribute
+                                       $parsedData[(string)$translationElement['id']][0] = array(
+                                               'source' => (string)$translationElement->source,
+                                               'target' => (string)$translationElement->target,
+                                       );
+                               }
                        } elseif ($translationElement->getName() === 'group' && isset($translationElement['restype']) && (string)$translationElement['restype'] === 'x-gettext-plurals') {
                                        // This is a translation with plural forms
                                $parsedTranslationElement = array();
@@ -62,11 +70,19 @@ class t3lib_l10n_parser_Xliff extends t3lib_l10n_parser_AbstractXml {
                                                        // When using plural forms, ID looks like this: 1[0], 1[1] etc
                                                $formIndex = substr((string)$translationPluralForm['id'], strpos((string)$translationPluralForm['id'], '[') + 1, -1);
 
-                                                       // @todo Support "approved" attribute
-                                               $parsedTranslationElement[(int)$formIndex] = array(
-                                                       'source' => (string)$translationPluralForm->source,
-                                                       'target' => (string)$translationPluralForm->target,
-                                               );
+                                               if ($this->languageKey === 'default') {
+                                                               // Default language come from XLIFF template (no target element)
+                                                       $parsedTranslationElement[(int)$formIndex] = array(
+                                                               'source' => (string)$translationPluralForm->source,
+                                                               'target' => (string)$translationPluralForm->source,
+                                                       );
+                                               } else {
+                                                               // @todo Support "approved" attribute
+                                                       $parsedTranslationElement[(int)$formIndex] = array(
+                                                               'source' => (string)$translationPluralForm->source,
+                                                               'target' => (string)$translationPluralForm->target,
+                                                       );
+                                               }
                                        }
                                }