nuxt-i18n-micro 3.18.3 → 3.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/200.html +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/bbe443af-4371-4ec3-b41c-7a5e9deb9b9b.json +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.d.mts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +57 -149
- package/dist/runtime/composables/useI18nLocale.js +3 -3
- package/dist/runtime/composables/useLocaleHead.js +1 -1
- package/dist/runtime/plugins/01.plugin.js +6 -3
- package/dist/runtime/plugins/02.meta.js +2 -2
- package/dist/runtime/plugins/05.hooks.js +1 -1
- package/dist/runtime/plugins/06.redirect.js +4 -4
- package/dist/runtime/server/middleware/i18n.global.js +4 -4
- package/dist/runtime/server/plugins/watcher.dev.js +36 -66
- package/dist/runtime/server/routes/i18n.js +2 -2
- package/dist/runtime/server/utils/locale-detector.js +11 -1
- package/dist/runtime/server/utils/locale-server-middleware.js +2 -2
- package/dist/runtime/server/utils/server-loader.d.ts +3 -3
- package/dist/runtime/server/utils/server-loader.js +32 -8
- package/dist/runtime/server/utils/translation-server-middleware.js +2 -2
- package/dist/runtime/utils/storage.d.ts +4 -6
- package/dist/runtime/utils/storage.js +20 -11
- package/dist/types.d.mts +2 -0
- package/package.json +11 -8
- package/dist/client/_nuxt/builds/meta/c5d2004e-f981-4363-a9ec-4d72cf7f4a8f.json +0 -1
- package/dist/runtime/utils/accept-language.d.ts +0 -3
- package/dist/runtime/utils/accept-language.js +0 -21
- package/dist/runtime/utils/active-locales.d.ts +0 -4
- package/dist/runtime/utils/active-locales.js +0 -9
- package/dist/runtime/utils/cache-control.d.ts +0 -50
- package/dist/runtime/utils/cache-control.js +0 -88
- package/dist/runtime/utils/cookie.d.ts +0 -24
- package/dist/runtime/utils/cookie.js +0 -22
- package/dist/runtime/utils/deep-merge.d.ts +0 -15
- package/dist/runtime/utils/deep-merge.js +0 -14
- package/dist/runtime/utils/resolve-server-locale.d.ts +0 -21
- package/dist/runtime/utils/resolve-server-locale.js +0 -30
- package/dist/runtime/utils/route-utils.d.ts +0 -33
- package/dist/runtime/utils/route-utils.js +0 -63
- package/dist/runtime/utils/runtime-i18n-config.d.ts +0 -8
- package/dist/runtime/utils/runtime-i18n-config.js +0 -90
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
function toNonEmptyString(value) {
|
|
2
|
-
if (typeof value !== "string") return void 0;
|
|
3
|
-
const normalized = value.trim();
|
|
4
|
-
return normalized.length > 0 ? normalized : void 0;
|
|
5
|
-
}
|
|
6
|
-
function parseLocalesList(value) {
|
|
7
|
-
if (Array.isArray(value)) {
|
|
8
|
-
const items = value.map((entry) => toNonEmptyString(entry)).filter((entry) => Boolean(entry));
|
|
9
|
-
return items.length > 0 ? items : void 0;
|
|
10
|
-
}
|
|
11
|
-
if (typeof value === "string") {
|
|
12
|
-
const items = value.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
13
|
-
return items.length > 0 ? items : void 0;
|
|
14
|
-
}
|
|
15
|
-
return void 0;
|
|
16
|
-
}
|
|
17
|
-
function readEnvOverrides() {
|
|
18
|
-
return {
|
|
19
|
-
defaultLocale: toNonEmptyString(process.env.NUXT_I18N_DEFAULT_LOCALE) ?? toNonEmptyString(process.env.NUXT_PUBLIC_I18N_RUNTIME_DEFAULT_LOCALE),
|
|
20
|
-
fallbackLocale: toNonEmptyString(process.env.NUXT_I18N_FALLBACK_LOCALE) ?? toNonEmptyString(process.env.NUXT_PUBLIC_I18N_RUNTIME_FALLBACK_LOCALE),
|
|
21
|
-
disabledLocales: parseLocalesList(process.env.NUXT_I18N_DISABLED_LOCALES) ?? parseLocalesList(process.env.NUXT_PUBLIC_I18N_RUNTIME_DISABLED_LOCALES),
|
|
22
|
-
strategy: toNonEmptyString(process.env.NUXT_I18N_STRATEGY) ?? toNonEmptyString(process.env.NUXT_PUBLIC_I18N_RUNTIME_STRATEGY)
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function readRuntimeOverrides(runtimePublic) {
|
|
26
|
-
const raw = runtimePublic?.i18nRuntime;
|
|
27
|
-
if (!raw || typeof raw !== "object") return {};
|
|
28
|
-
const runtime = raw;
|
|
29
|
-
return {
|
|
30
|
-
defaultLocale: toNonEmptyString(runtime.defaultLocale),
|
|
31
|
-
fallbackLocale: toNonEmptyString(runtime.fallbackLocale),
|
|
32
|
-
disabledLocales: parseLocalesList(runtime.disabledLocales),
|
|
33
|
-
strategy: toNonEmptyString(runtime.strategy)
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function mergeOverrides(runtimePublic) {
|
|
37
|
-
const env = readEnvOverrides();
|
|
38
|
-
const runtime = readRuntimeOverrides(runtimePublic);
|
|
39
|
-
return {
|
|
40
|
-
defaultLocale: runtime.defaultLocale ?? env.defaultLocale,
|
|
41
|
-
fallbackLocale: runtime.fallbackLocale ?? env.fallbackLocale,
|
|
42
|
-
disabledLocales: runtime.disabledLocales ?? env.disabledLocales,
|
|
43
|
-
strategy: runtime.strategy ?? env.strategy
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export function resolveI18nConfigWithRuntimeOverrides(baseConfig, runtimePublic, warn = (message) => console.warn(message)) {
|
|
47
|
-
const overrides = mergeOverrides(runtimePublic);
|
|
48
|
-
const locales = (baseConfig.locales ?? []).map((locale) => ({ ...locale }));
|
|
49
|
-
if (overrides.strategy && overrides.strategy !== baseConfig.strategy) {
|
|
50
|
-
warn(
|
|
51
|
-
`[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${overrides.strategy}" (build strategy: "${baseConfig.strategy}"). Build a separate artifact for each strategy.`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
if (overrides.disabledLocales && overrides.disabledLocales.length > 0) {
|
|
55
|
-
const disabledSet = new Set(overrides.disabledLocales);
|
|
56
|
-
for (const locale of locales) {
|
|
57
|
-
locale.disabled = disabledSet.has(locale.code);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const enabledLocales = locales.filter((locale) => !locale.disabled);
|
|
61
|
-
if (enabledLocales.length === 0) {
|
|
62
|
-
if (overrides.disabledLocales && overrides.disabledLocales.length > 0) {
|
|
63
|
-
warn("[nuxt-i18n-micro] runtime disabledLocales override would disable all locales; override ignored.");
|
|
64
|
-
}
|
|
65
|
-
return { ...baseConfig, locales: (baseConfig.locales ?? []).map((locale) => ({ ...locale })) };
|
|
66
|
-
}
|
|
67
|
-
const allLocaleCodes = new Set(locales.map((locale) => locale.code));
|
|
68
|
-
let defaultLocale = overrides.defaultLocale ?? baseConfig.defaultLocale;
|
|
69
|
-
let fallbackLocale = overrides.fallbackLocale ?? baseConfig.fallbackLocale;
|
|
70
|
-
if (fallbackLocale && !allLocaleCodes.has(fallbackLocale)) {
|
|
71
|
-
warn(`[nuxt-i18n-micro] runtime fallbackLocale "${fallbackLocale}" is not defined in locales; override ignored.`);
|
|
72
|
-
fallbackLocale = baseConfig.fallbackLocale;
|
|
73
|
-
}
|
|
74
|
-
const enabledLocaleCodes = new Set(enabledLocales.map((locale) => locale.code));
|
|
75
|
-
const firstEnabledLocale = enabledLocales[0]?.code ?? baseConfig.defaultLocale ?? "en";
|
|
76
|
-
if (!defaultLocale || !enabledLocaleCodes.has(defaultLocale)) {
|
|
77
|
-
if (overrides.defaultLocale) {
|
|
78
|
-
warn(`[nuxt-i18n-micro] runtime defaultLocale "${overrides.defaultLocale}" is not enabled; falling back to "${firstEnabledLocale}".`);
|
|
79
|
-
} else if (defaultLocale && !enabledLocaleCodes.has(defaultLocale)) {
|
|
80
|
-
warn(`[nuxt-i18n-micro] defaultLocale "${defaultLocale}" is disabled by runtime overrides; falling back to "${firstEnabledLocale}".`);
|
|
81
|
-
}
|
|
82
|
-
defaultLocale = firstEnabledLocale;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
...baseConfig,
|
|
86
|
-
locales,
|
|
87
|
-
defaultLocale,
|
|
88
|
-
fallbackLocale
|
|
89
|
-
};
|
|
90
|
-
}
|