silverstripe / silverstripe/developer-docs

Document how to unset and change the fallback locale for i18n

Open
#292 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

affects/v4 affects/v5 impact/medium type/docs
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.