Laravel-JS-Localization icon indicating copy to clipboard operation
Laravel-JS-Localization copied to clipboard

Matching laravel current locale in js

Open chilio opened this issue 7 years ago • 1 comments

My question is how to most elegantly set current locale in js, based on currently used laravel (backend locale)? I have tried different solutions like for example setting locale based on headers - accept language, but it is not working correctly under some circumstances. Currently I have it working by including view partial on every page:

<script>
lang.setLocale('{{ LaravelLocalization::getCurrentLocale() }}');
</script>

but it seems like terrible solution. Any ideas how to deal with this respecting best practices?

chilio avatar Aug 03 '18 00:08 chilio

I just had the same problem and as it's not documented I'll add the better option here as well.

This package tries to guess language from <html lang="en"> attribute, unless specifically set separately.

Hope it helps.

iffutsius avatar Apr 17 '20 07:04 iffutsius