Project

General

Profile

Actions

Bug #32573

closed

locallangXMLOverride is broken since the switch to XLIFF

Added by Lars no-lastname-given almost 13 years ago. Updated almost 13 years ago.

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

100%

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

Description

Since TYPO3 4.6 the locallangXMLOverride mechanism does not work like before v4.6. There are some issues while loading translations from XML files, e.g. the target language will be mixed with the default language.

I use the following line oh php code to configure the override in a localconf-file:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['path/to/originalTranslationFile.xml'][] = 'path/to/otherTranslationFile.xml'

The content of the original translation file "originalTranslationFile.xml" is this:

    <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
    <T3locallang>
        <data type="array">
            <languageKey index="default" type="array">
                <label index="test_label_one">one (default)</label>
                <label index="test_label_two">two (default)</label>
            </languageKey>

            <languageKey index="de" type="array">
                <label index="test_label_one">eins (german)</label>
                <label index="test_label_two">zwei (german)</label>
            </languageKey>
        </data>
    </T3locallang>

The content of the translation file "otherTranslationFile.xml", which is used to override translations, is this:

    <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
    <T3locallang>
        <data type="array">
            <languageKey index="fr" type="array">
                <label index="test_label_one">une (française)</label>
            </languageKey>
        </data>
    </T3locallang>

My testcase in typoscript is something like this, it only outputs two translations via the TS-TEXT object:

    config {
        linkVars = L
        sys_language_uid = 0
        language = en
        locale_all = en_EN.UTF-8
        htmlTag_langKey = en
    }

    # DE
    [globalVar=GP:L=1]
        config {
            sys_language_uid = 1
            language = de
            locale_all = de_DE.UTF-8
            htmlTag_langKey = de
        }
    [global]

    # FR
    [globalVar = GP:L = 2]
        config {
            sys_language_uid = 2
            language = fr
            locale_all = fr_FR.UTF-8
            htmlTag_langKey = fr
        }
    [global]

    page = PAGE
    page.typeNum = 0

    page.10 = TEXT
    page.10.data = LLL:path/to/originalTranslationFile.xml:test_label_one
    page.10.wrap = | <br />

    page.20 = TEXT
    page.20.data = LLL:path/to/originalTranslationFile.xml:test_label_two

The output in english (the default language) is this:

une (française) // << that's wrong! It must be "one (default)"
two (default)

In german:

une (française) // << that's wrong! It must be "eins (german)"
zwei (german)

In french:

une (française)
two (default)

Also do tests with this "otherTranslationFile.xml" files:
otherTranslationFile V2:

    <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
    <T3locallang>
        <data type="array">
            <languageKey index="default" type="array">
                <label index="test_label_one">one (default NEW)</label>
                <label index="test_label_two">two (default NEW)</label>
            </languageKey>

            <languageKey index="de" type="array">
                <label index="test_label_one">eins (german NEW)</label>
            </languageKey>

            <languageKey index="fr" type="array">
                <label index="test_label_one">une (française)</label>
            </languageKey>
        </data>
    </T3locallang>

otherTranslationFile V3:

    <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
    <T3locallang>
        <data type="array">
            <languageKey index="default" type="array">
                <label index="test_label_two">two (default NEW)</label>
            </languageKey>

            <languageKey index="de" type="array">
                <label index="test_label_one">eins (german NEW)</label>
            </languageKey>

            <languageKey index="fr" type="array">
                <label index="test_label_one">une (française)</label>
            </languageKey>
        </data>
    </T3locallang>

After a lot of debugging i had replace the body of method "t3lib_l10n_parser_Llxml::doParsingFromRootForElement" with this:

    protected function doParsingFromRootForElement(SimpleXMLElement $root, $element) {
        $bodyOfFileTag = $root->data->languageKey;

            // Check if the source llxml file contains localized records
        $localizedBodyOfFileTag = $root->data->xpath("languageKey[@index='" . $this->languageKey . "']");
        if ($element === 'target' && count($localizedBodyOfFileTag) === 0)
            return array();

        $parsedData = $this->getParsedDataForElement($bodyOfFileTag, $element);
        if ($element === 'source')
            return $parsedData;

        if ($element === 'target' && isset($localizedBodyOfFileTag[0]) && $localizedBodyOfFileTag[0] instanceof SimpleXMLElement) {
            $parsedTargetData = $this->getParsedDataForElement($localizedBodyOfFileTag[0], $element);
            $mergedData = array_merge($parsedData, $parsedTargetData);

            if ($this->languageKey === 'default') {
                foreach (array_keys($mergedData) as $key) {
                    if (!isset($parsedData[$key])) {
                        unset($mergedData[$key]);
                    }
                }
            } else {
                foreach (array_keys($mergedData) as $key) {
                    if (!isset($parsedTargetData[$key])) {
                        unset($mergedData[$key]);
                    }
                }
            }

            return $mergedData;
        }

        return $parsedData;
    }

This does work for my test cases very well, but i can imagine that there is a better way then unset all unneeded keys.

i also do a little optimization if the method was loading the translations for $element = 'source'.

Actions

Also available in: Atom PDF