next-i18next
Version:
The easiest way to translate your NextJs apps.
43 lines (42 loc) • 1.76 kB
JavaScript
//#region src/appRouter/config.ts
function defineConfig(config) {
return config;
}
function normalizeConfig(userConfig) {
const supportedLngs = userConfig.supportedLngs ?? userConfig.i18n?.locales?.filter((l) => l !== "default") ?? ["en"];
const fallbackLng = userConfig.fallbackLng ?? userConfig.i18n?.defaultLocale ?? supportedLngs[0];
if (!fallbackLng) throw new Error("next-i18next: fallbackLng (or i18n.defaultLocale) is required");
if (supportedLngs.length === 0) throw new Error("next-i18next: supportedLngs (or i18n.locales) must contain at least one language");
const defaultNS = userConfig.defaultNS ?? "common";
return {
supportedLngs,
fallbackLng,
defaultNS,
ns: userConfig.ns ?? [defaultNS],
localeInPath: userConfig.localeInPath ?? true,
hideDefaultLocale: userConfig.hideDefaultLocale ?? false,
localePath: userConfig.localePath ?? "/locales",
localeStructure: userConfig.localeStructure ?? "{{lng}}/{{ns}}",
localeExtension: userConfig.localeExtension ?? "json",
cookieName: userConfig.cookieName ?? "i18next",
headerName: userConfig.headerName ?? "x-i18next-current-language",
cookieMaxAge: userConfig.cookieMaxAge ?? 365 * 24 * 60 * 60,
ignoredPaths: userConfig.ignoredPaths ?? [
"/api",
"/_next",
"/static"
],
basePath: userConfig.basePath,
resources: userConfig.resources,
resourceLoader: userConfig.resourceLoader,
use: userConfig.use ?? [],
i18nextOptions: userConfig.i18nextOptions ?? {},
nonExplicitSupportedLngs: userConfig.nonExplicitSupportedLngs ?? false,
i18n: userConfig.i18n,
serializeConfig: userConfig.serializeConfig,
reloadOnPrerender: userConfig.reloadOnPrerender
};
}
//#endregion
export { defineConfig, normalizeConfig };
//# sourceMappingURL=index.mjs.map