pod-point / laravel-javascript-lang
Laravel package that exposes translations and routes to JavaScript
Installs: 3 857
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 10
Forks: 2
Open Issues: 0
Requires
- php: ^7.1||^8.1||^8.2
- ext-json: *
- illuminate/contracts: ^6.20||^7.30||^8.83||^9.52||^10.3
- illuminate/support: ^6.20||^7.30||^8.83||^9.52||^10.3
This package is auto-updated.
Last update: 2024-10-31 00:23:20 UTC
README
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'))