PHPackages                             supsign/laravel-js-localization - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. supsign/laravel-js-localization

ActiveLibrary[Localization &amp; i18n](/categories/localization)

supsign/laravel-js-localization
===============================

Laravel Localization in JavaScript

v1.12.1(2y ago)0346MITPHPPHP ^5.4 || ^7.0 || ^8.0

Since Mar 19Pushed 2y agoCompare

[ Source](https://github.com/supsign/Laravel-JS-Localization)[ Packagist](https://packagist.org/packages/supsign/laravel-js-localization)[ Docs](https://github.com/supsign/laravel-js-localization)[ RSS](/packages/supsign-laravel-js-localization/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

[![Laravel JS Localization - Convert you Laravel messages and use them in the front-end!](.github/assets/banner.svg)](.github/assets/banner.svg)
================================================================================================================================================

[](#)

[![Laravel 5.5](https://camo.githubusercontent.com/e6e7acb00516dc024d625b4b2f133613ba8c1f81848fe8c930c459bb60371839/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e352d6634363435662e737667)](https://camo.githubusercontent.com/e6e7acb00516dc024d625b4b2f133613ba8c1f81848fe8c930c459bb60371839/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e352d6634363435662e737667)[![Laravel 4.2](https://camo.githubusercontent.com/5082187d110c7f214eb85535e944c5b50dddf182bb953161a7cd6fb616994f8c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d342e322d6634363435662e737667)](https://camo.githubusercontent.com/5082187d110c7f214eb85535e944c5b50dddf182bb953161a7cd6fb616994f8c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d342e322d6634363435662e737667)[![Latest Stable Version](https://camo.githubusercontent.com/2550cc9611b6821134bedef324eacaf7b81ad81c0b9727a97eeb8a65501ee166/68747470733a2f2f706f7365722e707567782e6f72672f6d617269757a7a6f2f6c61726176656c2d6a732d6c6f63616c697a6174696f6e2f762f737461626c652e737667)](https://packagist.org/packages/mariuzzo/laravel-js-localization)[![Total Downloads](https://camo.githubusercontent.com/ab3a29aabf737b5c9e412da9ea245d239957aa065a88505ffeae1944fb02e89d/68747470733a2f2f706f7365722e707567782e6f72672f6d617269757a7a6f2f6c61726176656c2d6a732d6c6f63616c697a6174696f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/mariuzzo/laravel-js-localization)[![License](https://camo.githubusercontent.com/9c96bbd1682c47f71bcb1272136cf744e929e95c4ae5a808f5cf027812a45ee3/68747470733a2f2f706f7365722e707567782e6f72672f6d617269757a7a6f2f6c61726176656c2d6a732d6c6f63616c697a6174696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/mariuzzo/laravel-js-localization)

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.

Features
--------

[](#features)

- Support Laravel 5.0 up to 11.0
- Includes [Lang.js](https://github.com/rmariuzzo/lang.js) (a thin library highly inspired on Laravel's [`Translator`](https://laravel.com/api/5.4/Illuminate/Translation/Translator.html) class).
- Allow to specify desired lang files to be converted to JS.
- Lang.js API is based on Laravel's [`Translator`](https://laravel.com/api/5.4/Illuminate/Translation/Translator.html) class. No need to learn a whole API.

⭐ **Webpack user?** Try the new and shiny [**Laravel localization loader**](https://github.com/rmariuzzo/laravel-localization-loader) for Webpack!

Installation
------------

[](#installation)

```
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
```

Usage
-----

[](#usage)

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 contain all your messages plus [Lang.js](https://github.com/rmariuzzo/lang.js) (a thin library highly inspired on Laravel's [`Translator`](https://laravel.com/api/5.4/Illuminate/Translation/Translator.html) class).

### Generating JS messages

[](#generating-js-messages)

```
php artisan lang:js
```

### Specifying a custom target

[](#specifying-a-custom-target)

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

### Compressing the JS file

[](#compressing-the-js-file)

```
php artisan lang:js -c
```

### Specifying a custom source folder

[](#specifying-a-custom-source-folder)

```
php artisan lang:js public/assets/dist/lang.dist.js -s themes/default/lang
```

### Output a JSON file instead.

[](#output-a-json-file-instead)

```
php artisan lang:js --json
```

Configuration
-------------

[](#configuration)

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` and `validation.php` files to be included in build process:

```
