Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Js or Json per language and lazy loading #10

Open
Enrica-r opened this issue Dec 27, 2020 · 3 comments
Open

Js or Json per language and lazy loading #10

Enrica-r opened this issue Dec 27, 2020 · 3 comments
Labels
Work in progress Currently working on this issue

Comments

@Enrica-r
Copy link

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.

@GENL
Copy link
Owner

GENL commented Dec 28, 2020

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 GENL closed this as completed Jan 15, 2021
@GENL
Copy link
Owner

GENL commented Mar 7, 2021

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

@GENL GENL reopened this Mar 7, 2021
@GENL GENL added the Work in progress Currently working on this issue label Mar 7, 2021
@xhava
Copy link

xhava commented Apr 22, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Work in progress Currently working on this issue
Projects
None yet
Development

No branches or pull requests

3 participants