silverstripe / silverstripe/developer-docs
Document how to unset and change the fallback locale for i18n
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 7
- Forks
- 74
- Avg merge
- 1d 14m
- Merged PRs (30d)
- 6
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']);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing developer documentation and the _config.php example using MessageProvider and Injector; compare it with the Symfony TranslatorInterface configuration shown in the issue. Document how to unset and change the fallback locale, including the default-locale behavior and both configuration approaches, and ensure the examples explain the expected translation result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- documentation, internationalization
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100