karunais13/simple-js-localization is a Laravel package for laravel simple js localization .
It currently has 0 GitHub stars and 48 downloads on Packagist (latest version 3.0.2).
Install it with composer require karunais13/simple-js-localization.
Discover more Laravel packages by karunais13
or browse all Laravel packages to compare alternatives.
Last updated
Laravel has some pretty sweet functions for translation, but the function only limited to blade or php file only. Thus, This package convert all your localization messages from your Laravel app to JavaScript with a simple logic to interact with those messages following a very similar syntax you are familiar with.
Install the usual composer way.
"composer require karunais13/laravel-simple-js-localization"
...
'providers' => array(
...
Karu\SimpleJsLocalization\SimpleJsLocalizationProvider::class,
]
The Simple JS Localization package provides a command that generate the JavaScript version of all your messages found at: resources/lang (Laravel 5) directory. The resulting JavaScript file will contain all your messages plus a simple logic to use on javascript.
php artisan localization:generate-js
php artisan localization:generate-js -c
With the default configuration, this will create a public/js/simple-js-localise.js file to include in your page, or build.
<script src="{{ asset('js/simple-js-localise.js') }}"></script>
Note: You'll have to run localization:generate-js if you change your localization files.
window.lang.setLocale("{{ app()->getLocale() }}");
window.lang.get("Hello");
//> "Hello";
// If locale set to `es`
//> "Hola" (based on localization from lang folder in resources)