PHPackages                             hadefication/polyglot - 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. hadefication/polyglot

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

hadefication/polyglot
=====================

Extend Laravel Translation to JavaScript.

1.0.8(7y ago)266MITPHP

Since Aug 15Pushed 7y ago1 watchersCompare

[ Source](https://github.com/hadefication/polyglot)[ Packagist](https://packagist.org/packages/hadefication/polyglot)[ RSS](/packages/hadefication-polyglot/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (9)Dependencies (2)Versions (14)Used By (0)

Polyglot
========

[](#polyglot)

Polyglot creates a blade directive `@polyglot` that you can add to your master blade file. This will then export a global variable `Polyglot` where all of your app's current locale translation keys are stored. The root object keys are base from the defined translation files located in the Polyglot's configuration file.

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

[](#installation)

1. `composer require hadefication/polyglot`
2. Add `Hadefication\Polyglot\PolyglotServiceProvider::class` to your `config/app.php` under the `providers` array. This step is not needed for version 5.5 and above where package auto-discovery is introduced.
3. Include `@polyglot` blade directive to your master blade file on top of your JavaScript files -- probably in the header or before the body tag ends.

Usage
-----

[](#usage)

Once installed, this package will then expose a `Polyglot` variable where all of your current locale translation keys are stored.

A nifty JavaScript helper function will be exposed too that you can use to translate translation keys like what we're doing in Laravel. Accidentally named it `trans` too. See examples below for more details on `trans` helper function.

### Example

[](#example)

Without param

```
trans('auth.failed');

// Should return the equivalent translation of the supplied key

```

Translations with params

```
trans('validation.required', {attribute: 'email'});

// Should return the equivalent translation of the supplied key including the supplied params

```

Config
------

[](#config)

A configuration file is included too to customize the translation files that will be loaded to `Polyglot`. To publish the included config file, run `php artisan vendor:publish`.

Artisan Command
---------------

[](#artisan-command)

An artisan command is also provided where it will dump a JavaScript file that houses all collected translation keys including the importable route method helper. Upon using this approach, including the `@polyglot` blade directive won't be necessary.

```
php artisan polyglot:dump

```

The command above should dump a JavaScript file named polyglot.js in your `/resources/assets/js` directory. You can also supply `--path=/path/to/where/the/dump/file/will/be/exported` to dumpt the file in other location. The command should look like `php artisan polyglot:dump --path=./resources/assets/js/vendor/polyglot.js`.

```
// ES6
import './path/to/polyglot';

// Old School
require('./path/to/polyglot.js');

```

The code above should be added to your bootstrap file or to the main JavaScript file if you have a custom entry point.

### Laravel Mix

[](#laravel-mix)

You can also automate the dumping by installing a webpack plugin that runs a simple artisan command on every build so you are sure that you got the latest translation files included in your build. Follow steps below:

1. Install the [webpack shell plugin](https://github.com/1337programming/webpack-shell-plugin): `npm install --save-dev webpack-shell-plugin` or `yarn add --dev webpack-shell-plugin`
2. Include the plugin to your `webpack.mix.js` file:

```
const mix = require('laravel-mix');
const WebpackShellPlugin = require('webpack-shell-plugin');

mix.webpackConfig({
    plugins: [
        new WebpackShellPlugin({ onBuildStart: ['php artisan polyglot:dump'], onBuildEnd: [] }),
    ]
});

....

```

3. Done! This will run `php artisan polyglot:dump` on start of the build so you get the latest translation files.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

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 ~45 days

Total

10

Last Release

2836d ago

### Community

Maintainers

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

---

Top Contributors

[![hadefication](https://avatars.githubusercontent.com/u/6673244?v=4)](https://github.com/hadefication "hadefication (25 commits)")

---

Tags

laravellaravel-packagetranslation

### Embed Badge

![Health badge](/badges/hadefication-polyglot/health.svg)

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

###  Alternatives

[typicms/base

A modular multilingual CMS built with Laravel, enabling developers to manage structured content like pages, news, events, and more.

1.6k20.4k](/packages/typicms-base)[vemcogroup/laravel-translation

Translation package for Laravel to scan for localisations and up/download to poeditor

136319.2k3](/packages/vemcogroup-laravel-translation)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135212.4k7](/packages/statamic-rad-pack-runway)

PHPackages © 2026

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