laravel-javascript-lang maintained by pod-point
Description
Laravel package that exposes translations and routes to JavaScript
Last update
2024/07/01 15:23
(dev-master)
License
Downloads
4 641
Tags
Laravel JavaScript Lang
A Laravel package that exposes translations to JavaScript.
Installation
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"
Usage
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'))