-
Notifications
You must be signed in to change notification settings - Fork 73
Description
Affected Version
Framework 4.13.10 and probably up
Description
Note: See comments for a clear indication of what needs to be documented.
When translating keywords in templates with <%t MyClass.MyKeyword "My Default Value" %> and the default language is not EN then the Default Value will not be displayed but instead the value of the English language file will be shown if the MyClass.MyKeyword is not in the language yml file of the (non english) default language.
It should fall back to the default - not the English version. So not expected behavior.
Steps to Reproduce
Create nl.yml file and add nothing
Create en.yml file and add: MyClass.MyKeyword: 'MY ENGLISH VALUE'
Set locale to NL and test in template with <%t MyClass.MyKeyword "My Default Value" %>
'MY ENGLISH VALUE' will be shown instead of 'My Default Value'
Fix with Injector
Override the FallbackLocales value of Symfony\Component\Translation\TranslatorInterface this should be set to the default language and not to English. In this example the setFallbackLocales language is set to dutch language NL.
---
Name: resettranslatorinterface
---
SilverStripe\Core\Injector\Injector:
Symfony\Component\Translation\TranslatorInterface: false
---
Name: overridetranslatorinterface
---
SilverStripe\Core\Injector\Injector:
Symfony\Component\Translation\TranslatorInterface:
class: Symfony\Component\Translation\Translator
constructor:
0: 'en'
1: null
2: '`TEMP_PATH`'
properties:
ConfigCacheFactory: '%$Symfony\Component\Config\ConfigCacheFactoryInterface'
calls:
FallbackLocales: [ setFallbackLocales, [['nl']]]
Loader: [ addLoader, ['ss', '%$Symfony\Component\Translation\Loader\LoaderInterface' ]]Fix with _config.php
$provider = Injector::inst()->create(MessageProvider::class);
$provider->getTranslator()->setFallbackLocales(['nl']);