PHPackages                             leanadmin/gloss - 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. leanadmin/gloss

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

leanadmin/gloss
===============

Brilliant localization for Laravel

v0.1.11(3y ago)385.4k↓91.7%5MITPHP

Since Dec 13Pushed 3y ago2 watchersCompare

[ Source](https://github.com/archtechx/gloss)[ Packagist](https://packagist.org/packages/leanadmin/gloss)[ GitHub Sponsors](https://github.com/stancl)[ RSS](/packages/leanadmin-gloss/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (4)Versions (14)Used By (0)

🔍 Gloss ✨ — Brilliant localization for Laravel
==============================================

[](#-gloss---brilliant-localization-for-laravel)

Gloss is a Laravel package for advanced localization.

Laravel's localization system is perfect for many languages, but it breaks down when you need a bit more control.

For example, some languages change words depending on the context they're used in. The words may get prefixed, suffixed, or even changed completely.

Aside from adding support for complex languages, Gloss also ships with quality of life improvements such as the ability to add formatting to a translation string.

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

[](#installation)

Laravel 6 or 8 is required, PHP 7.4 is required.

```
composer require leanadmin/gloss

```

Configuration
-------------

[](#configuration)

By default, Gloss comes with the `gloss()` helper and `___()` helper.

If you wish, you may disable the `___()` helper by setting:

```
use Gloss;

Gloss::$underscoreHelper = false;
```

And if you wish to make all existing `__()` calls Gloss-aware:

```
use Gloss;

Gloss::$shouldReplaceTranslator = true;
```

A good place for these calls is the `boot()` method of your `LeanServiceProvider` or `AppServiceProvider`.

Usage
-----

[](#usage)

Gloss can be used just like the standard Laravel localization helpers:

```
___('Create :Resource', ['resource' => 'product']);

// 'resources.edit' => 'Show :Resource :title'
gloss('resources.create', ['resource' => 'product', 'title' => 'MacBook Pro 2019']); // Show Product MacBook Pro 2019

// 'notifications.updated' => ':Resource :title has been updated!'
Gloss::get('resources.edit', ['resource' => 'product', 'title' => 'iPhone 12']); // Product iPhone 12 has been updated!

// 'foo.apple' => 'There is one apple|There are many apples'
Gloss::choice('foo.apple', ['count' => 2]); // There are many apples
```

However, unlike the standard localization, it lets you make changes to these strings on the fly:

### Value overrides

[](#value-overrides)

Imagine that you're editing the `Order` resource in an admin panel. Your resource's singular label is `Objednávka`, which is Czech for `Order`.

The language string for the create button is

```
// Original in English: 'create' => 'Create :Resource',
'create' => 'Vytvořit :Resource',
```

If we fill the value with the resource name, we get `Vytvořit Objednávka`. Unfortunately, that's wrong not once, but twice.

Firstly, it should be Objednávk**u**, because the suffix changes with context. And secondly, it's grammatically incorrect to capitalize the word here.

```
- Vytvořit Objednávka
+ Vytvořit objednávku
```

So we want to specify a **complete override** of that language string whenever we're in the `Order` resource context.

To do this, simply call:

```
Gloss::value('resource.create', 'Vytvořit objednávku');
```

(From an appropriate place, where the application is working with the Order resource.)

If you're using Lean, this is taken care of for you. You can simply define entire language strings in the `$lang` property of your resource, and they'll be used in all templates which use the resource.

Also note that the example above mentions resources, but that's just how Lean is implemented. Gloss will work with any setup.

You can also set multiple value overrides in a single call:

```
Gloss::values([
    'resource.create' => 'Vytvořit objednávku',
    'resource.edit' => 'Upravit objednávku',
]);
```

You may also use the `gloss()` helper for this. Simply pass the array as the first argument.

### Scoping overrides

[](#scoping-overrides)

Sometimes you may want to scope your overrides. For example, rather than overriding all `resource.create` with `Vytvořit objednávku`, you may want to only do that if the `resource` parameter is `order`.

To do this, pass a third argument:

```
Gloss::value('resource.create', 'Vytvořit objednávku', ['resource' => 'order');
```

The condition can also be passed to `values()`:

```
Gloss::values([
    'resource.create' => 'Vytvořit objednávku',
    'resource.edit' => 'Upravit objednávku',
], ['resource' => 'order']);
```

Or to the `gloss()` helper when setting overrides:

```
gloss([
    'resource.create' => 'Vytvořit objednávku',
    'resource.edit' => 'Upravit objednávku',
], ['resource' => 'order']);
```

### Key overrides

[](#key-overrides)

To build up on the example above, let's say our admin panel uses multiple languages. So replacing the language string with a translation that's part of the code isn't feasible.

For this reason, Gloss also lets you alias keys to another keys:

```
// 'orders.create' => 'Vytvořit objednávku',
// 'resources.create' => 'Vytvořit :resource',

Gloss::key('resource.create', 'orders.create');
```

This is equivalent to fetching the value using a translation helper.

```
Gloss::value('resource.create', gloss('orders.create'));
Gloss::key('resource.create', 'orders.create');
```

As with `value()`, you can pass conditions:

```
Gloss::key('resource.create', 'orders.create', ['resource' => 'order');
```

### Extending values

[](#extending-values)

You may also build upon fully resolved language strings.

For example, consider the following example:

```
Showing 10 to 20 of 50 results.
```

To localize this, we'd either have to localize each word separately (which is what Laravel does, and it breaks down similarly to the "Order" word example), or we'd have to add the markup to the translation strings (which sucks for security, translator life quality), or we'd have to ditch the formatting completely.

All of those are unnecessary trade-offs.

Gloss lets you add formatting after the string is fully built:

```
// 'pagination' => 'Showing :start to :end of :total results',

Gloss::extend('foo.pagination', fn ($value, $replace) => $replace($value, [
    ':start' => ':start',
    ':end' => ':end',
    ':total' => ':total',
]));

Gloss::get('foo.pagination', ['start' => 10, 'end' => 20, 'total' => 50])
// Showing 10 to 20 of 50 results
```

Of course, `extend()` works perfectly with localized strings:

```
// 'pagination' => 'Zobrazeno :start až :end z :total výsledků',

// Zobrazeno 10 až 20 z 50 výsledků
```

It even works with pluralized/choice-based strings:

```
// 'apples' => '{0} There are no apples|[1,*]There are :count apples'

Gloss::extend('foo.apples', fn ($apples, $replace) => $replace($apples, [
    ':count' => ':count',
]));

gloss()->choice('foo.apples', 0); // There are no apples
gloss()->choice('foo.apples', 5); // There are 5 apples
```

The second argument is a callable that can return any string, but in most cases this will simply be the resolved string with a few segments replaced.

For that reason, Gloss automatically passes `$replace` to the callable, which lets you replace parts of the string using beautiful, arrow function-compatible syntax.

```
// So elegant!

fn ($string, $replace) => $replace($string, [
   'elegant' => 'eloquent',
]);

// So eloquent!
```

### Callable translation strings

[](#callable-translation-strings)

Gloss also adds support for callable translation strings.

Those can be useful when you have some code for dealing with things like inflection.

For example, consider these three language strings:

```
'index' => ':resources',
'create' => 'Create :resource',
'edit' => 'Edit :resource :title',
'delete' => 'Delete :resource :title',
```

In many languages that have declension (inflection of nouns, read more about the complexities of localization on [in our documentation](https://lean-admin.dev/docs/localization)), the form of `:Resource` will be the same for `create`, `edit`, and `delete`.

It would be painful to translate each string manually for no reason. A better solution is to use intelligent inflection logic **as the default, while still keeping the option to manually change specific strings if needed**.

```
'index' => fn ($resource) => nominative($resource, 'plural'),
'create' => fn ($resource) => 'Vytvořit ' . oblique($resource, 'singular'),
'edit' => fn ($resource, $title) => 'Upravit ' . oblique($resource, 'singular') . $title,
'delete' => fn ($resource, $title) => 'Smazat ' . oblique($resource, 'singular') . $title,
```

You could have logic like this (with your own helpers) for the default values, and only use the overrides when some words are have irregular grammar rules and need custom values.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.8% 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 ~72 days

Recently: every ~175 days

Total

12

Last Release

1234d ago

### Community

Maintainers

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

---

Top Contributors

[![stancl](https://avatars.githubusercontent.com/u/33033094?v=4)](https://github.com/stancl "stancl (46 commits)")[![abrardev99](https://avatars.githubusercontent.com/u/54532330?v=4)](https://github.com/abrardev99 "abrardev99 (1 commits)")[![lukinovec](https://avatars.githubusercontent.com/u/34375937?v=4)](https://github.com/lukinovec "lukinovec (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/leanadmin-gloss/health.svg)

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

###  Alternatives

[barryvdh/laravel-translation-manager

Manage Laravel Translations

1.7k3.8M18](/packages/barryvdh-laravel-translation-manager)[illuminate/validation

The Illuminate Validation package.

18838.2M1.7k](/packages/illuminate-validation)[tanmuhittin/laravel-google-translate

Translate translation files to other languages using google translate api

4342.3M11](/packages/tanmuhittin-laravel-google-translate)[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3301.5M20](/packages/kkomelin-laravel-translatable-string-exporter)[tio/laravel

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

170341.2k](/packages/tio-laravel)[conedevelopment/i18n

Push your translations to the front-end.

128143.2k3](/packages/conedevelopment-i18n)

PHPackages © 2026

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