ARCANEDEV / Localization

:globe_with_meridians: Localization package for Laravel
MIT License
187 stars 37 forks source link

Translation doesnt persist? #59

Closed thusfar7 closed 8 years ago

thusfar7 commented 8 years ago

So I have two locales: en and hr.

I have to routes files. One in /app/Http/routes.php

and other one in /vendor/laravel/spark/src/Htpp/routes.php (assigns routes to $router variable)

Now when I got to /dashboard which is defined in original Laravel routes.php like this

Route::localizedGroup(function () {
    /*  Middleware Auth  */
    Route::group(['prefix' => 'dashboard', 'middleware' => ['auth', 'subscribed']], function () {
        Route::get('/', [
            'as' => 'dashboard',
            'uses' => 'DashboardController@index'
        ]);
    });
    // ...

and then it takes me to /en/dashboard or /hr/dasdashboard. That's great. And there I switch to /en/dashboard

Then I go to '/settings' route. No locale prefixed and it always takes me to /hr/settings but I was on /en/dashboard.

Why does it change locale for no reason? That route '/settings' is defined in Spark's routes.php

$router->group([
    'prefix'     => Localization::setLocale(),
    'middleware' => [
        'localization-session-redirect',
        'localization-redirect',
    ],
], function($router) {
    $router->group(['middleware' => 'web'], function ($router) {

    // ...
       // Settings Dashboard...
        $router->get('/settings', 'Settings\DashboardController@show');
    // ...

Also my localization.php

    /* ------------------------------------------------------------------------------------------------
     |  Settings
     | ------------------------------------------------------------------------------------------------
     */
    'supported-locales'      => ['en', 'hr'],

    'accept-language-header' => true,

    'hide-default-in-url'    => false,

    'facade'                 => 'Localization',

    /* -----------------------------------s-------------------------------------------------------------
     |  Route
     | ------------------------------------------------------------------------------------------------
     */
    'route'                  => [
        'middleware' => [
            'localization-session-redirect' => true,
            'localization-cookie-redirect'  => false,
            'localization-redirect'         => true,
            'localized-routes'              => true,
            'translation-redirect'          => true,
        ],
    ],

So why Locale /en doesnt persist and why is it always changed to hr???

arcanedev-maroc commented 8 years ago

What is your default locale inside 'app.locale' ?

Can you use this route for 'settings' instead and see if it solves your issue :

$router->localizedGroup(function($router) {
    $router->group(['middleware' => 'web'], function ($router) {

    // ...
       // Settings Dashboard...
        $router->get('/settings', 'Settings\DashboardController@show');
    // ...

Honestly, i never used spark and i don't know if it's gonna effect your localization or not.

UPDATE:

thusfar7 commented 8 years ago

I move web middleware before Localization middlewares. It seems that solved the problem. I guess when web middleware is set after localization middlewares, localization doesnt persist.

I dont know if that is general problem or just in my case, but it is worth mentioning.