Plugin Development: Languages

Previous Section: Routes

Translate your plugin into different languages with ease.


File Structure

Translations are stored in the Lang folder, and within this directory there should be a subdirectory for each language supported. The files within each subdirectory must have the same names, as these are used as keys when calling the language strings. An example file structure where English and French are supported:


The file should contain an array of language key to language string, each key must be unique. Plurals can be defined by using a pipe (|) character between the words, and placeholders can be defined by starting a word with ':'.



    return [

        "hello_world"       => "Hello World",

        "setting"           => "Setting",
        "setting_desc"      => "A description of the setting.",

        "worlds"			=> "World|Worlds",
        "placeholder_for"   => "This is a placeholder for :item",



The language strings are available in the plugin namespace and can be called in the following way:


    Lang::get('Plugins#HelloWorld::lang.setting');                                // Setting
    Lang::choice('', 1);                            // World
    Lang::choice('', 2);                            // Worlds
    Lang::get('Plugins#HelloWorld::lang.placeholder_for', [ 'item' => 'Item' ]);  // This is a placeholder for Item

    {{ Lang.get('Plugins#HelloWorld::lang.setting') }}                            // Setting
    {{ Lang.choice('', 1) }}                        // World
    {{ Lang.choice('', 2) }}                        // Worlds
    {{ Lang.get('Plugins#HelloWorld::lang.placeholder_for', {'item': 'Item'}) }}  // This is a placeholder for Item

Overriding Translations

It is possible to override built-in language file translations. The example below overrides the addons/Languages/English/Lang/en/core.php submit_ticket translation and replaces it with the addons/Plugins/HelloWorld/Lang/en/lang.php translation.

    \Illuminate\Support\Facades\Lang::setParsedKey('core.submit_ticket', ['Plugins#HelloWorld', 'lang', 'world']);

The second argument is an array list of each individual component of the key. The : and . characters are emitted.

Next Section: Views