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

[WIP] fix: ensure fallback locale is always loaded #338

Closed
wants to merge 1 commit into from
Closed

[WIP] fix: ensure fallback locale is always loaded #338

wants to merge 1 commit into from

Conversation

EmilePerron
Copy link

In the current version, when a fallback locale is defined, it isn't loaded automatically (as explained in #307).

That means you still have to specifically request that the fallback be loaded, which is inconvenient and often forgotten.

This commit updates the getLocales() method to ensure the fallback translations are always loaded when a fallback locale is defined.

Here's a comparison in the case of a project with the fr_CA as the default locale and fr as the fallback locale (with only one message, in order to keep things simple).

Before:

(function (t) {
t.fallback = 'fr';
t.defaultDomain = 'messages';
// fr_CA
})(Translator);

After:

(function (t) {
t.fallback = 'fr';
t.defaultDomain = 'messages';
// fr_CA
// fr
t.add("generic.save", "Enregistrer", "messages", "fr");
})(Translator);

Closes #307

In the current version, when a fallback locale is defined, it isn't loaded automatically (as explained in #307). 

That means you still have to specifically request that the fallback be loaded.

This commit updates the `getLocales()` method to ensure the fallback translations are always loaded when a fallback locale is defined.

Here's a comparison in the case of a project with the `fr_CA` as the default locale and `fr` as the fallback locale (with only one message, in order to keep things simple).

**Before:**
```js
(function (t) {
t.fallback = 'fr';
t.defaultDomain = 'messages';
// fr_CA
})(Translator);
```

**After:**
```js
(function (t) {
t.fallback = 'fr';
t.defaultDomain = 'messages';
// fr_CA
// fr
t.add("generic.save", "Enregistrer", "messages", "fr");
})(Translator);
```

Closes #307
@EmilePerron EmilePerron changed the title fix: ensure fallback locale is always loaded [WIP] fix: ensure fallback locale is always loaded Jul 28, 2022
@EmilePerron
Copy link
Author

The more I think about it, the more I think this isn't the package's responsibility.
The package has no way of knowing if the fallback locale has already been loaded in a different script or not.

Going to close this issue - sorry for the disturbance!

@EmilePerron EmilePerron deleted the fix-fallback-locale-autoload branch March 10, 2023 13:30
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.

Fallback translatations not loaded
1 participant