If you use Qwik-provided adapters for publishing your app, especially with edge functions or static generation, it is recommended to bundle the translation files (see Translation functions)
If your production environment doesn't support dynamic import, you can import files directly:
/**
* Translation files are imported directly as string
*/
const translationData = import.meta.glob('/i18n/**/*.json', { as: 'raw', eager: true });
const loadTranslation$: LoadTranslationFn = server$((lang: string, asset: string) =>
JSON.parse(translationData[`/i18n/${lang}/${asset}.json`])
);
If you want to use Static Site Generation with the localized router, it is necessary to manage the dynamic language parameter, and you need to add the values it can take to the pages that will be pre-rendered:
/**
* Dynamic SSG route
*/
export const onStaticGenerate: StaticGenerateHandler = () => {
return {
params: config.supportedLocales.map(locale => {
return { lang: locale.lang !== config.defaultLocale.lang ? locale.lang : '' };
})
};
};