nuxt-i18n-micro 1.13.2 → 1.14.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.
@@ -9,4 +9,4 @@
9
9
  <link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DzdJBprQ.js">
11
11
  <script type="module" src="/__nuxt-i18n-micro/_nuxt/D1fvHJQV.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__">[{"serverRendered":1},false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"cef9112f-2f86-40b3-9815-286383780fe2",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -9,4 +9,4 @@
9
9
  <link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DzdJBprQ.js">
11
11
  <script type="module" src="/__nuxt-i18n-micro/_nuxt/D1fvHJQV.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__">[{"serverRendered":1},false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"cef9112f-2f86-40b3-9815-286383780fe2",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb","timestamp":1725460561569}
1
+ {"id":"cef9112f-2f86-40b3-9815-286383780fe2","timestamp":1725543893300}
@@ -0,0 +1 @@
1
+ {"id":"cef9112f-2f86-40b3-9815-286383780fe2","timestamp":1725543893300,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -9,4 +9,4 @@
9
9
  <link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DzdJBprQ.js">
11
11
  <script type="module" src="/__nuxt-i18n-micro/_nuxt/D1fvHJQV.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__">[{"serverRendered":1},false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"cef9112f-2f86-40b3-9815-286383780fe2",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.d.mts CHANGED
@@ -35,7 +35,7 @@ interface ModulePrivateOptionsExtend extends ModuleOptions {
35
35
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
36
36
 
37
37
  interface ModuleHooks {
38
- 'i18n:register': (registerModule: (translations: unknown, locale: string) => void) => HookResult;
38
+ 'i18n:register': (registerModule: (translations: unknown, locale?: string) => void, locale: string) => HookResult;
39
39
  }
40
40
  declare module '@nuxt/schema' {
41
41
  interface ConfigSchema {
package/dist/module.d.ts CHANGED
@@ -35,7 +35,7 @@ interface ModulePrivateOptionsExtend extends ModuleOptions {
35
35
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
36
36
 
37
37
  interface ModuleHooks {
38
- 'i18n:register': (registerModule: (translations: unknown, locale: string) => void) => HookResult;
38
+ 'i18n:register': (registerModule: (translations: unknown, locale?: string) => void, locale: string) => HookResult;
39
39
  }
40
40
  declare module '@nuxt/schema' {
41
41
  interface ConfigSchema {
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
3
  "configKey": "i18n",
4
- "version": "1.13.2",
4
+ "version": "1.14.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.3",
7
7
  "unbuild": "2.0.0"
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <div :style="[wrapperStyle, customWrapperStyle]">
3
3
  <button
4
+ class="language-switcher"
4
5
  :style="[buttonStyle, customButtonStyle]"
5
6
  @click="toggleDropdown"
6
7
  >
@@ -17,9 +18,11 @@
17
18
  :style="[itemStyle, customItemStyle]"
18
19
  >
19
20
  <NuxtLink
21
+ :class="`switcher-locale-${locale.code}`"
20
22
  :to="getLocaleLink(locale)"
21
23
  :style="[linkStyle, locale.code === currentLocale ? activeLinkStyle : {}, locale.code === currentLocale ? disabledLinkStyle : {}, customLinkStyle]"
22
24
  :hreflang="locale.iso || locale.code"
25
+ @click="toggleDropdown"
23
26
  >
24
27
  {{ localeLabel(locale) }}
25
28
  </NuxtLink>
@@ -39,8 +39,18 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale) {
39
39
  const currentLocale = locale || getCurrentLocale(route, i18nConfig);
40
40
  const selectRoute = router.resolve(to);
41
41
  const routeName = getRouteName(selectRoute, currentLocale);
42
+ const resolveParams = (to2) => {
43
+ const params = typeof to2 === "object" && "params" in to2 && typeof to2.params === "object" ? { ...to2.params } : {};
44
+ if (typeof to2 === "string") {
45
+ const resolved = router.resolve(to2);
46
+ if (resolved && resolved.params) {
47
+ Object.assign(params, resolved.params);
48
+ }
49
+ }
50
+ return params;
51
+ };
42
52
  if (router.hasRoute(`localized-${routeName}-${currentLocale}`)) {
43
- const newParams2 = typeof to === "object" && "params" in to && typeof to.params === "object" ? { ...to.params } : {};
53
+ const newParams2 = resolveParams(to);
44
54
  newParams2.locale = currentLocale;
45
55
  return router.resolve({
46
56
  params: newParams2,
@@ -48,7 +58,7 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale) {
48
58
  });
49
59
  }
50
60
  const newRouteName = currentLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute ? `localized-${routeName}` : routeName;
51
- const newParams = typeof to === "object" && "params" in to && typeof to.params === "object" ? { ...to.params } : {};
61
+ const newParams = resolveParams(to);
52
62
  delete newParams.locale;
53
63
  if (currentLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute) {
54
64
  newParams.locale = currentLocale;
@@ -62,10 +72,6 @@ function formatDate(value, locale, options) {
62
72
  return new Intl.DateTimeFormat(locale, options).format(new Date(value));
63
73
  }
64
74
  export default defineNuxtPlugin(async (nuxtApp) => {
65
- const registerI18nModule = (translations, locale) => {
66
- i18nHelper.mergeGlobalTranslation(locale, translations);
67
- };
68
- await nuxtApp.callHook("i18n:register", registerI18nModule);
69
75
  if (!nuxtApp.payload.data.translations) {
70
76
  nuxtApp.payload.data.translations = {};
71
77
  }
@@ -94,16 +100,19 @@ export default defineNuxtPlugin(async (nuxtApp) => {
94
100
  await loadTranslationsIfNeeded(locale, initialRouteName);
95
101
  }
96
102
  useRouter().beforeEach(async (to, from, next) => {
103
+ const locale = getCurrentLocale(to, i18nConfig);
97
104
  if (import.meta.client) {
98
- const locale = getCurrentLocale(to, i18nConfig);
99
105
  const data = await $fetch(`/_locales/general/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
100
106
  await i18nHelper.loadTranslations(locale, data ?? {});
101
107
  }
102
108
  if (import.meta.client && !i18nConfig.disablePageLocales) {
103
- const locale = getCurrentLocale(to, i18nConfig);
104
109
  const routeName = getRouteName(to, locale);
105
110
  await loadTranslationsIfNeeded(locale, routeName);
106
111
  }
112
+ await nuxtApp.callHook("i18n:register", (translations, selectedLocale) => {
113
+ const routeName = getRouteName(to, locale);
114
+ i18nHelper.mergeTranslation(selectedLocale ?? locale, routeName, translations, true);
115
+ }, locale);
107
116
  next();
108
117
  });
109
118
  const getTranslation = (key, params, defaultValue) => {
@@ -3,8 +3,8 @@ export declare function useTranslationHelper(): {
3
3
  hasCache(locale: string, page: string): boolean;
4
4
  getCache(locale: string, routeName: string): Map<string, unknown>;
5
5
  setCache(locale: string, routeName: string, cache: Map<string, Translations | unknown>): void;
6
- mergeTranslation(locale: string, routeName: string, newTranslations: Translations): void;
7
- mergeGlobalTranslation(locale: string, newTranslations: Translations): void;
6
+ mergeTranslation(locale: string, routeName: string, newTranslations: Translations, force?: boolean): void;
7
+ mergeGlobalTranslation(locale: string, newTranslations: Translations, force?: boolean): void;
8
8
  hasGeneralTranslation(locale: string): boolean;
9
9
  hasPageTranslation(locale: string, routeName: string): boolean;
10
10
  getTranslation: <T = unknown>(locale: string, routeName: string, key: string) => T | null;
@@ -39,8 +39,8 @@ export function useTranslationHelper() {
39
39
  serverTranslationInit[`${locale}:index`] = true;
40
40
  serverTranslationInit[cacheKey] = true;
41
41
  },
42
- mergeTranslation(locale, routeName, newTranslations) {
43
- if (!routeLocaleCache[`${locale}:${routeName}`]) {
42
+ mergeTranslation(locale, routeName, newTranslations, force = false) {
43
+ if (!force && !routeLocaleCache[`${locale}:${routeName}`]) {
44
44
  console.error(`marge: route ${locale}:${routeName} not loaded`);
45
45
  }
46
46
  routeLocaleCache[`${locale}:${routeName}`] = {
@@ -48,8 +48,8 @@ export function useTranslationHelper() {
48
48
  ...newTranslations
49
49
  };
50
50
  },
51
- mergeGlobalTranslation(locale, newTranslations) {
52
- if (!generalLocaleCache[`${locale}`]) {
51
+ mergeGlobalTranslation(locale, newTranslations, force = false) {
52
+ if (!force && !generalLocaleCache[`${locale}`]) {
53
53
  console.error(`marge: route ${locale} not loaded`);
54
54
  }
55
55
  generalLocaleCache[locale] = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.13.2",
3
+ "version": "1.14.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",
@@ -1 +0,0 @@
1
- {"id":"1f40d9d0-1d86-4ceb-b98c-da56e66c6bdb","timestamp":1725460561569,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}