Skip to content

[7.x] Get/Set fallback locale#33595

Merged
taylorotwell merged 1 commit into
laravel:7.xfrom
ruanpepe:patch-1
Jul 20, 2020
Merged

[7.x] Get/Set fallback locale#33595
taylorotwell merged 1 commit into
laravel:7.xfrom
ruanpepe:patch-1

Conversation

@ruanpepe

Copy link
Copy Markdown
Contributor

With this changes, we can set the app fallback locale dinamicaly.
e.g When using 'en_US', is possible set the fallback locale to 'en', and when using 'pt_BR' set 'pt' as fallback locale.

{
$this['config']->set('app.fallback_locale', $fallbackLocale);

$this['translator']->setFallback($fallbackLocale);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This force instantiates the translator. You should check if it has been created yet.

@driesvints

Copy link
Copy Markdown
Member

@ruanpepe can you elaborate more upon the use case for this?

@driesvints driesvints changed the title Get/Set fallback locale [7.x] Get/Set fallback locale Jul 20, 2020
@taylorotwell taylorotwell merged commit 0d8af41 into laravel:7.x Jul 20, 2020
@ruanpepe

Copy link
Copy Markdown
Contributor Author

@driesvints If you set config/app.fallback_locale to "en", all translatable string not found for language in config/app.locale will be translated to "en".
If you change your app locale to "es-CO", "pt-BR", "zh-CN" or another one, maybe you will not want "en" as fallback locale anymore, but "es", "pt" or "zh".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants