It's quite easy just add a route to your routes/web.php and fill in the following code Route::get('language/{language}', function ($language) { Session()->put('locale', $language); \App::setLocale($language); return redirect()->back(); })->name('language'); Make sure to use inertia link to switch the language instead of ahref or axios for the page to be reloaded On your vue add the following link Arabic
@@waiylkarim That should be a put request form submission not a get request, no? Can't see a reason their browser would need to actually visit the address
Thanks for this tutorial. I'm getting error message in translations.js file "Type annotatins can only be used in TypeScript files. ts(8010)". I try to implement your instructions in Laravel 11 Inertia and Vue. Difference is that lang folder is now in root application folder and I use base_path instead of resource path but that isn't a problem because I'm getting lang data (both php and json) in page source, so php code is ok. Problem is in javascript. I install Inertia and Vue using laravel/breeze package. Can you make same tutorial using Laravel 11 and breeze package with Inertia and Vue? Thanks in advance.
Genius work I can see here, but something I can't understand: Why we include all the translations in script tag? Imagine we have 10.000 sentence with sessions etc ... The page will be like a snail. I loved your job
@@EL_PANDA_742 i am about to do this on a new project, and was thinking about injecting them from inertiajs middleware based on the page i am on, based on the route name based on the page i am on, additionally caching them in the state manager and only retrieving them if the page was never accessed before on the current visit
This is one amazing tutorial. Thank you so much for this! I have a bit of newbie question here, as I was learning vue, the instructor suggested not to use mixins as they are fraud upon in the community. Since this is a 2 years old video, would you recommend an alternative approach?
One problem with phpsources - we need to prefix all keys with the name of the file, so not "failed" but "auth.failed". I'm looking for an elegant solution, but didn't find for now Maybe you can help?
Been using almost the same approach but I like yours better especially the introduction of replacements. Keep up the good work
I love your approach! It is so clear and maintainable! I can adjust every single inch to my project needs. Thanks a lot for that!
Glad you found it helpful! 😀
Awesome tutorial!!! Thanx a lot
You are the life saver man.... Lots of love
hi. that was a really great video. can you make a video on how to build a laravel package?
This is sooo awesoome!! Thank you
Thank you, but not working in ssr mode , Is there any way to make it work with ssr ?
big thank for this tutorial is very helpful.
Glad it was helpful!
Laravel + Inertia + Vue: localization/translation in this stack is tricky. There are only 2 documents about it on internet
it is really nice video but can you show us how to change the language(switch locals)?
It's quite easy just add a route to your routes/web.php and fill in the following code
Route::get('language/{language}', function ($language) {
Session()->put('locale', $language);
\App::setLocale($language);
return redirect()->back();
})->name('language');
Make sure to use inertia link to switch the language instead of ahref or axios for the page to be reloaded
On your vue add the following link
Arabic
@@waiylkarim That should be a put request form submission not a get request, no? Can't see a reason their browser would need to actually visit the address
@@bentomlin That could work too, but since you are not interacting with the database, it's better to use GET over PUT
@@waiylkarim Where do you imagine you'd store locale/language preferences on the servers if not in the database?
@@bentomlin It's what Cookies are for, mate
What about other translation features like pluralization, choice() etc? Maybe after 2 years some packages appeared in which all this is implemented?
Thank you, K.I.S.S. methodogy is still the best! Can you explain how to switch from Mixin to Composable on such cases?
Unfortunately it doesn't work for component. I just see {{.__('Create') }} in title...
Ok, the solution could be instead of
Thanks for this tutorial. I'm getting error message in translations.js file "Type annotatins can only be used in TypeScript files. ts(8010)". I try to implement your instructions in Laravel 11 Inertia and Vue. Difference is that lang folder is now in root application folder and I use base_path instead of resource path but that isn't a problem because I'm getting lang data (both php and json) in page source, so php code is ok. Problem is in javascript. I install Inertia and Vue using laravel/breeze package. Can you make same tutorial using Laravel 11 and breeze package with Inertia and Vue? Thanks in advance.
Genius work I can see here, but something I can't understand:
Why we include all the translations in script tag? Imagine we have 10.000 sentence with sessions etc ...
The page will be like a snail.
I loved your job
Are you suggesting only sending the ones for the current page each time? Perhaps even building up a local cache as each page is visited?
@@bentomlin It's partialy true but, better to get only the requested ones. This latter called lazy loading translations.
@@EL_PANDA_742 i am about to do this on a new project, and was thinking about injecting them from inertiajs middleware based on the page i am on, based on the route name based on the page i am on, additionally caching them in the state manager and only retrieving them if the page was never accessed before on the current visit
This is one amazing tutorial. Thank you so much for this!
I have a bit of newbie question here, as I was learning vue, the instructor suggested not to use mixins as they are fraud upon in the community. Since this is a 2 years old video, would you recommend an alternative approach?
Yes, with Vue 3 mixins are kind of obsolete/outdated - nowadays I'd go with a composable instead 👍
Next switch locale language , thanks
One problem with phpsources - we need to prefix all keys with the name of the file, so not "failed" but "auth.failed".
I'm looking for an elegant solution, but didn't find for now
Maybe you can help?
This is my solution: return Arr::dot([$file->getFilenameWithoutExtension() => File::getRequire($file->getRealPath())]);