PHPackages                             developersunesis/lang2js - 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. developersunesis/lang2js

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

developersunesis/lang2js
========================

A package to copy Laravel lang files for JS use

05[1 issues](https://github.com/developersunesis/lang2js/issues)PHP

Since Aug 21Pushed 4y ago1 watchersCompare

[ Source](https://github.com/developersunesis/lang2js)[ Packagist](https://packagist.org/packages/developersunesis/lang2js)[ RSS](/packages/developersunesis-lang2js/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Welcome to lang2js 👋
====================

[](#welcome-to-lang2js-)

 [![Version](https://camo.githubusercontent.com/d8766dfd7a274db82bddd2f49084453d96c3c89f125707b7c3d91e971b34d520/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d302e302e312d626c75652e7376673f63616368655365636f6e64733d32353932303030)](https://camo.githubusercontent.com/d8766dfd7a274db82bddd2f49084453d96c3c89f125707b7c3d91e971b34d520/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d302e302e312d626c75652e7376673f63616368655365636f6e64733d32353932303030) [ ![Documentation](https://camo.githubusercontent.com/5391604d1e8f886512ab4eeeb3922f4d58a8fac27454e641b1b39c65f51c4d6b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d7965732d627269676874677265656e2e737667) ](https://github.com/developersunesis/lang2js#readme) [ ![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667) ](#) [ ![Twitter: developrsunesis](https://camo.githubusercontent.com/31f7304de51f04b0a87c5592247a6f94e4a1fccd77441b4f5362da6fdfa283af/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f666f6c6c6f772f646576656c6f707273756e657369732e7376673f7374796c653d736f6369616c) ](https://twitter.com/developrsunesis)

> A package that provides an easy way to export and sync Laravel localization files for JavaScript use

Problem
-------

[](#problem)

I have a Laravel project/website, while thinking of how to sync my localization and translation files from the app for JavaScript usage; my first approach was to have the localization content stored in the `localStorage` of the browser when a user first visits the app. While this was a goto solution, I realized this wasn't efficient enough, because it meant that the first page the user visits might not have its strings translated until the localization is available already in the `localStorage`. Another solution, was to inject the localization content directly into a `DOMElement`: ``, clearly there was a trade-off as this drastically increased the page load time but solves the problem of the translations not being available.

#### Final Solution

[](#final-solution)

My final solution which is currently in use was to have a package periodically sync the localization files for JavaScript use. The package reads the following files:

```
resources
├── lang
│   ├── en
│   │   ├── auth.php
│   │   └── dashboard.php
│   ├── fr
│   │   ├── auth.php
│   │   └── dashboard.php

```

and converts it to minified js files

```
public
├── js
│   ├── locales
│   │   ├── en.min.js
│   │   ├── fr.min.js
│   │   └── lang2js.min.js

```

So each locale that needs to be used is imported into my blade component

```
...

       let helloText = __("index.TEST_2", 'en') // this function is provided by `lang2js.min.js`
       document.getElementById("hellotext").innerHTML = helloText

...
```

Install
-------

[](#install)

```
composer require developersunesis/lang2js
```

Usage
-----

[](#usage)

You can simply run a command

```
php artisan lang2js:export exportDir=:exportDir
```

The command above reads the translation files from Laravel default lang folder.

But if you have a custom location you want the translation files to be read from, you can use the following

```
php artisan lang2js:export exportDir=:exportPath localesDir=:localesPath
```

The two commands above uses the base path of the app and the path you specified as their absolute path.
Example:

```
php artisan lang2js:export exportDir=/public/js/locales localesDir=/resources/lang

# Uses full path
# exportDir == {YOUR_CURRENT_APP_LOCATION}/public/js/locales
# localesDir == {YOUR_CURRENT_APP_LOCATION}/public/resources/lang
```

To disable to command from using your base app file, you can add an option to the command as below

```
php artisan lang2js:export exportDir=C:/manners/Documents/public/js/locales localesDir=C:/manners/Documents/resources/lang --useBasePath=false
```

There are various use cases, one of which is to create a schedule for the package to resync the JavaScript translations periodically, this is very useful if you make use of laravel localizations that can be dynamically changed

```
$command = "php artisan lang2js:export exportDir=/public/js/locales"
$schedule->command($command)
          ->weekdays()
          ->daily();

# or through a facade function call
$schedule->call(function () {
    $lang2js = new Lang2js();
    $lang2js->setExportsDir("resources/exports");
    $lang2js->export();
})->weekly()->daily();

# or through a facade function call
$schedule->call(function () {
    L2J::setExportsDir("/public/js/locales")->export();
})->weekly()->daily();
```

Author
------

[](#author)

👤 **Uche Emmanuel**

- Website:
- Twitter: [@developrsunesis](https://twitter.com/developrsunesis)
- Github: [@developersunesis](https://github.com/developersunesis)
- LinkedIn: [@developersunesis](https://linkedin.com/in/developersunesis)

🤝 Contributing
--------------

[](#-contributing)

Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/developersunesis/lang2js/issues).

Show your support
-----------------

[](#show-your-support)

Give a ⭐️ if this project helped you!

---

*This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)*

###  Health Score

16

—

LowBetter than 4% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f7e8a94a4a51f2cfcbe169044e20a8e99d12075a22ae5ae33d2ba2267ec316c5?d=identicon)[developersunesis](/maintainers/developersunesis)

---

Top Contributors

[![aerecurax](https://avatars.githubusercontent.com/u/20749859?v=4)](https://github.com/aerecurax "aerecurax (23 commits)")

### Embed Badge

![Health badge](/badges/developersunesis-lang2js/health.svg)

```
[![Health](https://phpackages.com/badges/developersunesis-lang2js/health.svg)](https://phpackages.com/packages/developersunesis-lang2js)
```

###  Alternatives

[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1927.0k1](/packages/smmoosavi-php-gettext)

PHPackages © 2026

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