PHPackages                             netstudio/loki - 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. netstudio/loki

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

netstudio/loki
==============

Laravel localization done right.

8.0(5y ago)05.7kMITPHPPHP &gt;=7.2

Since Jul 6Pushed 8mo agoCompare

[ Source](https://github.com/netstudio/loki)[ Packagist](https://packagist.org/packages/netstudio/loki)[ Patreon](https://www.patreon.com/laravelista)[ RSS](/packages/netstudio-loki/feed)WikiDiscussions master Synced 1mo ago

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

Loki
====

[](#loki)

Laravel localization done right.

[![Become a Patron](https://camo.githubusercontent.com/16fde1abb7601eba23de38f592bc54e3a7d10da24ac58db594d7fab32d449d46/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4265636f6d65253230612d506174726f6e2d6639363835342e7376673f7374796c653d666f722d7468652d6261646765)](https://www.patreon.com/laravelista)

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.**

Before, I was using [mcamara/laravel-localization ](https://github.com/mcamara/laravel-localization) to handle this, but I really really needed route caching to work. So, I created this package and simplified the whole setup and integration process.

Whatever `mcamara/laravel-localization` package can do, Loki 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 netstudio/loki

```

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

```
use Laravelista\Loki\Loki;

class RouteServiceProvider extends ServiceProvider
{
    use Loki;
}

```

> 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 `loki.web.php` to your `/routes` directory:

```
php artisan vendor:publish --provider="Laravelista\Loki\ServiceProvider" --tag=route

```

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

**Installation complete!**

---

Put your localized routes in `/routes/loki.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="Laravelista\Loki\ServiceProvider" --tag=config

```

You will find it under `config/loki.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`:

```
