https://github.com/pod-point/laravel-javascript-lang
Laravel package that exposes translations and routes to JavaScript
https://github.com/pod-point/laravel-javascript-lang
language laravel software-team
Last synced: about 1 year ago
JSON representation
Laravel package that exposes translations and routes to JavaScript
- Host: GitHub
- URL: https://github.com/pod-point/laravel-javascript-lang
- Owner: Pod-Point
- License: mit
- Created: 2018-02-02T16:37:19.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-01T13:24:29.000Z (almost 2 years ago)
- Last Synced: 2025-04-05T07:15:25.536Z (about 1 year ago)
- Topics: language, laravel, software-team
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 9
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel JavaScript Lang
[](https://packagist.org/packages/pod-point/laravel-javascript-lang)
A Laravel package that exposes translations to JavaScript.
## Installation
Require the package in composer:
```javascript
"require": {
"pod-point/laravel-javascript-lang": "^1.0"
},
```
Add the service provider to your `config/app.php` providers array:
```php
'providers' => [
PodPoint\JsLang\Providers\ServiceProvider::class
]
```
Then finally, publish the config files:
```php
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:
```html
```
There is a provided JavaScript module with a helper method you can use to retrieve the translations:
```js
import jsLang from '../lib/jslang';
const string = jsLang.get('orders.form.error');
```
Or you can get the data yourself:
```js
JSON.parse(document.body.getAttribute('data-jslang'))
```