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

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

anahkiasen/polyglot
===================

Laravel localization helpers and models

1.4.0(11y ago)13912.1k20[4 issues](https://github.com/Anahkiasen/polyglot/issues)[1 PRs](https://github.com/Anahkiasen/polyglot/pulls)MITPHPPHP &gt;=5.4.0

Since Aug 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Anahkiasen/polyglot)[ Packagist](https://packagist.org/packages/anahkiasen/polyglot)[ RSS](/packages/anahkiasen-polyglot/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (9)Versions (11)Used By (0)

Polyglot
========

[](#polyglot)

[![Build Status](https://camo.githubusercontent.com/a21d65d0657500788bc06e84e26880c15770f6c5f71e005c3a2356525b91d957/68747470733a2f2f7472617669732d63692e6f72672f416e61686b696173656e2f706f6c79676c6f742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Anahkiasen/polyglot)[![Latest Stable Version](https://camo.githubusercontent.com/3588206f472c7c8e00af4bff26983d47370cf913acdbc0cd14aaca4f498f7ff2/68747470733a2f2f706f7365722e707567782e6f72672f616e61686b696173656e2f706f6c79676c6f742f762f737461626c652e706e67)](https://packagist.org/packages/anahkiasen/polyglot)[![Total Downloads](https://camo.githubusercontent.com/385af4fb27db39af129d52a664ec2d03e494b2269597e103d40d04fd159c5042/68747470733a2f2f706f7365722e707567782e6f72672f616e61686b696173656e2f706f6c79676c6f742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/anahkiasen/polyglot)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/cb126b6ab197c819a1bd39653b400e2d969a7a11cac44148c28e169aa7cd3f4e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f416e61686b696173656e2f706f6c79676c6f742f6261646765732f7175616c6974792d73636f72652e706e673f733d32306439613462653636393562373637376334323765616237333135316331613964383033303434)](https://scrutinizer-ci.com/g/Anahkiasen/polyglot/)[![Code Coverage](https://camo.githubusercontent.com/61ae910ddb24dd4d63b1840d05806f6c275d5c57d2c398b72fd4d9fe8200dc67/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f416e61686b696173656e2f706f6c79676c6f742f6261646765732f636f7665726167652e706e673f733d66366530323263626366316135316638326235643965366662333062643136343366633730653736)](https://scrutinizer-ci.com/g/Anahkiasen/polyglot/)

Introduction
------------

[](#introduction)

Polyglot is a localization helper for the Laravel framework, it's an helper class to localize your routes, models and views.

To install it, do `composer require anahkiasen/polyglot:dev-master`, then add `Polyglot\PolyglotServiceProvider` to the `providers` array in `app/config/app.php`.

Publish config to your laravel app : `php artisan config:publish anahkiasen/polyglot`

Model localization
------------------

[](#model-localization)

Setting a model as polyglot will allow you to make fields speak several languages. Polyglot requires you to separate common fields from localized ones assuming the following common pattern :

*Take the example of a blog article model*

```
TABLE articles
  id INT
  category_id INT
  created_at DATETIME
  updated_at DATETIME

TABLE article_langs
  id INT
  title VARCHAR
  content TEXT
  article_id INT
  lang ENUM

```

From there you can either access any language easily by doing the following : `$article->fr->title`. **Or** you can add the following parameter to your model and let Polyglot automatically translate attributes.

```
class Article extends Polyglot
{
  protected $polyglot = ['title', 'content'];
}

// Get an automatically localized Article
$article = Article::find(4)

echo $article->fr->title // This will print out the french title
echo $article->title // This will print out the title in the current language
```

Polyglot also helps you saving localized attributes :

```
$article->fill([
  'title'   => 'Titre',
  'content' => 'Contenu',
  'lang'    => 'fr',
])->save();

// Is the same as

$article->fr->fill([
  'title'   => 'Titre',
  'content' => 'Contenu',
])->save();
```

Globally speaking when Polyglot sees you're trying to save localized attribute on the parent model, it will automatically fetch the Lang model and save them on it instead. If no `lang` attribute is passed, Polyglot will use the current language.

Note that, as your attributes are now split into two tables, you can Polyglot eager load the correct Lang relation with the `withLang` method. Per example `Article::withLang()->get()` will return Articles with `fr` autoloaded if it's the current language, or `en`, according to `app.locale`.

Routes localization
-------------------

[](#routes-localization)

To localize your routes, you need to set the `locales` option in your config file, per example `array('fr', 'en')`. Now you may define your routes as such :

```
Route::groupLocale(['before' => 'auth'], function() {
  Route::get('/', 'HomeController@index');
  Route::get('articles', 'ArticlesController@index');
  // etc...
});
```

Now you can access `/fr` and `/fr/articles`, or `/en` and `/en/articles` – Polyglot will recognize the locale in the URL and automatically set your app in that language. There is also a `default` option in the config file, setting that option to a locale like `'default' => 'fr'` will make the root URLs point to that locale. So accessing `/articles` without prefixing it with a locale would render the page in french.

Views localization
------------------

[](#views-localization)

Views localization work by setting up gettext for you and providing two commands to extract translations from your views to PO files and compile those to MO files.

This is currently only possible for Twig but will soon for Blade and classic PHP files, and will require the `twig/extensions` package which adds gettext support for Twig.

To use simply configure your domain in the configuration, then run `php artisan lang:extract`.

Locales helpers
---------------

[](#locales-helpers)

Polyglot also provide various locale helpers hooked into the `Lang` and `URL` class you know and love :

```
URL::locale() // Returns the locale in the current URL

Lang::active('fr') // Check if fr is the current locale
Lang::setInternalLocale('fr') // Set both the locale with the Translator class and setlocale method
Lang::valid('fr') // Check if a locale is valid
Lang::sanitize('fr') // Returns the locale if valid, or the default locale if not
```

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 83.1% 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 ~98 days

Total

8

Last Release

4019d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

1.3.0PHP &gt;=5.4.0

### Community

Maintainers

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

---

Top Contributors

[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (128 commits)")[![jvdanilo](https://avatars.githubusercontent.com/u/6813993?v=4)](https://github.com/jvdanilo "jvdanilo (17 commits)")[![MathieuDoyon](https://avatars.githubusercontent.com/u/1854511?v=4)](https://github.com/MathieuDoyon "MathieuDoyon (5 commits)")[![EspadaV8](https://avatars.githubusercontent.com/u/115825?v=4)](https://github.com/EspadaV8 "EspadaV8 (2 commits)")[![gontard](https://avatars.githubusercontent.com/u/1221664?v=4)](https://github.com/gontard "gontard (2 commits)")

---

Tags

laravellocalizationtranslationmodel

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k2.1M163](/packages/laravel-ai)[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3281.5M17](/packages/kkomelin-laravel-translatable-string-exporter)[codezero/laravel-localized-routes

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

544656.8k4](/packages/codezero-laravel-localized-routes)[tio/laravel

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

170333.8k](/packages/tio-laravel)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

4821.5k](/packages/erag-laravel-lang-sync-inertia)

PHPackages © 2026

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