Localization

Definition

A localization file is used to translate all the labels present in a module. To do this it is necessary to create a translation file per module and per language.

You can have more information about localization in the Laravel official documentation.

Example

Here is the english localization file of the User module.

<?php

return [
    'user' => 'Users',
    'block' => [
        'auth' => 'Authentication',
        'contact' => 'Contact',
        'roles' => 'Roles',
    ],
    'field' => [
        'username' => 'Username',
        'name' => 'Name',
        'is_admin' => 'Is admin?',
        'password' => 'Password',
        'password_confirmation' => 'Password (confirmation)',
        'email' => 'Email',
        'current_password' => 'Current password',
        'new_password' => 'New password',
        'new_password_confirm' => 'New password (confirmation)',
    ],
    'relatedlist' => [
        'groups' => 'Groups',
    ],
    'label' => [
        'no_role' => 'No related role',
        'my_account' => 'My account',
        'avatar_type' => 'Avatar type',
    ],
    'account' => [
        'profile' => 'Profile',
        'avatar' => 'Avatar',
        'password' => 'Password',
        'upload_image' => 'Upload an image',
        'avatar_type' => [
            'initials' => 'Initials',
            'gravatar' => 'Gravatar',
            'image' => 'Image',
        ],
        'avatar_description' => [
            'initials' => 'An avatar containing initials will be generated from the user name.',
            'gravatar' => 'Go to :url to configure your avatar. It will be associated to your email address.',
            'image' => 'Upload an image from your computer.',
        ],
    ],
    'error' => [
        'current_password' => 'The current password is not correct.',
    ],
    'success' => [
        'profile_updated' => 'The profile has been updated!',
        'avatar_updated' => 'The avatar has been updated!',
        'password_updated' => 'The password has been updated!'
    ],
];

The field named field.name is translated into Name. The block name block.auth is translated into Authentication.

Create a localization file

For each module you have to create a localization file for each language you want to use.

To do this, simply create a file located at resources/lang/{lang_code}/{module_name}.php. Add a translation key for the module's name like (e.g. 'person' => 'People'). This translation is used in several places, like in the menu.

Override a localization file

You can easily override a localization file from another package. For more information, please refer to the Overriding documentation.

Last updated