matice
matice copied to clipboard
Js or Json per language and lazy loading
I saw your comment on PR discussion of Laravel Jetstream. I'm still looking for an I18n solution for my project. It should be realized with Laravel/Jetstream/Inertia/Vue. I studied your solution.
Your library is very good because it uses Laravel's standard files and standard location.
As I understand your component is loading all languages together with the blade directive. Same with the Artisan command which produces one file together with current local, fallback and all translations. This is OK for small applications with few languages. But think about an application with 20 - 50 pages and 3 to 10 languages? One user uses one language only mostly.
My feature request is:
- The Artisan command should generate one file per language
- The blade directive should send one language only for current locale. Often nobody is changing his standard language.
- A provided Laravel Middleware component should send the value of App::currentLocale and fallback locale to Inertia shared which can used in app.js to set locale (via function setLocale)
- The setLocale function should check if the translations for requested local is already loaded. If not import with lazy loading see function loadLanguageAsync of Vue I18n
- Replace the lang attribute in HTML tag with current locale in function setLocale
- When using Inertia's shared for current locale then "setLocale" could executed for every response. This allows the developer to change the language via route (change with App:setLocale) or while storing user's language etc.
What are you thinking? Thank you very much for your answer.
Hello @Enrica-r ! Matice aims to bring in JS the power of Laravel translations. So what is does basically is to load your translation files and make them available on the browser in a single object and then provides some js helpers to manipulate the same has Laravel does. Instead of generating one file per language, it generates one js object where each object key is the language's name.
In production, matice lazy loads the translations. The translations are only generated once and reused each time. See config/matice.php
.
Also, the directive @translations
takes one optional argument named locale
which is the locale you want to load. When this argument is provided, only the translations of this locale are loaded.
Basically, maticeJs methods are independent of inertia or vue js. You do not have to use inertia's shared.
Some of your comments/suggestions are relevant. Now working on them,
hi @GENL , this is an excelente work. really! save my day.
there is something to make available also the json lang files in /lang/en.json /lang/fr.json /lang/es.json etc....
thanks @GENL have a very nice day.
sorry @GENL I had not realized that they are loaded!
thanks again. regards.