Posted: 08-10-2017

Laravel Translation Strings

Laravel Translation Strings

Laravel provides a very powerfull and easy to use feature to localize and translate strings.

Typically, translation 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: 

/resources
    /lang
        /en
            messages.php
        /es
            messages.php

You may retrieve lines from language files using the  __ helper function according you current locale setting.

echo __('messages.welcome');

or in blade

{{ __('messages.welcome') }}

@lang('messages.welcome')


But how to retrive a translation string from a language different from the current locale?

Looking to the  laravel code  i've  just discovered that __ helper function accepet as additional third parameter a locale code so you can easy translate a string in any language.

laravel translate

So you can easy get translation in this way:

// default locale is en

        __('message.remember_me'); // return remember me


        __('message.remember_me',[],'it'); // return ricordati


        __('message.remember_me',[],'es'); // return recuerda

More info about Localization can be found @ Laravel documentation