nuxt-i18n-micro 1.27.0 → 1.28.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/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![npm downloads](https://img.shields.io/npm/dw/nuxt-i18n-micro?style=for-the-badge)](https://www.npmjs.com/package/nuxt-i18n-micro)
3
3
  [![License](https://img.shields.io/npm/l/nuxt-i18n-micro?style=for-the-badge)](https://www.npmjs.com/package/nuxt-i18n-micro)
4
4
  [![Nuxt](https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js&style=for-the-badge)](https://nuxt.com)
5
+ [![Donate](https://img.shields.io/badge/Donate-ff4081?style=for-the-badge)](https://www.donationalerts.com/r/s00d88)
5
6
 
6
7
  <p align="center">
7
8
  <img src="https://github.com/s00d/nuxt-i18n-micro/blob/main/logo.png?raw=true" alt="logo">
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/0GmYR_kR.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.CBAEdpZV.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/2C6ahHCU.js">
11
- <script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729272343291,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"ae460766-4aac-4e10-8148-f637be2c18a6",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729325923213,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"be20711c-09b4-4275-a779-8234f5aad9c8",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/0GmYR_kR.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.CBAEdpZV.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/2C6ahHCU.js">
11
- <script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729272343292,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"ae460766-4aac-4e10-8148-f637be2c18a6",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729325923214,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"be20711c-09b4-4275-a779-8234f5aad9c8",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"ae460766-4aac-4e10-8148-f637be2c18a6","timestamp":1729272329466}
1
+ {"id":"be20711c-09b4-4275-a779-8234f5aad9c8","timestamp":1729325910015}
@@ -0,0 +1 @@
1
+ {"id":"be20711c-09b4-4275-a779-8234f5aad9c8","timestamp":1729325910015,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/0GmYR_kR.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.CBAEdpZV.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/2C6ahHCU.js">
11
- <script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729272343292,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"ae460766-4aac-4e10-8148-f637be2c18a6",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729325923214,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"be20711c-09b4-4275-a779-8234f5aad9c8",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.d.mts CHANGED
@@ -36,7 +36,6 @@ interface ModuleOptions {
36
36
  interface ModuleOptionsExtend extends ModuleOptions {
37
37
  plural: string;
38
38
  dateBuild: number;
39
- baseURL: string;
40
39
  hashMode: boolean;
41
40
  apiBaseUrl: string;
42
41
  }
package/dist/module.d.ts CHANGED
@@ -36,7 +36,6 @@ interface ModuleOptions {
36
36
  interface ModuleOptionsExtend extends ModuleOptions {
37
37
  plural: string;
38
38
  dateBuild: number;
39
- baseURL: string;
40
39
  hashMode: boolean;
41
40
  apiBaseUrl: string;
42
41
  }
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
3
  "configKey": "i18n",
4
- "version": "1.27.0",
4
+ "version": "1.28.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -413,7 +413,7 @@ const module = defineNuxtModule({
413
413
  let plural = options.plural;
414
414
  if (typeof plural !== "string")
415
415
  plural = plural.toString();
416
- const apiBaseUrl = (options.apiBaseUrl ?? "_locales").replace(/^\/+/, "");
416
+ const apiBaseUrl = (process.env.NUXT_I18N_APP_BASE_URL ?? options.apiBaseUrl ?? "_locales").replace(/^\/+|\/+$|\/{2,}/, "");
417
417
  nuxt.options.runtimeConfig.public.i18nConfig = {
418
418
  plural,
419
419
  locales: localeManager.locales ?? [],
@@ -430,7 +430,6 @@ const module = defineNuxtModule({
430
430
  routesLocaleLinks: options.routesLocaleLinks ?? {},
431
431
  fallbackLocale: options.fallbackLocale ?? void 0,
432
432
  dateBuild: Date.now(),
433
- baseURL: nuxt.options.app.baseURL,
434
433
  hashMode: nuxt.options?.router?.options?.hashMode ?? false,
435
434
  globalLocaleRoutes: void 0,
436
435
  apiBaseUrl,
@@ -20,7 +20,12 @@
20
20
  <NuxtLink
21
21
  :class="`switcher-locale-${locale.code}`"
22
22
  :to="getLocaleLink(locale)"
23
- :style="[linkStyle, locale.code === currentLocale ? activeLinkStyle : {}, locale.code === currentLocale ? disabledLinkStyle : {}, customLinkStyle]"
23
+ :style="[
24
+ linkStyle,
25
+ locale.code === currentLocale ? activeLinkStyle : {},
26
+ locale.code === currentLocale ? disabledLinkStyle : {},
27
+ customLinkStyle,
28
+ ]"
24
29
  :hreflang="locale.iso || locale.code"
25
30
  @click="toggleDropdown"
26
31
  >
@@ -62,9 +67,10 @@ const props = withDefaults(defineProps<Props>(), {
62
67
  customIconStyle: () => ({}),
63
68
  })
64
69
 
65
- const { $localeRoute, $getLocales, $getLocale } = useNuxtApp()
70
+ const { $localeRoute, $getLocales, $getLocale, $getLocaleName } = useNuxtApp()
66
71
  const locales = ref($getLocales())
67
72
  const currentLocale = computed(() => $getLocale())
73
+ const currentLocaleName = computed(() => $getLocaleName())
68
74
  const dropdownOpen = ref(false)
69
75
 
70
76
  const toggleDropdown = () => {
@@ -72,14 +78,24 @@ const toggleDropdown = () => {
72
78
  }
73
79
 
74
80
  const localeLabel = (locale: Locale) => {
75
- return props.customLabels[locale.code] || locale.code.toUpperCase()
81
+ const current = props.customLabels[locale.code] || locale.displayName
82
+ if (!current) {
83
+ console.warn(
84
+ '[i18n-switcher] Either define a custom label for the locale or provide a displayName in the nuxt.config.i18n',
85
+ )
86
+ }
87
+ return current
76
88
  }
77
89
 
78
- const currentLocaleLabel = computed(() => localeLabel({ code: currentLocale.value }))
90
+ const currentLocaleLabel = computed(() => localeLabel({
91
+ code: currentLocale.value,
92
+ displayName: currentLocaleName.value ?? undefined,
93
+ }))
79
94
 
80
95
  const getLocaleLink = (locale: Locale) => {
81
96
  const route = useRoute()
82
- const routeName = (route?.name ?? '').toString()
97
+ const routeName = (route?.name ?? '')
98
+ .toString()
83
99
  .replace(`localized-`, '')
84
100
  .replace(new RegExp(`-${currentLocale.value}$`), '')
85
101
  .replace(new RegExp(`-${locale}$`), '')
@@ -4,6 +4,7 @@ export function useI18n() {
4
4
  const injections = {
5
5
  $defaultLocale: nuxtApp.$defaultLocale,
6
6
  $getLocale: nuxtApp.$getLocale,
7
+ $getLocaleName: nuxtApp.$getLocaleName,
7
8
  $getLocales: nuxtApp.$getLocales,
8
9
  $getRouteName: nuxtApp.$getRouteName,
9
10
  $t: nuxtApp.$t,
@@ -13,6 +13,7 @@ declare const _default: import("#app").Plugin<{
13
13
  i18n: undefined;
14
14
  __micro: boolean;
15
15
  getLocale: () => string;
16
+ getLocaleName: () => string | null;
16
17
  defaultLocale: () => string | undefined;
17
18
  getLocales: () => Locale[];
18
19
  getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
@@ -34,6 +35,7 @@ declare const _default: import("#app").Plugin<{
34
35
  i18n: undefined;
35
36
  __micro: boolean;
36
37
  getLocale: () => string;
38
+ getLocaleName: () => string | null;
37
39
  defaultLocale: () => string | undefined;
38
40
  getLocales: () => Locale[];
39
41
  getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
@@ -55,6 +57,7 @@ declare const _default: import("#app").Plugin<{
55
57
  export default _default;
56
58
  export interface PluginsInjections {
57
59
  $getLocale: () => string;
60
+ $getLocaleName: () => string;
58
61
  $getLocales: () => Locale[];
59
62
  $defaultLocale: () => string | undefined;
60
63
  $getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
@@ -16,6 +16,20 @@ function getCurrentLocale(route, i18nConfig, hashLocale) {
16
16
  }
17
17
  return (route.params?.locale ?? i18nConfig.defaultLocale).toString();
18
18
  }
19
+ function getCurrentName(route, i18nConfig, hashLocale) {
20
+ let currentLocale = i18nConfig.defaultLocale;
21
+ if (i18nConfig.hashMode && hashLocale) {
22
+ currentLocale = hashLocale;
23
+ } else if (route.params?.locale) {
24
+ currentLocale = (route.params?.locale ?? i18nConfig.defaultLocale).toString();
25
+ }
26
+ const checkLocale = i18nConfig.locales?.find((l) => l.code === currentLocale);
27
+ if (!checkLocale || !checkLocale.displayName) {
28
+ console.warn(`current locale name not found`);
29
+ return null;
30
+ }
31
+ return checkLocale.displayName;
32
+ }
19
33
  function getRouteName(route, locale) {
20
34
  return (route?.name ?? "").toString().replace("localized-", "").replace(new RegExp(`-${locale}$`), "");
21
35
  }
@@ -122,6 +136,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
122
136
  const i18nConfig = config.public.i18nConfig;
123
137
  const plural = new Function("return " + i18nConfig.plural.toString())();
124
138
  const apiBaseUrl = i18nConfig.apiBaseUrl ?? "_locales";
139
+ const runtimeConfig = useRuntimeConfig();
125
140
  const loadTranslationsIfNeeded = async (locale, routeName) => {
126
141
  try {
127
142
  if (!i18nHelper.hasPageTranslation(locale, routeName)) {
@@ -129,7 +144,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
129
144
  if (i18nConfig.routesLocaleLinks && i18nConfig.routesLocaleLinks[fRouteName]) {
130
145
  fRouteName = i18nConfig.routesLocaleLinks[fRouteName];
131
146
  }
132
- const data = await $fetch(`/${apiBaseUrl}/${fRouteName}/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
147
+ const data = await $fetch(`/${apiBaseUrl}/${fRouteName}/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: runtimeConfig.app.baseURL });
133
148
  await i18nHelper.loadPageTranslations(locale, routeName, data ?? {});
134
149
  }
135
150
  } catch (_error) {
@@ -139,7 +154,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
139
154
  const hashLocale2 = i18nConfig.hashMode ? nuxtApp.runWithContext(() => (useCookie("hash-locale").value ?? i18nConfig.defaultLocale).toString()).toString() : null;
140
155
  const locale = getCurrentLocale(to, i18nConfig, hashLocale2);
141
156
  if (!i18nHelper.hasGeneralTranslation(locale)) {
142
- const data = await $fetch(`/${apiBaseUrl}/general/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
157
+ const data = await $fetch(`/${apiBaseUrl}/general/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: runtimeConfig.app.baseURL });
143
158
  await i18nHelper.loadTranslations(locale, data ?? {});
144
159
  }
145
160
  if (!i18nConfig.disablePageLocales) {
@@ -180,6 +195,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
180
195
  i18n: void 0,
181
196
  __micro: true,
182
197
  getLocale: () => getCurrentLocale(useRoute(), i18nConfig, hashLocale),
198
+ getLocaleName: () => getCurrentName(useRoute(), i18nConfig, hashLocale),
183
199
  defaultLocale: () => i18nConfig.defaultLocale,
184
200
  getLocales: () => i18nConfig.locales || [],
185
201
  getRouteName: (route, locale) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.27.0",
3
+ "version": "1.28.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":"ae460766-4aac-4e10-8148-f637be2c18a6","timestamp":1729272329466,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}