Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 1.16 KB

adapters.md

File metadata and controls

31 lines (26 loc) · 1.16 KB

Qwik Speak and Adapters

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`])
);

Static Site Generation (SSG)

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 : '' };
    })
  };
};