LaravelPackages.net
Acme Inc.
Toggle sidebar
karunais13/simple-js-localization

Laravel Simple JS localization

48
0
3.0.2
About karunais13/simple-js-localization

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

Simple JS Localization

NOTE: Support laravel 5.0 and above.

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.

Installation

Install the usual composer way.

Run this command at root directory of your project
"composer require karunais13/laravel-simple-js-localization"

For Laravel 5.5 and below add provider in config file like below :

app/config/app.php
	...
	
	'providers' => array(
		...
		Karu\SimpleJsLocalization\SimpleJsLocalizationProvider::class,
	]

Usage

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.

Generating JS messages

php artisan localization:generate-js

Compressing the JS file (minified)

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.

Set Locale

window.lang.setLocale("{{ app()->getLocale() }}");

Get Message

window.lang.get("Hello");
//> "Hello";
// If locale set to `es`
//> "Hola" (based on localization from lang folder in resources) 

Licence

View the licence in this repo.

Star History Chart