nuxt-i18n-micro 1.27.1 → 1.29.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.
@@ -1,12 +1,12 @@
1
1
  <!DOCTYPE html><html data-capo=""><head><meta charset="utf-8">
2
2
  <meta name="viewport" content="width=device-width, initial-scale=1">
3
3
  <link rel="stylesheet" href="/__nuxt-i18n-micro/_nuxt/entry.BqOlM4b6.css">
4
- <link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/C9JTnD_j.js">
4
+ <link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/mVL4Ag1z.js">
5
5
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/B6E6ObS_.js">
6
6
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-404.C_4C5G96.css">
7
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/C9bVPi9V.js">
8
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DBxM89eY.js">
7
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/B3qz2zap.js">
8
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CtNJ_juG.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.CBAEdpZV.css">
10
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/D3gRF9DB.js">
11
- <script type="module" src="/__nuxt-i18n-micro/_nuxt/C9JTnD_j.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},1729277902621,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"a8ba103a-9ef6-4931-874d-27f2a7538974",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
10
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CKE-slgQ.js">
11
+ <script type="module" src="/__nuxt-i18n-micro/_nuxt/mVL4Ag1z.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},1729326556734,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"586a38c7-df12-4fac-ae0d-f67dd0448804",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": "1.27.1",
4
+ "version": "1.29.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
@@ -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 | null;
58
61
  $getLocales: () => Locale[];
59
62
  $defaultLocale: () => string | undefined;
60
63
  $getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
@@ -16,6 +16,14 @@ 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
+ const currentLocaleCode = getCurrentLocale(route, i18nConfig, hashLocale);
21
+ const checkLocale = i18nConfig.locales?.find((l) => l.code === currentLocaleCode);
22
+ if (!checkLocale) {
23
+ return null;
24
+ }
25
+ return checkLocale?.displayName ?? null;
26
+ }
19
27
  function getRouteName(route, locale) {
20
28
  return (route?.name ?? "").toString().replace("localized-", "").replace(new RegExp(`-${locale}$`), "");
21
29
  }
@@ -181,6 +189,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
181
189
  i18n: void 0,
182
190
  __micro: true,
183
191
  getLocale: () => getCurrentLocale(useRoute(), i18nConfig, hashLocale),
192
+ getLocaleName: () => getCurrentName(useRoute(), i18nConfig, hashLocale),
184
193
  defaultLocale: () => i18nConfig.defaultLocale,
185
194
  getLocales: () => i18nConfig.locales || [],
186
195
  getRouteName: (route, locale) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.27.1",
3
+ "version": "1.29.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":"a8ba103a-9ef6-4931-874d-27f2a7538974","timestamp":1729277889731,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}