LaravelPackages.net
Acme Inc.
Toggle sidebar
thetminnhtun/laravel-localization-js

Laravel localization for JavaScript

1.180
1
v0.1.1
About thetminnhtun/laravel-localization-js

thetminnhtun/laravel-localization-js is a Laravel package for laravel localization for javascript. It currently has 1 GitHub stars and 1.180 downloads on Packagist (latest version v0.1.1). Install it with composer require thetminnhtun/laravel-localization-js. Discover more Laravel packages by thetminnhtun or browse all Laravel packages to compare alternatives.

Last updated

Laravel Localization JS

Issues Forks Stars

Laravel localization for JavaScript

Requirements

  1. PHP 7.0 or higher
  2. Laravel 6.0 or higher

Installation

composer require thetminnhtun/laravel-localization-js

Include the asset

<html>

<body>

    ...

    <x-tmh::laravel-localization-js />

</body>

</html>

Publish the asset file

php artisan vendor:publish --tag=localization-js

Usage

Create the language files what you want. For example, we will create english and myanmar.

/resources
    /lang
        en.json
        my.json

In en.json

{
    "Welcome": "Welcome",
    "Hello": "Hello :name"
}

In my.json

{
    "Welcome": "ကြိုဆိုပါတယ်။",
    "Hello": "မင်္ဂလာပါ :name။"
}

Getting a message from JavaScript

console.log(Lang.get('Welcome'));
console.log(Lang.get('Hello', {name: 'Mg Mg'}));

Ouput

// What if locale is `en`
Welcome
Hello Mg Mg

// or what if locale is `en`
ကြိုဆိုပါတယ်။
မင်္ဂလာပါ Mg Mg။

Avaliable another ways

Lang.get('Welcome');
__('Welcome');
trans('Welcome');

License

This package is open-sourced software licensed under the MIT license.

Comments