nuxt-i18n-micro 1.27.1 → 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.
@@ -1 +1 @@
1
- {"id":"a8ba103a-9ef6-4931-874d-27f2a7538974","timestamp":1729277889731}
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":[]}
@@ -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/Czi4MokJ.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/BfH8Q6Ot.js">
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
- <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/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},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.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.28.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;
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
  }
@@ -181,6 +195,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
181
195
  i18n: void 0,
182
196
  __micro: true,
183
197
  getLocale: () => getCurrentLocale(useRoute(), i18nConfig, hashLocale),
198
+ getLocaleName: () => getCurrentName(useRoute(), i18nConfig, hashLocale),
184
199
  defaultLocale: () => i18nConfig.defaultLocale,
185
200
  getLocales: () => i18nConfig.locales || [],
186
201
  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.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",