GENL / matice

Use your Laravel translations in JavaScript.
MIT License
99 stars 15 forks source link

Js or Json per language and lazy loading #10

Open Enrica-r opened 3 years ago

Enrica-r commented 3 years ago

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:

What are you thinking? Thank you very much for your answer.

GENL commented 3 years ago

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.

GENL commented 3 years ago

Some of your comments/suggestions are relevant. Now working on them,

xhava commented 3 years ago

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.