2017 © Pedro Peláez
 

library laravel-js-lang-converter

Laravel Localization in JavaScript

image

michele-angioni/laravel-js-lang-converter

Laravel Localization in JavaScript

  • Friday, February 9, 2018
  • by Michele
  • Repository
  • 1 Watchers
  • 24 Stars
  • 33,087 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 1 Open issues
  • 22 Versions
  • 5 % Grown

The README.md

Laravel JS Lang Converter

Laravel Localization in JavaScript., (*1)

Latest Stable Version License Build Status SensioLabsInsight, (*2)

Laravel JS Lang Converter converts all your localization messages of your Laravel app to JavaScript, providing a small JavaScript library to interact with those messages in the fron end., (*3)

Most of the work has been developed in Mariuzzo's package , (*4)

Laravel 5.5+ is supported. PHP 7.0 is required. For Laravel 5.1 - 5-4 versions, use the v2.x branch., (*5)

Installation

Add the following line to you composer.json file under require., (*6)

"michele-angioni/laravel-js-lang-converter": "~3.0"

and run composer update or composer install., (*7)

Then you need to add the Laravel JS Lang Converter service provider in your app/config/app.php file, (*8)

'providers' => [
    // ...
    'MicheleAngioni\LaravelJsLangConverter\LaravelJsLangConverterServiceProvider',
    // ...
],

In order to use some package features, you need to publish the config file through the artisan command php artisan vendor:publish. It will create the laravel_js_lang.php file in your config directory., (*9)

Now you are done!, (*10)

Usage

This project comes with a command that generate the JavaScript version of all your messages found in resources/lang directory. The resulting JavaScript file will have the whole bunch of messages and a thin library similar to Laravel's Lang class., (*11)

Generating JS messages, (*12)

php artisan lang:js

Specifying a custom target, (*13)

php artisan lang:js public/assets/dist/lang.dist.js

Converting only some files, (*14)

If you don't want to convert ALL your lang files, you can specify the files you want to be converted into your laravel_js_lang.php conf file. Under the files array, just add the list of your source files, like so:, (*15)

'files' => [
    'pagination',
    'validation'
]

Compressing the JS file, (*16)

php artisan lang:js -c

Use gulp to publish (optional):, (*17)

  1. Install gulp-shell from https://github.com/sun-zheng-an/gulp-shell with npm install --save-dev gulp-shell ., (*18)

  2. Create an extension for elixir in your gulpfile.js:, (*19)

    var shell = require('gulp-shell');
    
    //......
    
    var Task = elixir.Task;
    
    elixir.extend('langjs', function(path, minimize) {
        new Task('langjs', function() {
            var command = "php artisan lang:js " + (path || "public/js/messages.js");
                if (minimize) {
                    command += " -c";
                }
            return gulp.src("").pipe(shell(command));
        });
    });
    
    gulp.task('langJs', shell.task('php artisan lang:js -c public/js/messages.js'));
    
  3. Use the new elixir task:, (*20)

elixir(function(mix) {
    var path = "public/js";
    var minimize = true;
    mix.langjs(path, minimize);
});

Documentation

This is the documentation regarding the thin JavaScript library. The library is highly inspired on Laravel's Lang class., (*21)

Getting a message, (*22)

Lang.get('messages.home');

Getting a message with replacements, (*23)

Lang.get('messages.welcome', { name: 'Joe' });

Changing the locale, (*24)

Lang.setLocale('es');

Checking if a message key exists, (*25)

Lang.has('messages.foo');

Support for singular and plural message based on a count, (*26)

Lang.choice('messages.apples', 10);

Calling the choice method with replacements, (*27)

Lang.choice('messages.apples', 10, { name: 'Joe' });

For more detailed information, take a look at the source: Lang.js., (*28)

How to contribute

Pull requests are welcome., (*29)

  1. Fork this repository and clone it.
  2. Create a branch from develop: git checkout -b feature-foo.
  3. Push your commits and create a pull request.

Setting up development environment

Prerequisites:, (*30)

You need to have installed the following softwares., (*31)

  • Composer
  • NodeJS
  • NPM
  • PHP 7.0+

After getting all the required software you may run the following commands to get everything ready:, (*32)

  1. Install PHP dependencies:
composer install
  1. Install NPM dependences:
npm install -g jasmine-node

npm install

Now you are good to go! Happy coding!, (*33)

Unit testing

This project use Jasmine-Node and PHPUnit. All tests are stored at tests directory., (*34)

To run all JS tests type in you terminal:, (*35)

npm test

To run all PHP tests type in your terminal:, (*36)

vendor/bin/phpunit tests/

The Versions

09/02 2018
22/03 2017
23/02 2016

dev-development

dev-development https://github.com/michele-angioni/laravel-js-lang-converter

Laravel Localization in JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript js i18n localization laravel 5 lang

29/06 2015

v1.2.1

1.2.1.0 https://github.com/rmariuzzo/laravel-js-localization

Laravel Localization in JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript js i18n localization laravel 5 lang

16/06 2015

v1.2.0

1.2.0.0 https://github.com/rmariuzzo/laravel-js-localization

Laravel Localization in JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript js i18n localization laravel 5 lang

20/05 2014
15/05 2014
01/05 2014