PHPackages                             leafs/lingo - 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. leafs/lingo

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

leafs/lingo
===========

Add multi language support to your Leaf applications with ease.

013PHP

Since Apr 4Pushed 1mo agoCompare

[ Source](https://github.com/leafsphp/lingo)[ Packagist](https://packagist.org/packages/leafs/lingo)[ RSS](/packages/leafs-lingo/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

 [![](https://camo.githubusercontent.com/e83224618735d048f0f70f04e02d7973a634a055e18d47fe22501e3a85e40b9f/68747470733a2f2f6c6561667068702e6e65746c6966792e6170702f6173736574732f696d672f6c656166332d6c6f676f2e706e67)](https://camo.githubusercontent.com/e83224618735d048f0f70f04e02d7973a634a055e18d47fe22501e3a85e40b9f/68747470733a2f2f6c6561667068702e6e65746c6966792e6170702f6173736574732f696d672f6c656166332d6c6f676f2e706e67)

Lingo
=====

[](#lingo)

[![Latest Stable Version](https://camo.githubusercontent.com/5f442fe6299887faf4f75dec99e5bde6112a1c68758359240a36f00ed7236140/687474703a2f2f706f7365722e707567782e6f72672f6c656166732f6c696e676f2f76)](https://packagist.org/packages/leafs/lingo)[![Total Downloads](https://camo.githubusercontent.com/40b30e83f77e0ebd37cf072f31f608be89b856b2e519c5714ac87617cea8ca55/687474703a2f2f706f7365722e707567782e6f72672f6c656166732f6c696e676f2f646f776e6c6f616473)](https://packagist.org/packages/leafs/lingo)[![License](https://camo.githubusercontent.com/4eb79b5a7c1e7c5a31e058571f16d80418ffd0e8d1d44c75de415b2463e29944/687474703a2f2f706f7365722e707567782e6f72672f6c656166732f6c696e676f2f6c6963656e7365)](https://packagist.org/packages/leafs/lingo)

Leaf Lingo is a simple but powerful module that adds multi language functionality to your leaf applications. It is baked into Leaf's core and allows you to easily translate your applications to multiple languages, without any hassle.

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

[](#installation)

You can easily install Lingo using [Composer](https://getcomposer.org/).

```
composer require leafs/lingo
```

Or with Leaf Cli

```
leaf install lingo
```

Quick Start Guide
-----------------

[](#quick-start-guide)

After installing Lingo, you only need to define your translation files. In Leaf MVC, you simply need to create an `app/locales` folder and add your translation files there. Translation files are written in YML, and can use languages like `en.yml` and `de.yml` or specific locales like `en_US.yml` and `pt_BR.yml`.

```
# app/locales/fr.yml

hero.title: "Bonjour le monde"
```

From there, you can use the `lingo()` helper function to translate strings in your views or controllers.

```
$heroTitle = lingo('hero.title'); // "Bonjour le monde"
```

In a Blade template, you can use it like this:

```
@lingo('hero.title')
```

Lingo Modes
-----------

[](#lingo-modes)

By default, Lingo uses routes for the translation strategy which means that if you have routes like this in your Leaf app:

```
app()->get('/home', function() {
    return response()->render('home');
});

app()->get('/about', function() {
    return response()->render('about');
});
```

Lingo will automatically create routes for each language like this:

```
/en/home
/fr/home
/en/about
/fr/about
```

This will be done automatically for you, based on the locales you have defined in your translation files. If you have `de.yml` and `fr.yml`, Lingo will create routes for `/de/*` and `/fr/*`. It will also set up redirects so that if a user visits `/home`, they will be redirected to the default language route, e.g. `/en/home`. The default language can be configured in your `.env` file with `APP_LOCALE=...`.

### Header Mode

[](#header-mode)

Header mode is useful when you are building an API with Leaf and want to support multiple languages based on the `Accept-Language` header sent by the client. In this mode, Lingo will **not** create language-specific routes, but will instead determine the language to use based on the `Accept-Language` header.

For example, if a client sends a request with the header `Accept-Language: fr`, Lingo will use the French translations for that request, even though the route is **not** prefixed with `/fr`.

To enable header mode, you need to set the following in your `.env` file:

```
LOCALES_STRATEGY=header
```

### Session Mode

[](#session-mode)

Session mode is useful when you want to allow users to switch languages without changing the URL structure. In this mode, Lingo will store the selected language in the user's session. When a user selects a language, Lingo will update the session with the chosen language, and all subsequent requests will use that language for translations. Again, there will be no language-specific routes created in this mode.

To enable session mode, you need to set the following in your `.env` file:

```
LOCALES_STRATEGY=session
```

Switching Locales
-----------------

[](#switching-locales)

Lingo uses the same approach for switching locales regardless of the mode you are using. You can use the `lingo()->setCurrentLocale()` method to create a route that handles locale switching. This will switch the current locale based on the strategy you have configured (routes or session). In header mode, this method will not have any effect since the locale is determined by the `Accept-Language` header.

Here is an example of how to create a route for switching locales:

```
app()->post('/language/switch', function() {
    $locale = request()->get('locale');

    return lingo()->setCurrentLocale($locale);
});
```

`setCurrentLocale()` will automatically redirect the user to the expected location based on the strategy you are using.

### Switcher Templating

[](#switcher-templating)

You can create a simple language switcher in your views. Here is an example of how to do this in a Blade template:

```

    @foreach(lingo()->getAvailableLocalesWithNames() as $locale => $name)
        getCurrentLocale() === $locale ? 'selected' : '' }}>{{ $name }}
    @endforeach

@lingo('welcome.title')
```

`getAvailableLocalesWithNames()` will return an array with the available locales as keys and the language names as values, so you can easily create a dropdown or any other UI element for switching languages, eg:

```
[
    'en_US' => 'English (US)',
    'es' => 'Español',
    'it' => 'Italiano',
    'zh' => '中文',
    'zh_CN' => '简体中文',
    'fr_FR' => 'Français (France)',
    'de_DE' => 'Deutsch (Deutschland)',
]
```

You can also use `getAvailableLocales()` if you just want the locale codes, eg:

```
[
    'en_US',
    'es',
    'it',
    'zh',
    'zh_CN',
    'fr_FR',
    'de_DE',
]
```

Now you should be able to display translations and switch between languages in your Leaf application using Lingo!

### Current Locale Info

[](#current-locale-info)

You can retrieve information about the current locale using the following methods:

- `lingo()->getCurrentLocale()`: Returns the current locale code (e.g., `en_US`, `de`, ...).
- `lingo()->getCurrentLanguage()`: Returns the current language code (not including region, e.g., `en`, `de`, ...).
- `lingo()->getDefaultLocale()`: Returns the default locale code as defined in your `.env` file or configuration.
- `lingo()->is()`: Checks if the current locale matches a given locale code.

Translation Parameters
----------------------

[](#translation-parameters)

Lingo supports translation parameters, allowing you to insert dynamic values into your translations. You can define placeholders in your translation strings using the `{{ parameterName }}` or `$parameterName` syntax. For example:

```
# app/locales/en.yml

greeting.message: "Hello, {{ name }}! Welcome to our website."
farewell.message: "Goodbye, $name! See you next time."
```

You can then pass an associative array of parameters to the `lingo()` function to replace the placeholders with actual values:

```
$message1 = lingo('greeting.message', ['name' => 'John']); // "Hello, John! Welcome to our website."
$message2 = lingo('farewell.message', ['name' => 'John']); // "Goodbye, John! See you next time."
```

Multi-language routes
---------------------

[](#multi-language-routes)

Some applications may require multi-language routes where certain parts of the URL are translated based on the current locale. For example, you might want `/en/products` to be `/fr/produits` in French. Lingo supports this functionality through Leaf's route parameters. Just define your routes as you always would, and then pass the route variants as an array to the route definition:

```
app()->get('/products', [
    'lingo.routes' => [
        'en' => '/products',
        'fr' => '/produits',
        'de' => '/produkte',
    ],
    'ProductsController@index'
]);
```

Leaf will automatically handle the routing based on the current locale, allowing you to have translated routes in your application. Switching between locales will still work as expected, and users will be redirected to the appropriate translated route, so no additional handling is required on your part.

Note that this feature only works with Lingo's route-based strategy.

Lingo URL
---------

[](#lingo-url)

When using Lingo's route-based strategy, you can generate localized URLs using the `lingo()->url()` method. This method takes a path as an argument and returns the localized URL based on the current locale.

```
$url = lingo()->url('home'); // e.g., "/en/home" or "/fr/home"
```

If you are not using the route-based strategy, this method will simply return the path as is.

Using Variants
--------------

[](#using-variants)

Lingo provides a convenient method called `variants()` that allows you to define different string variants based on the current locale. This is particularly useful for localizing routes or other strings that may not be part of the translation files.

```
$localizedRoute = lingo()->variants([
    'en' => '/products',
    'fr' => '/produits',
    'es' => '/productos',
]);
// e.g., "/en/products" or "/fr/produits" or "/es/productos"
```

Variants aren't just limited to routes; you can use them for text, URLs, or any other strings that need localization based on the current locale.

```
$greeting = lingo()->variants([
    'en' => 'Hello',
    'fr' => 'Bonjour',
    'es' => 'Hola',
]);
// e.g., "Hello" or "Bonjour" or "Hola"
```

We recommend using the translation files instead of `variants()` for most text translations, as it provides better organization and maintainability. However, `variants()` can be useful for quick translations which are non-repetitive or for localized routes.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance60

Regular maintenance activity

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 61.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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/29547806?v=4)[Mychi](/maintainers/Mychi)[@mychi](https://github.com/mychi)

---

Top Contributors

[![mychidarko](https://avatars.githubusercontent.com/u/26604242?v=4)](https://github.com/mychidarko "mychidarko (22 commits)")[![crosa7](https://avatars.githubusercontent.com/u/32076460?v=4)](https://github.com/crosa7 "crosa7 (12 commits)")[![MischaKr](https://avatars.githubusercontent.com/u/1812985?v=4)](https://github.com/MischaKr "MischaKr (2 commits)")

### Embed Badge

![Health badge](/badges/leafs-lingo/health.svg)

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

###  Alternatives

[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)[statikbe/laravel-chained-translator

The Laravel Chained Translator can combine several translators that can override each others translations.

36149.4k6](/packages/statikbe-laravel-chained-translator)

PHPackages © 2026

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