willdurand / BazingaJsTranslationBundle

A pretty nice way to expose your Symfony translation messages to your client applications.
MIT License
572 stars 178 forks source link

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

Closed EmilePerron closed 1 year ago

EmilePerron commented 1 year ago

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

EmilePerron commented 1 year ago

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!