PHPackages                             hanoivip/language - 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. hanoivip/language

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

hanoivip/language
=================

Language switcher package for Laravel.

126PHP

Since Apr 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/hanoivip/language)[ Packagist](https://packagist.org/packages/hanoivip/language)[ RSS](/packages/hanoivip-language/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Language switcher package for Laravel.
======================================

[](#language-switcher-package-for-laravel)

[![Version](https://camo.githubusercontent.com/21d9b3fd884d28043572f78599343ed7b728200227c0b96c8bbd75db01f7f37d/68747470733a2f2f706f7365722e707567782e6f72672f616b61756e74696e672f6c616e67756167652f762f737461626c652e737667)](https://github.com/akaunting/language/releases)[![Downloads](https://camo.githubusercontent.com/283909135d8521cdc51fed208c87a2ffc5ff4ba1d9f8b0271c474cffdf8502a4/68747470733a2f2f706f7365722e707567782e6f72672f616b61756e74696e672f6c616e67756167652f642f746f74616c2e737667)](https://github.com/akaunting/language)[![StyleCI](https://camo.githubusercontent.com/e0c029c78135042c54ad27fcba5455cb427e1b166e03d15ac542418e4d75eaf1/68747470733a2f2f7374796c6563692e696f2f7265706f732f3130323239303234392f736869656c643f7374796c653d666c6174266272616e63683d6d6173746572)](https://styleci.io/repos/102290249)[![Quality](https://camo.githubusercontent.com/a8c2b7d44fd32249e2906703786c4d7820c984f33866e4eeca4e81a915a58637/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616b61756e74696e672f6c616e67756167652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/akaunting/language)[![License](https://camo.githubusercontent.com/fef8ba5e37e547111f2b12953ce24fb8c69e1eead2c382849a3a9eb8fa7331f9/68747470733a2f2f706f7365722e707567782e6f72672f616b61756e74696e672f6c616e67756167652f6c6963656e73652e737667)](LICENSE.md)

This package allows switching locale easily on Laravel projects. It's so simple to use, once it's installed, your App locale will change only by passing routes into SetLanguage middleware.

**Top features:**

- Change automatically app locale depending on user browser configuration
- Language flags built-in for easy implementation
- Get language name like 'English' or 'Español' from codes such as 'en' or 'es'
- Option to choose short (en) or long (en-GB) language code
- Store locale on users table
- Restrict users to set languages you don't have translations
- Helper functions for clean, simple and easy to read API
- Supports Carbon and Date packages

Getting Started
---------------

[](#getting-started)

### 1. Install

[](#1-install)

Run the following command:

```
composer require akaunting/language

```

### 2. Register (for Laravel &lt; 5.5)

[](#2-register-for-laravel--55)

Register the service provider in `config/app.php`

```
Akaunting\Language\Provider::class,
```

Add alias if you want to use the facade.

```
'Language'   => Akaunting\Language\Facade::class,
```

### 3. Publish

[](#3-publish)

Publish config, migration and blade files.

```
php artisan vendor:publish --tag=language

```

### 4. Migrate

[](#4-migrate)

Add locale column to users table:

```
php artisan migrate

```

### 5. Configure

[](#5-configure)

Default values can be modified also on `config/language.php`

#### Keys

[](#keys)

- route: Makes route available
- carbon: Sets briannesbitt/carbon translator language
- date: Sets jenssegers/date translator language
- home: Make home route available
- auto: Sets language automatically depending on user's browser config
- prefix: Prefix of routes URI to set locale
- middleware: default middleware to set locale
- controller: default controller to handle locale
- flags: Settings such as width, class etc for flags
- mode: The language code and name mode
- allowed: Allowed language codes
- all: Available language names and codes

Usage
-----

[](#usage)

### Middleware

[](#middleware)

All routes in which you want to set language should be under the `language`middleware to set at each request to App locale.

```
Route::group(['middleware' => 'language'], function () {

    // Here your routes

});
```

### URL

[](#url)

- Via URL with return home: /languages/{locale}/home
- Via URL with return back: /languages/{locale}/back

**Tip:** */languages prefix can be changed from `config/language.php`*

Methods
-------

[](#methods)

### language()-&gt;allowed()

[](#language-allowed)

Returns an array with `[$code => $name]` for all allowed languages of config. Example usage on blade:

```
@foreach (language()->allowed() as $code => $name)
    {{ $name }}
@endforeach
```

### language()-&gt;flags()

[](#language-flags)

Returns an output with flags for all allowed languages of config. Output can be changed from `resources/views/vendor/language` folder

### language()-&gt;flag()

[](#language-flag)

Returns the flag of the current locale. Output can be changed from `resources/views/vendor/language` folder

### language()-&gt;names($codes = null)

[](#language-namescodes--null)

Get an array like `[$code => $name]` from an array of only $codes.

### language()-&gt;codes($langs = null)

[](#language-codeslangs--null)

Get an array like `[$name => $code]` from an array of only $langs.

### language()-&gt;back($code)

[](#language-backcode)

Returns the URL to set up language and return back: `back()`

Also if you prefer to use directly route() function you can use it as following code:

```
{{ route('language::back', ['locale' => $code]) }}
```

### language()-&gt;home($code)

[](#language-homecode)

Returns the URL to set language and return to home: `url('/')`

Also if you prefer to use directly route() function you can use it as following code:

```
{{ route('language::home', ['locale' => $code]) }}
```

### language()-&gt;getName($code = 'default')

[](#language-getnamecode--default)

Returns the language name of `$code` if specified or the current language set if not.

**Tip:** *Use app()-&gt;getLocale() to get the current locale*

### language()-&gt;getCode($name = 'default')

[](#language-getcodename--default)

Returns the language code of `$name` if specified or the current language set if not.

Changelog
---------

[](#changelog)

Please see [Releases](../../releases) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Denis Duliçi](https://github.com/denisdulici)
- [Aitor Riba Archilla](https://github.com/24aitor)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.# language

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

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://www.gravatar.com/avatar/a45208b20482235c83ed370f71c352d516693ace0dac53c7ed8244cace45682b?d=identicon)[hanoivip](/maintainers/hanoivip)

### Embed Badge

![Health badge](/badges/hanoivip-language/health.svg)

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[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)

PHPackages © 2026

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