Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 20, 2020
Merged

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

merged 1 commit into from
Jul 20, 2020

Conversation

ruanpepe
Copy link
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
Member

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
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
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