There's no one-size-fits-all solution for localization. It can be really complex and include everything in the application or it can be as simple as just translating static text.
I'll try to summarize the main points of this course:
- Translating text. You can install a package to move translations to a database/Excel sheet but that is not mandatory.
- Translating validation/form attributes. You just use what Laravel provides.
- Translating routes. I would recommend the https://github.com/mcamara/laravel-localization package to save a lot of time and effort.
- Localizing dates. You can use Carbon localization feature.
-
Localizing currencies. You can use PHP's
NumberFormatter
class. - Translating DB Models. Not required to have a package but both spatie/laravel-translatable and astrotomic/laravel-translatable can be really beneficial.
You can also use a combination packages. For example:
- https://github.com/mcamara/laravel-localization - Translating routes
- https://github.com/MohmmedAshraf/laravel-translations or https://github.com/nikaia/translation-sheet - Translating text via UI
- https://github.com/Astrotomic/laravel-translatable - Translating DB Models
I hope this course gave you a good overview of the most important packages and how to use them.
If there are any questions or suggestions, feel free to write a comment below.
Hello there, This was a great tutorial but there is something missing that I don't know how to implement: update a slug from a model in the language switcher.
English URL site.com/post/[english-slug] French URL site.com/article/french-slug]
When using the locale switcher, it should redirect to the french slug otherwise it would get a 404 error with the current switcher: site.com/article/[english-slug] (instead of site.com/article/[french-slug])
How could you implement this?
Thanks! Vincent
Hey, this one is a bit tricky to implement. Since there are slugs that are changing, you need to:
And this quickly becomes a bigger deal than you might think, with a lot of fallbacks/checks needed. I can't go deep into specifics here due to the size of this project (in order for it to be done correctly), sorry! Hope the general idea/direction helps you
great course, thanks. would be good also to add how to translate text in js files
We have an article about that:
//post/laravel-and-vuejs-translations-with-i18n-plugin
Thank you very much. A good selection with real examples.