Waavi/translation

Does it working in controllers?

SerikK opened this issue · 4 comments

Hi. Thanks for good extension. Does it working in controllers and models? What I am trying to do
trans('app.updated') not working. But following works:
trans('app.updated', [], UriLocalizer::localeFromRequest()).
I use files as translation source.

He SerikK,

Do you use the localize middleware? In there it automatically sets the default locale and you wouldn't need to explicitly define UriLocalizer::localeFromRequest().

It's the file Waavi\Translation\Middleware\TranslationMiddleware. You can use it like:

Route::group(['prefix' => UriLocalizer::localeFromRequest(), 'middleware' => 'localize'], function () {
    Route::get('/', ['as' => 'home', 'uses' => 'PublicController@index']);
});

Yes, I use that in routes/web.php.

I think you use "POST" route not GET

Waavi dose not work with POST

It does work with POST requests if it's not the first request the user makes and their language preference has been set in a cookie. However, this would not work in API.

We are considering making POST requests optional, would that work for you?