New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

apih/laravel-jslang

Language localization in JavaScript, for Laravel-based application
4,124 2

Larablocks Analysis

apih/laravel-jslang works with Laravel 8 to 13 (latest release v1.2.11, Oct 10, 2026).

Promising: maintained and up to date, meets 2 of 4 checks; not yet widely used.

  • Works with Laravel 13, the current version
  • Released in the last 12 months (Oct 10, 2026)
  • 614 downloads a month (needs 10,000)
  • 2 GitHub stars (needs 100)

State

Maintained
  • Last stable release: Oct 10, 2026.
  • 2 releases in the last 12 months.
  • First released: Oct 3, 2021.
  • Monthly downloads: 614.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 28, 2026.

Install
composer require apih/laravel-jslang
Latest Version:v1.2.11
PHP:^8.0
Laravel:8 – 13
License:MIT
Last Updated:Oct 10, 2026
Links: GitHub  ·  Packagist
Maintainer: apih

Laravel JS Lang

Latest Version on Packagist Total Downloads License

This package provides the ability to use all language localization messages from your Laravel-based app in browser's JavaScript. It also comes with a simple JavaScript Translator library that has some methods to interact with the messages.

Requirements

  • PHP: ^8.0
  • Laravel: ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0

Installation

You can install the package via Composer:

composer require apih/laravel-jslang

The Apih\JsLang\JsLangServiceProvider class is auto-discovered and registered by default.

If you want to register it yourself, add the service provider in config/app.php:

'providers' => [
    /*
     * Package Service Providers...
     */
    Apih\JsLang\JsLangServiceProvider::class,
],

You can publish the config file with:

php artisan vendor:publish --provider="Apih\JsLang\JsLangServiceProvider" --tag="jslang-config"

You can publish the JavaScript Translator library with:

php artisan vendor:publish --provider="Apih\JsLang\JsLangServiceProvider" --tag="jslang-script"

Usage

Testing

To test whether the installation is successful, you can run the following code:

use Apih\JsLang\JsLang;

$jsLang = app(JsLang::class);
echo $jsLang->getUrl('en', 'all');
echo $jsLang->getContents('en', 'all');

It should output the URL and the JavaScript code for language localization messages.

Message Types

There are three message types:

  • short - localization messages defined in PHP files
  • long - localization messages defined in JSON files
  • all - combination of both short and long types

JavaScript Files

By opening the URL generated by getUrl(), you will get the respective contents based on provided locale and type. By default, the contents are generated on runtime, unless you generate all the files beforehand, using the provided Artisan command.

Artisan Commands

You can generate all JavaScript files with:

php artisan jslang:generate

By default, crc32 hashing algorithm is used to generate the contents' hash included in the filename. You can change the algorithm by using --hash-algo option. The following example uses sha256 hashing algorithm and only takes first 12 characters from the generated hash:

php artisan jslang:generate --hash-algo=sha256,12

Generated files are placed in public/lang directory, based on the default config. It is recommended to put the directory in .gitignore file.

You can clear all generated files with:

php artisan jslang:clear

Bootstrapping for Front-end

In order to use in front-end, several steps have to be taken. First, edit resources/js/app.js to add the JavaScript translator:

window.Lang = require('./lang');

Then, use npm run dev or npm run prod to compile resources/js/app.js.

After that, you need to configure it in your page:

<script src="{{ asset('js/app.js') }}"></script>
<script src="{{ app(\Apih\JsLang\JsLang::class)->getUrl('en', 'all') }}"></script>
<script>
    Lang.setLocale('en');
    Lang.setMessages(window.langData);
</script>

To test it, you can open the page in the browser and run the following code in the console to test it:

Lang.get('validation.required', { attribute: 'email' });
// Output: The email field is required.

Lang.choice('[0] No user|[1] 1 user|[2,*] :count users', 0);
// Output: No user

Lang.choice('[0] No user|[1] 1 user|[2,*] :count users', 1);
// Output: 1 user

Lang.choice('[0] No user|[1] 1 user|[2,*] :count users', 2);
// Output: 2 users

Security Vulnerabilities

If you discover any security related issues, please email hafizuddin_83@yahoo.com instead of using the issue tracker. Please prefix the subject with Laravel JS Lang:.

Credits

License

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

Alternatives to apih/laravel-jslang

tio/laravel

Add this package to localize your Laravel application (PHP, JSON or GetText).

382,573 169
niels-numbers/laravel-localizer

Detects the user’s preferred language and redirects to the matching localized UR...

40,282 41
codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

698,310 541
kenepa/translation-manager

Manage your application's translation strings in Filament.

123,777 147
lukasss93/laravel-larex

Translate your Laravel application from a single CSV file!

128,016 98

Version History

Version Released PHP Laravel License
v1.2.11 ^8.0 ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
v1.2.10 ^8.0 ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
v1.2.9 ^8.0 ^8.0|^9.0|^10.0|^11.0|^12.0 MIT
v1.2.8 ^8.0 ^8.0|^9.0|^10.0|^11.0|^12.0 MIT
v1.2.7 ^8.0 ^8.0|^9.0|^10.0|^11.0|^12.0 MIT