PHPackages                             apih/laravel-jslang - 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. apih/laravel-jslang

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

apih/laravel-jslang
===================

Language localization in JavaScript, for Laravel-based application

v1.2.9(1y ago)02.4k↓33.3%MITPHPPHP ^8.0

Since Oct 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/apih/laravel-jslang)[ Packagist](https://packagist.org/packages/apih/laravel-jslang)[ Docs](https://github.com/apih/laravel-jslang)[ RSS](/packages/apih-laravel-jslang/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (0)

Laravel JS Lang
===============

[](#laravel-js-lang)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f4eaedb9bc1884723f67c0c278569c353e81e3be752e036bd2947d7f1440c3ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617069682f6c61726176656c2d6a736c616e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/apih/laravel-jslang)[![Total Downloads](https://camo.githubusercontent.com/df7c834cf9fe302db7d4d59aaa7e97f4cf0fa3d3549bf63beaf9e1868f42f541/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617069682f6c61726176656c2d6a736c616e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/apih/laravel-jslang)[![License](https://camo.githubusercontent.com/9c4d519ff42e444eb564c7805ca730435dbf1e22734ff755cbb07469f1844679/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f617069682f6c61726176656c2d6a736c616e673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/apih/laravel-jslang)

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

[](#requirements)

- PHP: `^8.0`
- Laravel: `^8.0|^9.0|^10.0|^11.0|^12.0`

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

[](#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
-----

[](#usage)

### Testing

[](#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

[](#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

[](#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

[](#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

[](#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:

```

    Lang.setLocale('en');
    Lang.setMessages(window.langData);

```

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

[](#security-vulnerabilities)

If you discover any security related issues, please email [hafizuddin\_83@yahoo.com](mailto:hafizuddin_83@yahoo.com) instead of using the issue tracker. Please prefix the subject with `Laravel JS Lang:`.

Credits
-------

[](#credits)

- [Mohd Hafizuddin M Marzuki](https://github.com/apih)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance46

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~116 days

Recently: every ~122 days

Total

12

Last Release

404d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/798269?v=4)[Mohd Hafizuddin M Marzuki](/maintainers/apih)[@apih](https://github.com/apih)

---

Top Contributors

[![apih](https://avatars.githubusercontent.com/u/798269?v=4)](https://github.com/apih "apih (18 commits)")

---

Tags

phplaravellocalizationjavascripttranslationapihlaravel-jslang

### Embed Badge

![Health badge](/badges/apih-laravel-jslang/health.svg)

```
[![Health](https://phpackages.com/badges/apih-laravel-jslang/health.svg)](https://phpackages.com/packages/apih-laravel-jslang)
```

###  Alternatives

[codezero/laravel-localized-routes

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

543638.1k4](/packages/codezero-laravel-localized-routes)[jayesh/laravel-gemini-translator

An interactive command to extract and generate Laravel translations using Gemini AI.

691.7k1](/packages/jayesh-laravel-gemini-translator)[opgginc/codezero-laravel-localized-routes

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

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

3527.1k4](/packages/awes-io-localization-helper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
