ARCANEDEV / Localization

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

Can't translate url while switching language #131

Closed ddeshar closed 5 years ago

ddeshar commented 6 years ago

Description:

I am using this package for switching language but i am not able to translate url while switching language

for eg while i am in thai page http://project.woc/th/นิติบุคคล/ข่าว when i change language it will be like this http://project.woc/en/นิติบุคคล/ข่าว but it must be actually like this http://project.woc/en/individual/news

Here is my lang switcher

@foreach(Localization::getSupportedLocales() as $localeCode => $locale)
<li>
    <a rel="alternate" hreflang="{{ $localeCode }}" href="{{ Localization::getLocalizedURL($localeCode, url()->current()) }}{{ $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '' }}">
    <img src="{{ asset('front/images/flag_'.$localeCode.'.svg') }}">{{ $locale->native() }}
    </a>
</li>
@endforeach

My route

Route::group([
    // 'prefix'     => Localization::setLocale(),
    'middleware' => [
        'localization-session-redirect',
        'localization-redirect',
    ],
], function() {
        Route::get('/', function() {
            return view('index');
        })->name('index');

        Route::localizedGroup(function () {
            Route::group([
                'prefix' => trans('routes.individual'),
                'as'=>'individual.'
            ], function () {
                Route::get('/', 'IndiController@index')->name('index');

                Route::transGet('routes.news', 'IndiController@news')->name('news');
                Route::transGet('routes.newsdetail', 'IndiController@newsdetail')->name('newsdetail');
            });
        }); 

        Route::localizedGroup(function () {
            Route::group([
                'prefix' => trans('routes.corporate'),
                'as'=>'corporate.'
            ], function () {
                Route::get('/', 'CorController@index')->name('index');            

                Route::transGet('routes.news', 'CorController@news')->name('news');
                Route::transGet('routes.newsdetail', 'CorController@newsdetail')->name('newsdetail');
            });
        }); 
});

my lang/en & th routes

<?php
return [
    'individual'                    =>  'individual',
    'corporate'                     =>  'corporate',
    "news"                          =>  "news",
    "newsdetail"                    =>  "newsdetail/{slug}",
];

<?php
return [
    'individual'                    =>  'บุคคลธรรมดา',
    'corporate'                     =>  'นิติบุคคล',
    "news"                          =>  "ข่าว",
    "newsdetail"                    =>  "บทความ/{slug}",
];

so how can i translate my url while switch language

arcanedev-maroc commented 5 years ago

Check #139, #144