What does "{{ __('Login') }}" mean in the Laravel layouts file?

Asked

Viewed 1,571 times

3

In the archive \resources\layouts\app.blade.php has the following line 37:

{{ __('Login') }}

It seems that this is a Helper. But what is its meaning/functioning? I ask this because depending on the case I want to see if it is possible to perform implementations derived from it.

Laravel 5.6

  • This is in the new installation?

1 answer

7


The function "helper" __() Standard performs the translation of the string or translation key according to the user’s location, as informed in the official documentation. You can spend both configuring according to your files localization:

Example:

Resources/lang/en/messages.php:

return [
    'welcome' => 'Seja bem-vindo a site!'
];

Resources/lang/es/messages.php:

return [
    'welcome' => 'Bienvenido al sitio!'
];

To display the snippet with translation:

echo __('messages.welcome'); //se espanhol: 'Bienvenido al sitio!', se português: 'Seja bem-vindo ao site!'

You can also use literal strings to perform the translation, using files .json within the same directory:

Resources/lang/es.json:

{
    "Eu amo programar.": "Me encanta programar."
}

To display:

echo __('Eu amo programar'); //se espanhol: 'Me encanta programar.'

  • 1

    Cool, and this one {{ __('Login') }} it searches in which file by default?

  • 1

    There is no default file. If you set __('login.usuario'), for example, and you don’t have a file with the language parameters you set, the string will appear literally "login.usuario" on the page. What you can do is use a string like Nome de usuário and then configure the languages to translate this string using jsons. Anyway you should use the localization to do translations.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.