Bug #86156
closedCMS 8:When using inlineLanguageLabelFiles and a different default language than english, only the default language is usable
0%
Description
This is an issue that i found in CMS 8.7.
The feature I am using was introduced with:
https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.5/Feature-57632-AddInlineLanguageLabelFilesWithTypoScript.html
Following scenario:
You want to use `page.inlineLanguageLabelFiles` to get translations to the FE via `TYPO3.lang` in JS.
You use german as the default language in FE. English ist your secondary language.
Expectations:
You use `TYPO3.lang` in german and get the german translations in `source` and `target`.
You use `TYPO3.lang` in english and get the german translations in `source` and the english translations in `target`.
Reality:
You use `TYPO3.lang` in german and get the german translations in `source` and `target`.
You use `TYPO3.lang` in english and get the german translations in `source` and `target`.
Problem/Solution:
I searched for the issue. It seems that the issue lies in the following file:
sysext/core/Classes/Page/PageRenderer.php:2411
It uses `$this->readLLfile()` and there the in `$this->languageDependencies` the `Locales` class of the backend is used:
typo3/typo3/sysext/core/Classes/Localization/Locales.php
In that array of allowed locales the `en` key is missing, as the default language in the backend is english.
I am unsure where exactly the issue is, or rather how this should be changed. The functionality must be switched to allow other languages to also work.
Possibly this is only an issue with english as the secondary language. I am not sure about that.
Updated by Riccardo De Contardi about 5 years ago
I have performed the following test with TYPO3 9.5.8
Prerequisites¶
- fresh TYPO3 9.5.8 installation
- configuration with three languages: ITALIAN (main); ENGLISH (Id=1), FRENCH (Id=2); this is the config.yaml part about the language configuration:
languages: - title: Italian enabled: true languageId: '0' base: / typo3Language: it locale: it_IT.UTF-8 iso-639-1: it navigationTitle: Italiano hreflang: it-IT direction: ltr flag: it - title: English enabled: true languageId: '1' base: /en/ typo3Language: default locale: en_EN.UTF-8 iso-639-1: en navigationTitle: English hreflang: en-EN direction: '' fallbackType: fallback fallbacks: '0' flag: gb - title: French enabled: true languageId: '2' base: /fr/ typo3Language: fr locale: fr_FR.UTF-8 iso-639-1: fr navigationTitle: French hreflang: fr-FR direction: '' fallbackType: fallback fallbacks: '1' flag: fr
Test execution:¶
1) I created three language files:
fileadmin/loccallang.xlf
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <xliff version="1.0"> <file source-language="en" datatype="plaintext" original="messages" product-name="test" date="2019-06-26T22:00:00+02:00"> <header/> <body> <trans-unit id="test"> <source>Test ENG</source> </trans-unit> </body> </file> </xliff>
fileadmin/it.locallang.xlf
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <xliff version="1.0"> <file source-language="en" datatype="plaintext" original="messages" product-name="test" date="2019-06-26T22:00:00+02:00"> <header/> <body> <trans-unit id="test"> <source>Test ENG</source> <target>Test ITA</target> </trans-unit> </body> </file> </xliff>
fileadmin/fr.locallang.xlf
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <xliff version="1.0"> <file source-language="en" datatype="plaintext" original="messages" product-name="test" date="2019-06-26T22:00:00+02:00"> <header/> <body> <trans-unit id="test"> <source>Test ENG</source> <target>Test FRA</target> </trans-unit> </body> </file> </xliff>
2) TS Template: added:
page.inlineLanguageLabelFiles { someLabels = fileadmin/locallang.xlf someLabels.errorMode = 0 }
Test results:¶
- source code of https://mysite.com (italian) contains:
<script type="text/javascript"> /*<![CDATA[*/ var TYPO3 = TYPO3 || {}; TYPO3.lang = {"test":"Test ITA"};/*]]>*/ </script>
- source code of https://mysite.com/en (english) contains:
<script type="text/javascript"> /*<![CDATA[*/ var TYPO3 = TYPO3 || {}; TYPO3.lang = {"test":"Test ENG"};/*]]>*/ </script>
- source code of https://mysite.com/fr (french) contains:
<script type="text/javascript"> /*<![CDATA[*/ var TYPO3 = TYPO3 || {}; TYPO3.lang = {"test":"Test FRA"};/*]]>*/ </script>
Is this the expected result?
Updated by Justus Moroni about 5 years ago
Your example would be what i expect when using this feature.
It seems that something changed here between 8.7 and 9.5.
My TYPO3.lang contains the following:
TYPO3.lang = {
"foo": [
{
"source": "foo",
"target": "bar"
}
]
};
I will check this again in the project and will compare it with 9.5.
Updated by Justus Moroni about 5 years ago
Okay - i've tested this in 9.5 LTS.
I've realized that i forgot to mention that my locallang.xlf file is german.
And i have a en.locallang.xlf for the second language.
When i switch the languages in the locallang.xlf files - it works as you've described.
Is it "Best Practice" or somewhere mentioned that the default locallang.xlf should always be english?
Until now i've always used the default language of the website as the default language of the locallang.xlf file.
My scenario was that a website started with one language german and then a second language english was added.
In that case i did not switch the language files. The default locallang.xlf still containted the german translations.
I've never had any issues with this setup until i used the _ inlineLanguageLabelFiles_ feature in the project 11 months ago.
Updated by Riccardo De Contardi almost 5 years ago
Hello and sorry for my late answer;
I find in the documentation here https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Internationalization/XliffFormat.html#basics
The translated file is very similar. If the original file was named
locallang.xlf
, the translated file for German (code “de”) will be namedde.locallang.xlf
. Note that the original file must always be in english, so it is not
allowed to create a file with the prefix “en” e.g.en.locallang.xlf
[...]
Updated by Justus Moroni almost 5 years ago
Do you think this should be enforced?
Like:
Throw an exception when a `en.locallang.xlf` file was detected.
This could be a deprecation in version 10 and then be removed in a later version?
Updated by Benni Mack over 4 years ago
- Sprint Focus changed from PRC to Needs Decision
Updated by Georg Ringer 2 months ago
- Status changed from New to Closed
closing the issue as default should always be en (At least when trying to translate something)