PHPackages                             johnnestebann/langravel - 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. johnnestebann/langravel

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

johnnestebann/langravel
=======================

Multi Localization for Laravel. The Easy Way

3.6.0(5y ago)1425MITPHPPHP &gt;=7.2

Since Jul 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/johnnestebann/langravel)[ Packagist](https://packagist.org/packages/johnnestebann/langravel)[ RSS](/packages/johnnestebann-langravel/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (16)Used By (0)

Langravel
=========

[](#langravel)

Multi Localization for Laravel. The Easy Way

Overview
--------

[](#overview)

If you are building a multilingual website and you need URL management then this is the package for you. It integrates into existing Laravel functionality to support translated URLs and custom locales.

**It supports route caching out of the box.**

This package simplified the whole setup and integration process about localization.

Whatever `mcamara/laravel-localization` package can do, Langravel can do too, but better.

### Features

[](#features)

- Simple installation
- Easy configuration
- Custom locales
- Hide default locale
- Translated routes
- Language selector
- Route caching
- Native Laravel helper functions (`route` and `url`)
- Support for non localized routes
- Slug translation

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

[](#installation)

From the command line:

```
composer require johnnestebann/langravel

```

Then, add the `Langravel` trait to your `RouteServiceProvider` class:

```
use Johnnestebann\Langravel\Langravel;

class RouteServiceProvider extends ServiceProvider
{
    use Langravel;
}

```

> If you don't intend to use translated URLs (by default it is set to false) then publish the route file with the command bellow. Otherwise be sure to publish the config file, set `useTranslatedUrls` to `true` and create appropriate route files `{locale}.web.php`.

Publish the localized routes file `langravel.web.php` to your `/routes` directory:

```
php artisan vendor:publish --provider="Johnnestebann\Langravel\ServiceProvider" --tag=route

```

Now, add `$this->mapLocalizedWebRoutes();` to the `map` method in the `RouteServiceProvider`.

**Installation complete!**

---

Put your localized routes in `/routes/langravel.web.php` file. If you are using translated URLs create a route file for each locale `{locale}.web.php` (eg. `en.web.php`). Your non localized routes can remain in the `/routes/web.php` file. To access non localized routes use `URL::getNonLocalizedRoute` or `URL::getNonLocalizedUrl`. See the helpers chapter bellow to find out more.

**That's it!** View the configuration chapter bellow to configure your preferences.

### Configuration

[](#configuration)

Publish the config file with:

```
php artisan vendor:publish --provider="Johnnestebann\Langravel\ServiceProvider" --tag=config

```

You will find it under `config/langravel.php`.

#### `supportedLocales` \[array\]

[](#supportedlocales-array)

Locale names (codes) can be whatever you want.

*example.* en-GB, hr-HR, en-US, english, croatian, german, de, fr, ...

```
'supportedLocales' => ['hr', 'en'],

```

#### `defaultLocale` \[string\]

[](#defaultlocale-string)

The default application locale must be from one of the locales defined in `supportedLocales`.

```
'defaultLocale' => 'en',

```

#### `hideDefaultLocale` \[boolean\]

[](#hidedefaultlocale-boolean)

If you want to hide the default locale in your URL set this to true. (The default is `true`.)

*example.* If your default locale is set to `en` then requests to URLs starting with `/en` will be redirected to `/`.

```
'hideDefaultLocale' => true,

```

#### `useTranslatedUrls` \[boolean\]

[](#usetranslatedurls-boolean)

This enables you to use localized routes. (The default is `false`.)

If you are using translated URLs for each locale then set this to `true`.

*example.* `/en/about-us` on `en` locale will be `/hr/o-nama` on `hr` locale.

```
'useTranslatedUrls' => true,

```

Once this option is set to `true` you have to create a routes file for each locale with the prefix of the locale.

`routes/en.web.php`:

```
