rmariuzzo/Laravel-JS-Localization

Feature: add default and fallback locale in config file

fsasvari opened this issue · 7 comments

I have suggestion for setting locale and fallback locale in "localization-js.php" config file.

The problem is with generated .js file. Lang.setLocale() and Lang.setFallback() is not provided so I need to include it manually on all pages where I'm using Lang JS.

Is there any options to generate JS file with already set locale and fallback ?

No, currently there's no way the default and fallback locale to be included in the generated file. However, the default local in the lang.js library is en (https://github.com/rmariuzzo/Lang.js/blob/0512672395589614d895d6ca0e96eee41f24dcc7/src/lang.js#L49).

@fsasvari As I understand you want to change from within this package, right?

Yes, it will be nice to change it from this package. Language array files are being generated and it will be great to generate following in template file (https://github.com/rmariuzzo/Laravel-JS-Localization/blob/master/src/Mariuzzo/LaravelJsLocalization/Generators/Templates/langjs_with_messages.js):

Lang.setLocale(config('localization-js.locale'));
Lang.setFallback(config('localization-js.fallback'));

If provided.

@fsasvari got it. Any comment @a-komarev ?

You want to add just setters at the end?

'{ langjs }';

(function () {
    Lang = new Lang();
    Lang.setMessages('{ messages }');
    Lang.setLocale('de');
    Lang.setFallback('en');
})();

It will be added all the time or by using some special key on generate command?

@a-komarev I think it could be added all the time, with default if not set. I'm toward adding it all the time because it would be clear for the users.

Seems good to me.

Closing this issue because I believe that is the developer responsibility to set the default locale on init. Although I closed this issue, I'm open to suggestions.