nuxt-i18n-micro 2.6.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.
@@ -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},1762414713405,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"119cca13-ae84-4b8a-b244-c16eb4a6ed9f",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
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>
@@ -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},1762414713405,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"119cca13-ae84-4b8a-b244-c16eb4a6ed9f",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
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":"119cca13-ae84-4b8a-b244-c16eb4a6ed9f","timestamp":1762414707440}
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":[]}
@@ -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},1762414713405,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"119cca13-ae84-4b8a-b244-c16eb4a6ed9f",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
3
  "configKey": "i18n",
4
- "version": "2.6.0",
4
+ "version": "2.7.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
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
- const apiBaseUrl = rawUrl.startsWith("http://") || rawUrl.startsWith("https://") ? rawUrl : "/" + rawUrl.replace(/^\/+|\/+$|\/{2,}/, "");
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 ?? [],
@@ -947,7 +962,9 @@ const module = defineNuxtModule({
947
962
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
948
963
  // @ts-ignore
949
964
  routesLocaleLinks: options.routesLocaleLinks ?? {},
950
- apiBaseUrl
965
+ apiBaseUrl,
966
+ apiBaseClientHost,
967
+ apiBaseServerHost
951
968
  };
952
969
  addImportsDir(resolver.resolve("./runtime/composables"));
953
970
  if (process.env && process.env.TEST) {
@@ -999,7 +1016,7 @@ const module = defineNuxtModule({
999
1016
  });
1000
1017
  }
1001
1018
  addServerHandler({
1002
- route: `${apiBaseUrl}/:page/:locale/data.json`,
1019
+ route: `/${apiBaseUrl}/:page/:locale/data.json`,
1003
1020
  handler: resolver.resolve("./runtime/server/routes/get")
1004
1021
  });
1005
1022
  addComponentsDir({
@@ -1074,10 +1091,10 @@ ${accepts}
1074
1091
  localeManager.locales.forEach((locale) => {
1075
1092
  if (!options.disablePageLocales) {
1076
1093
  pagesNames.forEach((name) => {
1077
- prerenderRoutes.push(`${apiBaseUrl}/${name}/${locale.code}/data.json`);
1094
+ prerenderRoutes.push(`/${apiBaseUrl}/${name}/${locale.code}/data.json`);
1078
1095
  });
1079
1096
  }
1080
- prerenderRoutes.push(`${apiBaseUrl}/general/${locale.code}/data.json`);
1097
+ prerenderRoutes.push(`/${apiBaseUrl}/general/${locale.code}/data.json`);
1081
1098
  });
1082
1099
  if (!options.disableWatcher) {
1083
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 ?? "/_locales";
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", () => ({}));
@@ -68,7 +69,10 @@ export default defineNuxtPlugin(async (nuxtApp) => {
68
69
  }
69
70
  return;
70
71
  }
71
- const url = `${apiBaseUrl}/${routeName}/${locale}/data.json`.replace(/\/{2,}/g, "/");
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,
@@ -6,8 +6,13 @@ async function fetchTranslations(locale) {
6
6
  try {
7
7
  const config = useRuntimeConfig();
8
8
  const i18nConfig = config.i18nConfig;
9
- const apiBaseUrl = i18nConfig?.apiBaseUrl ?? "/_locales";
10
- const translations = await $fetch(`${apiBaseUrl}/general/${locale}/data.json`);
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);
11
16
  return translations;
12
17
  } catch (error) {
13
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.6.0",
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-test-utils": "1.0.7",
65
- "nuxt-i18n-micro-types": "1.0.13",
66
- "nuxt-i18n-micro-core": "1.0.24"
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":"119cca13-ae84-4b8a-b244-c16eb4a6ed9f","timestamp":1762414707440,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}