Skip to content

Pod-Point/laravel-javascript-lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel JavaScript Lang

Packagist

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'))