Multi languages in Laravel 5

Asked

Viewed 1,650 times

0

I am developing a project in Laravel 5, but I would like it to be in several languages. The language change would be by clicking on the link of each language and automatically translating the site in that language. Thank you.

1 answer

1


Automatically translating will never be perfect, and php or Laravel are not multilingual "databases" that interpret texts in different languages, they are programming language and framework respectively that run on back-end, who has to create the translation is you, using the programming.

However it is possible to make an automatic translation with Javascript and Google-Translate (which is front-end), but it’s like I said before "won’t be perfect" see an example in this answer:

However if you want to program, Laravel (pro examples 5.2) has Localization which is a way to design multi-language websites, the folder structure:

/resources
    /lang
        /en
            messages.php
        /pt
            messages.php

en/messages.php

<?php    
return [
    'welcome' => 'Welcome to our application'
];

pt/messages.php

<?php    
return [
    'welcome' => 'Bem vindo a sua aplicação'
];

An example of Route:

Route::get('welcome/{locale}', function ($locale) {
    App::setLocale($locale);

    //
});

This will not translate the information you see from the database, but rather the layout content and if you have a series of standard texts in the database it will be possible to translate them as long as you follow a unique pattern.

Documentation: https://laravel.com/docs/5.2/localization

  • 1

    Thank you so much man. Your answer helped so much. I’m even using the feature of Laravel "localization" and found it very cool. Brigadão.

Browser other questions tagged

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