Using Laravel localization with JavaScript and VueJS
We do know that Laravel has a wonderful localization support out of box which by default is located in resources/lang
folder. We can use it in PHP calling helper function like (or you can use also __
in newer versions). Laravel’s Blade template engine also has support of this helper:
<label for="email">{{ trans('auth.email') }}</label>
or (newer versions)
<label for="email">@lang('auth.email')</label>
So the code above would be rendered as:
<label for="email">Email:</label>
Passing Laravel language strings to JavaScript
But what about JS? It has neither trans()
nor __()
functions by default (at least up to version 5.4). And it doesn’t even know anything about localization strings, which by the way could be organized as JSON objects in PHP (since L5.4).