Localization

Introduction

The application can be managed multilingual. The translation in the frontend can be done in php using laravel's localization service or in vue using vue-i18n. It uses the syntax of laravel. All translation strings are formatted so they can be used in vue-i18n as well.

In Laravel applications that include the package, there are two different locales, one for your website and one for the admin application. So for example, a user can manage german content in the admin application and still see the interface in the english version.

The following examples refer to the translations which look like this:

return [
    "welcome": "Welcome, :name"
];

PHP

To compile for the locale of the admin interface the __lit() helper method is used, just like __() from laravel's localization.

__lit('messages.welcome', ['name', 'Jannes'])

Pluralization can be used with the __lit_choice function or the short version __lit_c.

'apples' => '{0} There are none|[1,19] There are some|[20,*] There are many',

...

__lit_choice('apples', 10)
__lit_c('apples', 10)

Vue

In Vue the vue-i18n format is used.

<template>
    <div>
        {{ $t('messages.welcome', { name: 'Jannes' }) }}
    </div>
</template>

You may also use the Larvel localization helpers in Vue components.

  • __()
  • trans()
  • trans_choice()

Determine Locale

To determine the locale the function getLocale can be used on the Lit facade like this:

use Ignite\Support\Facades\Lit;

$litLocale = Lit::getLocale();

if (Lit::isLocale('en')) {
    //
}

Add Path

By default the path lit/resources/lang is imported for the admin translation. You can register any number of paths with localization files in your service providers. However, it is recommended to keep the translations for the admin application and your website separate.

use Ignite\Support\Facades\Lang;

Lang::addPath(base_path('yourpath/lang/'));

All translation attributes are merged, which makes it easy to extend existing localizations for parts like validation or others.

Join us on our discord server