laravel-js-localization maintained by fortranlee
- php >=5.5.9
- illuminate/config >=4.2
- illuminate/console >=4.2
- illuminate/filesystem >=4.2
- tedivm/jshrink 1.0.*
- php >=5.5.9
- tedivm/jshrink 1.0.*
- illuminate/config >=4.2
- illuminate/console >=4.2
- illuminate/filesystem >=4.2
- php >=5.5.9
- tedivm/jshrink 1.0.*
- illuminate/config >=4.2
- illuminate/console >=4.2
- illuminate/filesystem >=4.2
- php >=5.5.9
- illuminate/config >=4.2
- illuminate/console >=4.2
- illuminate/filesystem >=4.2
- tedivm/jshrink 1.0.*
- php >=5.5.9
- illuminate/config >=4.2
- illuminate/console >=4.2
- illuminate/filesystem >=4.2
- tedivm/jshrink 1.0.*
- php >=5.5.9
- illuminate/config >=4.2
- illuminate/console >=4.2
- illuminate/filesystem >=4.2
- tedivm/jshrink 1.0.*
- php >=5.5.9
- illuminate/config >=4.2
- illuminate/console >=4.2
- illuminate/filesystem >=4.2
- tedivm/jshrink 1.0.*
- php >=5.5.9
- laravel/framework 5.1.*
- tedivm/jshrink 1.0.*
- php >=5.5.9
- laravel/framework 5.1.*
- tedivm/jshrink 1.0.*
- php >=5.4.0
- illuminate/support 5.0.*
- illuminate/console 5.0.*
- illuminate/filesystem 5.0.*
- tedivm/jshrink 1.0.*
- php >=5.3.0
- illuminate/support 4.1.*
- illuminate/console 4.1.*
- illuminate/filesystem 4.1.*
- tedivm/jshrink 0.5.*
- php >=5.3.0
- illuminate/support 4.1.*
- illuminate/console 4.1.*
- illuminate/filesystem 4.1.*
- tedivm/jshrink 0.5.*
- php >=5.3.0
- illuminate/support 4.1.*
- illuminate/console 4.1.*
- illuminate/filesystem 4.1.*
- tedivm/jshrink 0.5.*
comments powered by Disqus
🌐 Laravel Localization in JavaScript.
This package convert all your localization messages from your Laravel app to JavaScript with a small library to interact with those messages following a very similar syntax you are familiar with.
- Support Laravel 4.2.x, Laravel 5.0.x, Laravel 5.1.x, Laravel 5.2.x and Laravel 5.3.x.
- Includes Lang.js (a thin library highly inspired on Laravel's
Translator
class). - Allow to specify desired lang files to be converted to JS.
- Lang.js API is based on Laravel's
Translator
class. No need to learn a whole API.
composer require mariuzzo/laravel-js-localization
In your Laravel app go to config/app.php
and add the following service provider:
Mariuzzo\LaravelJsLocalization\LaravelJsLocalizationServiceProvider::class
The Laravel-JS-Localization
package provides a command that generate the JavaScript version of all your messages found at: app/lang
(Laravel 4) or resources/lang
(Laravel 5) directory. The resulting JavaScript file will contains all your messages plus Lang.js (a thin library highly inspired on Laravel's Translator
class).
php artisan lang:js
php artisan lang:js public/assets/dist/lang.dist.js
php artisan lang:js -c
First, publish the default package's configuration file running:
php artisan vendor:publish --provider="Mariuzzo\LaravelJsLocalization\LaravelJsLocalizationServiceProvider"
The configuration will be published to config/localization-js.php
.
You may edit this file to define the messages you need in your Javascript code. Just edit the messages
array in the config file. Empty messages array will include all the language files in build.
To make only pagination.php
& validation.php
files to be included in build process:
<?php
return [
'messages' => [
'pagination',
'validation',
],
];
Using gulp (optional)
Install gulp-shell
and then run it directly in your gulpfile.js
:
var shell = require('gulp-shell');
gulp.task('langjs', shell.task('php artisan lang:js -c public/js/messages.js'));
Using Laravel's elixir (optional)
Before Elixir 4.0:
elixir.extend('langjs', function(path) {
gulp.task('langjs', function() {
gulp.src('').pipe(shell('php artisan lang:js ' + (path || 'public/js/messages.js')));
});
return this.queueTask('langjs');
});
Elixir 4.0+:
var Task = elixir.Task;
elixir.extend('langjs', function(path) {
new Task('langjs', function() {
gulp.src('').pipe(shell('php artisan lang:js ' + (path || 'public/js/messages.js')));
});
});
And use it like this:
elixir(function(mix) {
mix.langjs();
});
This is a quick documentation regarding Lang.js (the thin JavaScript library included by Laravel-JS-Localization
). The Lang.js (a thin library highly inspired on Laravel's Translator
class).
💁 Go to Lang.js documentation to see all available methods.
Lang.get('messages.home');
Lang.get('messages.welcome', { name: 'Joe' });
Lang.setLocale('es');
Lang.has('messages.foo');
Lang.choice('messages.apples', 10);
Lang.choice('messages.apples', 10, { name: 'Joe' });
💁 Go to Lang.js documentation to see all available methods.
- Fork this repository and clone it.
- Create a feature branch from develop:
git checkout develop; git checkout -b feature-foo
. - Push your commits and create a pull request.
You will need to have installed the following softwares.
- Composer.
- PHP 5.5+.
After getting all the required softwares you may run the following commands to get everything ready:
-
Install PHP dependencies:
composer install
-
Install test dependencies:
composer test-install
Now you are good to go! Happy coding!
This project uses PHPUnit. All tests are stored at tests
directory. To run all tests type in your terminal:
composer test