Answer the question
In order to leave comments, you need to log in
How to competently implement React and Laravel multilingualism?
It is clear that requests are sent to Laravel. Displays all React.
I want to implement language selection for new visitors or choose some other language by default. In this case, you need to store word libraries somewhere. The question is where is the best... In React itself or send a request to Laravel with libraries.
For authorized users, a request will be sent to Laravel to find out what language the user has selected in the settings.
Please, enlighten and tell how it is implemented in large applications? I want to make something cool and well-made.
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
The main controversial issue that you should decide is where to store the static translation (inscriptions that do not change or change rarely, for example, the name of the button - Send / Submit, those are all that we usually do not store in the database and rarely change).
There are two options:
1. Use only react for this, then take the react-localization package , there are quite simple and understandable principles, there are no difficulties.
Advantages: the front lives completely separately and does not depend on the backend, there are no additional layers, there is no binding to a specific backend, etc.
2. Use Laravel's localization capabilities. But here, all the same, all the methods of one degree or another are hackneyed, or at least adding a hard binding of the frontend of the application to the current backend stack
Benefits: You can use different packages to integrate static localization redacting tools in the backend.
Personally, I still tend to the first option, because I like to write maximally (preferably completely) independent front-end applications.
Now the second part of the question. Already with regards to dynamic translations (this is content, comments, etc., relatively speaking, everything that we store in the database, or store information about them in the database).
Here I advise you to rely on Laravel, take the package from spatie laravel-translatable, it allows you to quickly build convenient interfaces for editing / reading translations in the database, write a simple API and when you initialize the react application, you get the data you need for the localization, or even send it all at once (they are stored in the json field of mysql / your database, even additional transformations are not particularly required ).
But I like the option of sending only what I need more, changing the locale is a rare event, but the savings on the size of the transferred data will be significant.
Well, then you already hang up all sorts of caching tp, so that everything flies and is ready.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question