My experience with using Inertia.js for Laravel has always been smooth and pleasant.
But I can't say the same with translations/localisation.
But I can't say the same with translations/localisation.
Having to load every single string from your entire application is something I don't like at all. I wish at some point we have a solution where we can just create a bundle per language so we can get code splitting, etc and just ship what's necessary for your locale.
For the Inertia project I work on at my job, we just use a "frontend" translation solution and keep the Rails translations system just for the backend.
const LOCALE_MAP: any = {
en: () =>
document.body.dataset["appEnv"] === "development"
? Promise.resolve({ default: {} as LocaleMap })
: import("@locales/admin.en.compiled.json"),
fr: () => import("@locales/admin.fr.compiled.json"),
es: () => import("@locales/admin.es.compiled.json"),
...
};
Then we consume it in a component which accepts the language key, lazy-loads the bundle by just calling `LOCALE_MAP[key]()`, and then uses it as the string translation set for a context function which looks up keys in a dict. Super simple.(Don’t tell me about having the option to manually do separate bundles like “common”, “admin”, etc… that’s just more madness)