chinleung / laravel-multilingual-routes

A package to handle multilingual routes in your Laravel application.
https://github.com/chinleung/laravel-multilingual-routes-demo
MIT License
395 stars 25 forks source link

locale() method never return "en" for default (for fallback lang) route #56

Closed NDruce closed 3 years ago

NDruce commented 3 years ago

Describe the bug

I setup and configured all by instruction, even inserted required row into $middlewareGroups in Kernel, and I have this language list in config/locales.php:

    'supported' => [
        'en',
        'de',
    ],

And that route:

/**
 * Main page
 */
Route::multilingual('/', 'IndexController@index')->name('index');

And when I request site via mysite.com/de, {{ locale() }} returns de. But when I access site via mysite.com, {{ locale() }} return me de too, not en. How to solve that? And is it right practice to make translation for whole page content via code like this (in Blade template of page):

@if (locale() == 'de')
    de content
@else
    en content
@endif

I want to create pages like FAQ, About us, Contacts and more, supporting multiple languages (I think I'll have only two langs). Thank you so much.

NDruce commented 3 years ago

Solved! Sorry, I forgot for .env file, it was contain non-english default locale