2017 © Pedro Peláez
 

library js-translator

Laravel JS translator

image

webkid/js-translator

Laravel JS translator

  • Saturday, June 10, 2017
  • by _webkid
  • Repository
  • 1 Watchers
  • 0 Stars
  • 719 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 21 % Grown

The README.md

Laravel JS-translator

Install

Via Composer, (*1)

``` bash $ composer require webkid/js-translator, (*2)


Add service provider: `Webkid\JsTranslator\JsTranslatorServiceProvider::class,` ## Usage. Angular JS example: Publish lang.js library file. to `your-public-folder/jstranslator/lang.js` ``` bash $ php artisan vendor:publish

Add deferred bootstrap library to load translations before everything was loaded., (*3)

``` bash bower install angular-deferred-bootstrap --save, (*4)


Add assets to your html or blade page ```html <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js"></script> <script src="/vendor/angular-deferred-bootstrap/angular-deferred-bootstrap.min.js"></script> <script src="/jstranslator/lang.js"></script>

Run deferred bootstrap:, (*5)

deferredBootstrapper.bootstrap({
    element: document.documentElement,
    module: 'app',
    resolve: {
        TRANS: ['$http', function ($http) {
            return $http.get('/trans');
        }]
    }
});

Set up route for /trans url:, (*6)

Route::get('/trans', function () {
    $a = app()->make('jstranslator');
    return response()->json($a->get());
});

Finnaly add your angular script file. Example:, (*7)

(function() {

    'use strict';

    angular
        .module('app', [])
        .controller('langController', langController)
        .filter('trans', trans)
        .filter('trans_plural', trans_plural)
        .filter('trans_as_array', trans_as_array)
        .run(runBlock)
    ;


    runBlock.$inject = ['TRANS'];
    function runBlock(TRANS)
    {
        Lang.setMessages(TRANS); //set messages object
    }

    function langController() {
        console.log(Lang.get('pagination.next'));
    }

    /**
     * Get translation from resources, empty.
     * Example:
     * 'pagination.next' | trans => 'Next'
     */
    function trans() {
        return function (input, replaces) {
            // Set symbol
            return Lang.get(input, replaces);
        };
    }

    /**
     * Get translation from resources.
     * Example:
     * 'subscription.month' | trans_plural:1 => 'month'
     * 'subscription.month' | trans_plural:2 => 'months'
     */
    function trans_plural() {
        return function (input, number) {
            return Lang.choice(input, number);
        };
    }

    /**
     * Convert translation object to array from resources.
     * Example:
     * 'property.property_types' | trans_as_array
     */
    function trans_as_array() {
        return function (input) {
            if(typeof Lang.get(input) !== 'object') {
                console.error('Error, ' + input + 'not a object.');
                return [];
            }
            var newOptions = [];
            angular.forEach(Lang.get(input), function(val, key){
                newOptions.push({key: key, value: val});
            });

            return newOptions;
        };
    }

})();

Example of usage in html:, (*8)

<div class="title" ng-controller="langController">Laravel 5 @{{ 'pagination.next' | trans }}</div>

Change log

Please see CHANGELOG for more information what has changed recently., (*9)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*10)

Security

If you discover any security related issues, please email kolodiy@ukietech.com instead of using the issue tracker., (*11)

Credits

  • [kolodiy@ukietech.com][http://john.if.ua/]

License

The MIT License (MIT). Please see License File for more information., (*12)

The Versions

10/06 2017

dev-master

9999999-dev https://github.com/Webkid/JsTranslator

Laravel JS translator

  Sources   Download

MIT

The Requires

 

The Development Requires

webkid jstranslator

10/06 2017

1.4

1.4.0.0 https://github.com/Webkid/JsTranslator

Laravel JS translator

  Sources   Download

MIT

The Requires

 

The Development Requires

webkid jstranslator

23/05 2016

1.2.1

1.2.1.0 https://github.com/Webkid/JsTranslator

Laravel JS translator

  Sources   Download

MIT

The Requires

 

The Development Requires

webkid jstranslator

23/05 2016

1.3

1.3.0.0 https://github.com/Webkid/JsTranslator

Laravel JS translator

  Sources   Download

MIT

The Requires

 

The Development Requires

webkid jstranslator

23/05 2016

1.0.1

1.0.1.0 https://github.com/Webkid/JsTranslator

Laravel JS translator

  Sources   Download

MIT

The Requires

 

The Development Requires

webkid jstranslator

23/05 2016

1.2

1.2.0.0 https://github.com/Webkid/JsTranslator

Laravel JS translator

  Sources   Download

MIT

The Requires

 

The Development Requires

webkid jstranslator

20/05 2016

1.0.0

1.0.0.0 https://github.com/Webkid/JsTranslator

:package_description

  Sources   Download

MIT

The Requires

 

The Development Requires

webkid jstranslator