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

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

gentor/polyglot
===============

Laravel localization helpers and models

1.4.0(10y ago)0908MITPHPPHP &gt;=5.4.0

Since Aug 8Pushed 8y ago1 watchersCompare

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

READMEChangelogDependencies (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`, then add `Polyglot\PolyglotServiceProvider` to the `providers` array in `app/config/app.php`.

Publish config to your laravel app : `php artisan vendor:publish --provider=Polyglot\PolyglotServiceProvider`

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

[](#model-localization)

Using the polyglot trait on a model 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 Model
{
  use Polyglot\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
URL::switchLanguage('fr') // Returns the current url with different locale

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

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 80.9% 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

3967d 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/210fd495e96c05caab1d50c09165794ff73175a9b49c43f91df0c8524dfa8add?d=identicon)[gentor](/maintainers/gentor)

---

Top Contributors

[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (144 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)")[![DMeganoski](https://avatars.githubusercontent.com/u/288899?v=4)](https://github.com/DMeganoski "DMeganoski (3 commits)")[![EspadaV8](https://avatars.githubusercontent.com/u/115825?v=4)](https://github.com/EspadaV8 "EspadaV8 (2 commits)")[![gentor](https://avatars.githubusercontent.com/u/2902504?v=4)](https://github.com/gentor "gentor (2 commits)")[![gontard](https://avatars.githubusercontent.com/u/1221664?v=4)](https://github.com/gontard "gontard (2 commits)")[![bramdevries](https://avatars.githubusercontent.com/u/1002245?v=4)](https://github.com/bramdevries "bramdevries (2 commits)")[![ivandokov](https://avatars.githubusercontent.com/u/2357455?v=4)](https://github.com/ivandokov "ivandokov (1 commits)")

---

Tags

laravellocalizationtranslationmodel

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3291.4M10](/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.

543638.1k4](/packages/codezero-laravel-localized-routes)[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)[longman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

5514.4k1](/packages/longman-laravel-multilang)[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)
