A Laravel package that exposes translations to JavaScript.
Require the package in composer:
"require": {
"pod-point/laravel-javascript-lang": "^1.0"
},
Add the service provider to your config/app.php
providers array:
'providers' => [
PodPoint\JsLang\Providers\ServiceProvider::class
]
Then finally, publish the config files:
php artisan vendor:publish --provider="PodPoint\JsLang\Providers\ServiceProvider"
Now the varable $jslang
is available in your view. We recommend attaching it to a data tag on your body element:
<body data-jslang='{{ $jslang }}'>
There is a provided JavaScript module with a helper method you can use to retrieve the translations:
import jsLang from '../lib/jslang';
const string = jsLang.get('orders.form.error');
Or you can get the data yourself:
JSON.parse(document.body.getAttribute('data-jslang'))