nuxt-i18n-micro 2.5.0 → 2.7.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 +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/e84c9eb7-2c0b-4741-b5c3-f8a613bfb352.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +23 -5
- package/dist/runtime/plugins/01.plugin.js +11 -7
- package/dist/runtime/translation-server-middleware.js +8 -2
- package/package.json +4 -4
- package/dist/client/_nuxt/builds/meta/dc8ec25f-2f2b-41cd-9ff1-ce2de81f36ea.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CBxwnKtU.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BqKd8Zt-.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BYEpoBUk.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1762430716730,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CBxwnKtU.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BqKd8Zt-.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BYEpoBUk.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1762430716731,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352","timestamp":1762430710401}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352","timestamp":1762430710401,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CBxwnKtU.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BqKd8Zt-.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BYEpoBUk.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1762430716731,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -827,6 +827,8 @@ const module = defineNuxtModule({
|
|
|
827
827
|
fallbackLocale: void 0,
|
|
828
828
|
localeCookie: "user-locale",
|
|
829
829
|
apiBaseUrl: "_locales",
|
|
830
|
+
apiBaseClientHost: void 0,
|
|
831
|
+
apiBaseServerHost: void 0,
|
|
830
832
|
routesLocaleLinks: {},
|
|
831
833
|
globalLocaleRoutes: {},
|
|
832
834
|
canonicalQueryWhitelist: ["page", "sort", "filter", "search", "q", "query", "tag"],
|
|
@@ -895,8 +897,19 @@ const module = defineNuxtModule({
|
|
|
895
897
|
write: true,
|
|
896
898
|
getContents: () => `export const plural = ${options.plural.toString()};`
|
|
897
899
|
});
|
|
900
|
+
let apiBaseClientHost = process.env.NUXT_I18N_APP_BASE_CLIENT_HOST ?? options.apiBaseClientHost ?? void 0;
|
|
901
|
+
if (apiBaseClientHost && apiBaseClientHost.endsWith("/")) {
|
|
902
|
+
apiBaseClientHost = apiBaseClientHost.slice(0, -1);
|
|
903
|
+
}
|
|
904
|
+
let apiBaseServerHost = process.env.NUXT_I18N_APP_BASE_SERVER_HOST ?? options.apiBaseServerHost ?? void 0;
|
|
905
|
+
if (apiBaseServerHost && apiBaseServerHost.endsWith("/")) {
|
|
906
|
+
apiBaseServerHost = apiBaseServerHost.slice(0, -1);
|
|
907
|
+
}
|
|
898
908
|
const rawUrl = process.env.NUXT_I18N_APP_BASE_URL ?? options.apiBaseUrl ?? "_locales";
|
|
899
|
-
|
|
909
|
+
if (rawUrl.startsWith("http://") || rawUrl.startsWith("https://")) {
|
|
910
|
+
throw new Error("Nuxt-i18n-micro: Please use NUXT_I18N_APP_BASE_CLIENT_HOST or NUXT_I18N_APP_BASE_SERVER_HOST instead.");
|
|
911
|
+
}
|
|
912
|
+
const apiBaseUrl = rawUrl.replace(/^\/+|\/+$|\/{2,}/, "");
|
|
900
913
|
nuxt.options.runtimeConfig.public.i18nConfig = {
|
|
901
914
|
locales: localeManager.locales ?? [],
|
|
902
915
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -909,6 +922,8 @@ const module = defineNuxtModule({
|
|
|
909
922
|
dateBuild: Date.now(),
|
|
910
923
|
hashMode: nuxt.options?.router?.options?.hashMode ?? false,
|
|
911
924
|
apiBaseUrl,
|
|
925
|
+
apiBaseClientHost,
|
|
926
|
+
apiBaseServerHost,
|
|
912
927
|
isSSG,
|
|
913
928
|
disablePageLocales: options.disablePageLocales ?? false,
|
|
914
929
|
canonicalQueryWhitelist: options.canonicalQueryWhitelist ?? [],
|
|
@@ -946,7 +961,10 @@ const module = defineNuxtModule({
|
|
|
946
961
|
customRegexMatcher: options.customRegexMatcher,
|
|
947
962
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
948
963
|
// @ts-ignore
|
|
949
|
-
routesLocaleLinks: options.routesLocaleLinks ?? {}
|
|
964
|
+
routesLocaleLinks: options.routesLocaleLinks ?? {},
|
|
965
|
+
apiBaseUrl,
|
|
966
|
+
apiBaseClientHost,
|
|
967
|
+
apiBaseServerHost
|
|
950
968
|
};
|
|
951
969
|
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
952
970
|
if (process.env && process.env.TEST) {
|
|
@@ -998,7 +1016,7 @@ const module = defineNuxtModule({
|
|
|
998
1016
|
});
|
|
999
1017
|
}
|
|
1000
1018
|
addServerHandler({
|
|
1001
|
-
route:
|
|
1019
|
+
route: `/${apiBaseUrl}/:page/:locale/data.json`,
|
|
1002
1020
|
handler: resolver.resolve("./runtime/server/routes/get")
|
|
1003
1021
|
});
|
|
1004
1022
|
addComponentsDir({
|
|
@@ -1073,10 +1091,10 @@ ${accepts}
|
|
|
1073
1091
|
localeManager.locales.forEach((locale) => {
|
|
1074
1092
|
if (!options.disablePageLocales) {
|
|
1075
1093
|
pagesNames.forEach((name) => {
|
|
1076
|
-
prerenderRoutes.push(
|
|
1094
|
+
prerenderRoutes.push(`/${apiBaseUrl}/${name}/${locale.code}/data.json`);
|
|
1077
1095
|
});
|
|
1078
1096
|
}
|
|
1079
|
-
prerenderRoutes.push(
|
|
1097
|
+
prerenderRoutes.push(`/${apiBaseUrl}/general/${locale.code}/data.json`);
|
|
1080
1098
|
});
|
|
1081
1099
|
if (!options.disableWatcher) {
|
|
1082
1100
|
localeManager.ensureTranslationFilesExist(pagesNames, options.translationDir, nuxt.options.rootDir);
|
|
@@ -7,7 +7,8 @@ const isDev = process.env.NODE_ENV !== "production";
|
|
|
7
7
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
8
8
|
const config = useRuntimeConfig();
|
|
9
9
|
const i18nConfig = config.public.i18nConfig;
|
|
10
|
-
const apiBaseUrl = i18nConfig.apiBaseUrl ?? "
|
|
10
|
+
const apiBaseUrl = i18nConfig.apiBaseUrl ?? "_locales";
|
|
11
|
+
const apiBaseHost = import.meta.client ? i18nConfig.apiBaseClientHost : i18nConfig.apiBaseServerHost;
|
|
11
12
|
const router = useRouter();
|
|
12
13
|
const runtimeConfig = useRuntimeConfig();
|
|
13
14
|
const generalLocaleCache = useState("i18n-general-cache", () => ({}));
|
|
@@ -58,7 +59,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
58
59
|
if (isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
59
60
|
locale = await nuxtApp.runWithContext(() => useCookie("no-prefix-locale", { default: () => locale }).value);
|
|
60
61
|
}
|
|
61
|
-
const routeName = routeService.
|
|
62
|
+
const routeName = routeService.getPluginRouteName(to, locale);
|
|
62
63
|
if (!routeName) {
|
|
63
64
|
return;
|
|
64
65
|
}
|
|
@@ -68,7 +69,10 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
68
69
|
}
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
+
let url = `/${apiBaseUrl}/${routeName}/${locale}/data.json`.replace(/\/{2,}/g, "/");
|
|
73
|
+
if (apiBaseHost) {
|
|
74
|
+
url = `${apiBaseHost}${url}`;
|
|
75
|
+
}
|
|
72
76
|
try {
|
|
73
77
|
const data = await $fetch(url, {
|
|
74
78
|
baseURL: runtimeConfig.app.baseURL,
|
|
@@ -92,7 +96,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
92
96
|
}
|
|
93
97
|
if (import.meta.client && enablePreviousPageFallback) {
|
|
94
98
|
const fromLocale = routeService.getCurrentLocale(from);
|
|
95
|
-
const fromRouteName = routeService.
|
|
99
|
+
const fromRouteName = routeService.getPluginRouteName(from, fromLocale);
|
|
96
100
|
previousPageInfo.value = { locale: fromLocale, routeName: fromRouteName };
|
|
97
101
|
}
|
|
98
102
|
try {
|
|
@@ -119,7 +123,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
119
123
|
if (!key) return "";
|
|
120
124
|
route = route ?? routeService.getCurrentRoute();
|
|
121
125
|
const locale = routeService.getCurrentLocale();
|
|
122
|
-
const routeName = routeService.
|
|
126
|
+
const routeName = routeService.getPluginRouteName(route, locale);
|
|
123
127
|
let value = i18nHelper.getTranslation(locale, routeName, key);
|
|
124
128
|
if (!value && previousPageInfo.value && enablePreviousPageFallback) {
|
|
125
129
|
const prev = previousPageInfo.value;
|
|
@@ -172,13 +176,13 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
172
176
|
has: (key, route) => {
|
|
173
177
|
route = route ?? routeService.getCurrentRoute();
|
|
174
178
|
const locale = routeService.getCurrentLocale();
|
|
175
|
-
const routeName = routeService.
|
|
179
|
+
const routeName = routeService.getPluginRouteName(route, locale);
|
|
176
180
|
return !!i18nHelper.getTranslation(locale, routeName, key);
|
|
177
181
|
},
|
|
178
182
|
mergeTranslations: (newTranslations) => {
|
|
179
183
|
const route = routeService.getCurrentRoute();
|
|
180
184
|
const locale = routeService.getCurrentLocale(route);
|
|
181
|
-
const routeName = routeService.
|
|
185
|
+
const routeName = routeService.getPluginRouteName(route, locale);
|
|
182
186
|
i18nHelper.mergeTranslation(locale, routeName, newTranslations);
|
|
183
187
|
},
|
|
184
188
|
mergeGlobalTranslations: (newTranslations) => {
|
|
@@ -5,8 +5,14 @@ const I18N_CONTEXT_KEY = "__i18n_cache__";
|
|
|
5
5
|
async function fetchTranslations(locale) {
|
|
6
6
|
try {
|
|
7
7
|
const config = useRuntimeConfig();
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const i18nConfig = config.i18nConfig;
|
|
9
|
+
const apiBaseUrl = i18nConfig?.apiBaseUrl ?? "_locales";
|
|
10
|
+
const apiBaseServerHost = i18nConfig?.apiBaseServerHost ?? void 0;
|
|
11
|
+
let url = `/${apiBaseUrl}/general/${locale}/data.json`;
|
|
12
|
+
if (apiBaseServerHost) {
|
|
13
|
+
url = `${apiBaseServerHost}${url}`;
|
|
14
|
+
}
|
|
15
|
+
const translations = await $fetch(url);
|
|
10
16
|
return translations;
|
|
11
17
|
} catch (error) {
|
|
12
18
|
console.error(`Error loading translation for locale "${locale}":`, error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Nuxt I18n Micro is a lightweight, high-performance internationalization module for Nuxt, designed to handle multi-language support with minimal overhead, fast build times, and efficient runtime performance.",
|
|
5
5
|
"repository": "s00d/nuxt-i18n-micro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"globby": "^14.1.0",
|
|
62
62
|
"sirv": "^2.0.4",
|
|
63
63
|
"ufo": "^1.5.4",
|
|
64
|
-
"nuxt-i18n-micro-
|
|
65
|
-
"nuxt-i18n-micro-
|
|
66
|
-
"nuxt-i18n-micro-
|
|
64
|
+
"nuxt-i18n-micro-core": "1.0.24",
|
|
65
|
+
"nuxt-i18n-micro-types": "1.0.14",
|
|
66
|
+
"nuxt-i18n-micro-test-utils": "1.0.7"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@nuxt/devtools": "^2.6.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"dc8ec25f-2f2b-41cd-9ff1-ce2de81f36ea","timestamp":1762356596622,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|