Localization

The Laravel facade provides a convenient way of retrieving strings in various languages, allowing you to easily support multiple languages within your application.

Language Files

Language strings are stored in files within the resources/lang directory. Within this directory there should be a subdirectory for each language supported by the application.

Example Language File

Language files simply return an array of keyed strings. For example:

  1. <?php
  2. return [
  3. 'welcome' => 'Welcome to our application'
  4. ];

Changing The Default Language At Runtime

The default language for your application is stored in the config/app.php configuration file. You may change the active language at any time using the App::setLocale method:

Setting The Fallback Language

You may also configure a "fallback language", which will be used when the active language does not contain a given language line. Like the default language, the fallback language is also configured in the config/app.php configuration file:

  1. 'fallback_locale' => 'en',

Retrieving Lines From A Language File

The first segment of the string passed to the get method is the name of the language file, and the second is the name of the line that should be retrieved.

You may also use the trans helper function, which is an alias for the Lang::get method.

  1. echo trans('messages.welcome');

Making Replacements In Lines

You may also define place-holders in your language lines:

  1. 'welcome' => 'Welcome, :name',

Then, pass a second argument of replacements to the method:

  1. echo Lang::get('messages.welcome', ['name' => 'Dayle']);

Determine If A Language File Contains A Line

Pluralization

  1. 'apples' => 'There is one apple|There are many apples',

You may then use the Lang::choice method to retrieve the line:

    You may also supply a locale argument to specify the language. For example, if you want to use the Russian (ru) language:

    1. echo Lang::choice('товар|товара|товаров', $count, [], 'ru');

    Since the Laravel translator is powered by the Symfony Translation component, you may also create more explicit pluralization rules easily:

    For localization for validation errors and messages, take a look at the .

    Overriding Package Language Files