nuxt-i18n-micro 1.5.0 → 1.6.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 +8 -480
- package/dist/client/200.html +6 -6
- package/dist/client/404.html +6 -6
- package/dist/client/_nuxt/{CdzliWdy.js → B5V5CGNX.js} +1 -1
- package/dist/client/_nuxt/{BfxQCKlw.js → C5CUDaeR.js} +1 -1
- package/dist/client/_nuxt/{Cnou2wpD.js → DUtCg1fH.js} +58 -66
- package/dist/client/_nuxt/{DrEIrqkc.js → a39Im4hm.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/4583b4b6-b29c-448a-91a8-18c469a313df.json +1 -0
- package/dist/client/index.html +6 -6
- package/dist/module.json +1 -1
- package/dist/runtime/components/i18n-link.vue +37 -0
- package/dist/runtime/components/i18n-switcher.vue +92 -0
- package/dist/runtime/plugins/01.plugin.d.ts +3 -14
- package/dist/runtime/plugins/01.plugin.js +5 -1
- package/dist/runtime/translationHelper.d.ts +2 -1
- package/dist/runtime/translationHelper.js +10 -1
- package/package.json +12 -3
- package/dist/client/_nuxt/builds/meta/d62c5b85-c72c-4371-bfa7-3402c13237f3.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as o}from"./
|
|
1
|
+
import{u as o}from"./B5V5CGNX.js";import{_ as a,o as s,c as i,a as e,t as r,p as u,f as c}from"./DUtCg1fH.js";const l=t=>(u("data-v-2c66185b"),t=t(),c(),t),d={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},p=l(()=>e("div",{class:"fixed -bottom-1/2 left-0 right-0 h-1/2 spotlight"},null,-1)),h={class:"max-w-520px text-center"},b=["textContent"],g=["textContent"],f={__name:"error-500",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:500},statusMessage:{type:String,default:"Server error"},description:{type:String,default:"This page is temporarily unavailable."}},setup(t){const n=t;return o({title:`${n.statusCode} - ${n.statusMessage} | ${n.appName}`,script:[],style:[{children:'*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:var(--un-default-border-color, #e5e7eb)}:before,:after{--un-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}h1{font-size:inherit;font-weight:inherit}h1,p{margin:0}*,:before,:after{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }'}]}),(m,x)=>(s(),i("div",d,[p,e("div",h,[e("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:r(t.statusCode)},null,8,b),e("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:r(t.description)},null,8,g)])]))}},w=a(f,[["__scopeId","data-v-2c66185b"]]);export{w as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"4583b4b6-b29c-448a-91a8-18c469a313df","timestamp":1724248922955}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"4583b4b6-b29c-448a-91a8-18c469a313df","timestamp":1724248922955,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -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.CF1WZhsD.css">
|
|
4
|
-
<link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/
|
|
4
|
+
<link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DUtCg1fH.js">
|
|
5
5
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/B6E6ObS_.js">
|
|
6
6
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-404.CjTTbIxB.css">
|
|
7
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/
|
|
8
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/
|
|
7
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/C5CUDaeR.js">
|
|
8
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/B5V5CGNX.js">
|
|
9
9
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.B4KzowuE.css">
|
|
10
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"
|
|
10
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/a39Im4hm.js">
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/DUtCg1fH.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"serverRendered":1},false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"4583b4b6-b29c-448a-91a8-18c469a313df",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<NuxtLink
|
|
3
|
+
:to="$localeRoute(to)"
|
|
4
|
+
:class="{ active: isActive }"
|
|
5
|
+
>
|
|
6
|
+
<slot>Go to Page</slot>
|
|
7
|
+
</NuxtLink>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script lang="ts" setup>
|
|
11
|
+
import { useNuxtApp, computed, useRoute, useRouter } from '#imports'
|
|
12
|
+
import type { NuxtLinkProps } from '#app/components/nuxt-link'
|
|
13
|
+
|
|
14
|
+
const { $localeRoute } = useNuxtApp()
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
to: NuxtLinkProps
|
|
18
|
+
activeClass?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const props = defineProps<Props>()
|
|
22
|
+
const route = useRoute()
|
|
23
|
+
|
|
24
|
+
const isActive = computed(() => {
|
|
25
|
+
// If `to` is a string, compare it directly to the route path
|
|
26
|
+
const newPath = $localeRoute(props.to)
|
|
27
|
+
if (typeof newPath === 'string') {
|
|
28
|
+
return route.path === useRouter().resolve(newPath).path
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return route.path === newPath.path
|
|
32
|
+
})
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<style scoped>
|
|
36
|
+
.active{color:#42b983;font-weight:700}
|
|
37
|
+
</style>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="wrapperClass">
|
|
3
|
+
<button
|
|
4
|
+
:class="buttonClass"
|
|
5
|
+
@click="toggleDropdown"
|
|
6
|
+
>
|
|
7
|
+
{{ currentLocaleLabel }}
|
|
8
|
+
<span :class="[iconClass, dropdownOpen ? 'open' : '']">▾</span>
|
|
9
|
+
</button>
|
|
10
|
+
<ul
|
|
11
|
+
v-if="dropdownOpen"
|
|
12
|
+
:class="dropdownClass"
|
|
13
|
+
>
|
|
14
|
+
<li
|
|
15
|
+
v-for="locale in locales"
|
|
16
|
+
:key="locale.code"
|
|
17
|
+
:class="[itemClass, locale.code === currentLocale ? activeClass : '']"
|
|
18
|
+
>
|
|
19
|
+
<NuxtLink
|
|
20
|
+
:to="getLocaleLink(locale)"
|
|
21
|
+
:class="[linkClass, locale.code === currentLocale ? disabledClass : '']"
|
|
22
|
+
:hreflang="locale.iso || locale.code"
|
|
23
|
+
>
|
|
24
|
+
{{ localeLabel(locale) }}
|
|
25
|
+
</NuxtLink>
|
|
26
|
+
</li>
|
|
27
|
+
</ul>
|
|
28
|
+
</div>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script lang="ts" setup>
|
|
32
|
+
import { ref, computed } from 'vue'
|
|
33
|
+
import { useNuxtApp } from '#app'
|
|
34
|
+
import { useRoute } from '#imports'
|
|
35
|
+
|
|
36
|
+
interface Locale {
|
|
37
|
+
code: string
|
|
38
|
+
iso?: string
|
|
39
|
+
dir?: 'rtl' | 'ltr'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface Props {
|
|
43
|
+
wrapperClass?: string
|
|
44
|
+
buttonClass?: string
|
|
45
|
+
dropdownClass?: string
|
|
46
|
+
itemClass?: string
|
|
47
|
+
linkClass?: string
|
|
48
|
+
activeClass?: string
|
|
49
|
+
disabledClass?: string
|
|
50
|
+
iconClass?: string
|
|
51
|
+
customLabels?: Record<string, string>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
55
|
+
wrapperClass: 'locale-switcher',
|
|
56
|
+
buttonClass: 'locale-button',
|
|
57
|
+
dropdownClass: 'locale-dropdown',
|
|
58
|
+
itemClass: 'locale-item',
|
|
59
|
+
linkClass: 'locale-link',
|
|
60
|
+
activeClass: 'active',
|
|
61
|
+
disabledClass: 'disabled',
|
|
62
|
+
iconClass: 'dropdown-icon',
|
|
63
|
+
customLabels: () => ({}),
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const { $localeRoute, $getLocales, $getLocale } = useNuxtApp()
|
|
67
|
+
const locales = ref($getLocales())
|
|
68
|
+
const currentLocale = ref($getLocale())
|
|
69
|
+
const dropdownOpen = ref(false)
|
|
70
|
+
|
|
71
|
+
const toggleDropdown = () => {
|
|
72
|
+
dropdownOpen.value = !dropdownOpen.value
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const localeLabel = (locale: Locale) => {
|
|
76
|
+
return props.customLabels[locale.code] || locale.code.toUpperCase()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const currentLocaleLabel = computed(() => localeLabel({ code: currentLocale.value }))
|
|
80
|
+
|
|
81
|
+
const getLocaleLink = (locale: Locale) => {
|
|
82
|
+
const route = useRoute()
|
|
83
|
+
|
|
84
|
+
const routeName = (route?.name ?? '').toString().replace(`localized-`, '')
|
|
85
|
+
|
|
86
|
+
return $localeRoute({ name: routeName }, locale.code)
|
|
87
|
+
}
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<style scoped>
|
|
91
|
+
.locale-switcher{display:inline-block;position:relative}.locale-button{align-items:center;background-color:#fff;border:1px solid #333;cursor:pointer;display:flex;font-size:16px;justify-content:space-between;padding:4px 12px;transition:background-color .3s ease}.locale-button:hover{background-color:#f0f0f0}.locale-dropdown{background-color:#fff;border:1px solid #333;left:0;list-style:none;margin:4px 0 0;padding:0;position:absolute;top:100%;z-index:10}.locale-item{margin:0;padding:0}.locale-link{color:#333;display:block;padding:8px 12px;text-decoration:none;transition:background-color .3s ease}.locale-link:hover{background-color:#f0f0f0}.locale-link.disabled{color:#aaa;cursor:not-allowed}.locale-link.active{color:#007bff;font-weight:700}.dropdown-icon{margin-left:8px;transition:transform .3s ease}.dropdown-icon.open{transform:rotate(180deg)}
|
|
92
|
+
</style>
|
|
@@ -46,22 +46,11 @@ declare module '@vue/runtime-core' {
|
|
|
46
46
|
interface ComponentCustomProperties extends PluginsInjections {
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
declare module 'nuxt/dist/app/nuxt' {
|
|
50
|
-
interface NuxtApp extends PluginsInjections {
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
49
|
declare module 'vue' {
|
|
54
50
|
interface ComponentCustomProperties extends PluginsInjections {
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
|
-
declare
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const $t: <T extends Record<string, string | number | boolean>>(key: string, params?: T, defaultValue?: string) => string | number | boolean | Translations | PluralTranslations | unknown[] | unknown | null;
|
|
61
|
-
const $tc: (key: string, count: number, defaultValue?: string) => string;
|
|
62
|
-
const $has: (key: string) => boolean;
|
|
63
|
-
const $mergeTranslations: (newTranslations: Translations) => void;
|
|
64
|
-
const $switchLocale: (locale: string) => void;
|
|
65
|
-
const $localeRoute: (to: RouteLocationRaw, locale?: string) => RouteLocationRaw;
|
|
66
|
-
const $loadPageTranslations: (locale: string, routeName: string) => Promise<void>;
|
|
53
|
+
declare module '#app/nuxt' {
|
|
54
|
+
interface NuxtApp extends PluginsInjections {
|
|
55
|
+
}
|
|
67
56
|
}
|
|
@@ -39,6 +39,10 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale) {
|
|
|
39
39
|
}
|
|
40
40
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
41
41
|
const router = useRouter();
|
|
42
|
+
const registerI18nModule = (translations, locale) => {
|
|
43
|
+
i18nHelper.margeGlobalTranslation(locale, translations);
|
|
44
|
+
};
|
|
45
|
+
await nuxtApp.callHook("i18n:register", registerI18nModule);
|
|
42
46
|
if (!nuxtApp.payload.data.translations) {
|
|
43
47
|
nuxtApp.payload.data.translations = {};
|
|
44
48
|
}
|
|
@@ -85,7 +89,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
85
89
|
const initialLocale = (route.params?.locale ?? i18nConfig.defaultLocale).toString();
|
|
86
90
|
const initialRouteName = route.name.replace(`localized-`, "");
|
|
87
91
|
const data = await $fetch(`/_locales/general/${initialLocale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
|
|
88
|
-
await i18nHelper.loadTranslations(initialLocale,
|
|
92
|
+
await i18nHelper.loadTranslations(initialLocale, data ?? {});
|
|
89
93
|
if (import.meta.server) {
|
|
90
94
|
const locale = (route.params?.locale ?? i18nConfig.defaultLocale).toString();
|
|
91
95
|
let routeName = initialRouteName;
|
|
@@ -4,9 +4,10 @@ export declare function useTranslationHelper(): {
|
|
|
4
4
|
getCache(locale: string, routeName: string): Map<string, unknown>;
|
|
5
5
|
setCache(locale: string, routeName: string, cache: Map<string, Translations | unknown>): void;
|
|
6
6
|
margeTranslation(locale: string, routeName: string, newTranslations: Translations): void;
|
|
7
|
+
margeGlobalTranslation(locale: string, newTranslations: Translations): void;
|
|
7
8
|
hasGeneralTranslation(locale: string): boolean;
|
|
8
9
|
hasPageTranslation(locale: string, routeName: string): boolean;
|
|
9
10
|
getTranslation: <T = unknown>(locale: string, routeName: string, key: string, useCache: boolean) => T | null;
|
|
10
11
|
loadPageTranslations: (locale: string, routeName: string, translations: Translations) => Promise<void>;
|
|
11
|
-
loadTranslations: (locale: string,
|
|
12
|
+
loadTranslations: (locale: string, translations: Translations) => Promise<void>;
|
|
12
13
|
};
|
|
@@ -43,6 +43,15 @@ export function useTranslationHelper() {
|
|
|
43
43
|
console.error(`marge: route ${locale}:${routeName} not loaded`);
|
|
44
44
|
}
|
|
45
45
|
routeLocaleCache[`${locale}:${routeName}`] = {
|
|
46
|
+
...routeLocaleCache[`${locale}:${routeName}`],
|
|
47
|
+
...newTranslations
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
margeGlobalTranslation(locale, newTranslations) {
|
|
51
|
+
if (!generalLocaleCache[`${locale}`]) {
|
|
52
|
+
console.error(`marge: route ${locale} not loaded`);
|
|
53
|
+
}
|
|
54
|
+
generalLocaleCache[locale] = {
|
|
46
55
|
...generalLocaleCache[locale],
|
|
47
56
|
...newTranslations
|
|
48
57
|
};
|
|
@@ -101,7 +110,7 @@ export function useTranslationHelper() {
|
|
|
101
110
|
console.error(`Error loading translations for ${locale} and ${routeName}:`, error);
|
|
102
111
|
}
|
|
103
112
|
},
|
|
104
|
-
loadTranslations: async (locale,
|
|
113
|
+
loadTranslations: async (locale, translations) => {
|
|
105
114
|
try {
|
|
106
115
|
if (!generalLocaleCache[locale]) {
|
|
107
116
|
generalLocaleCache[locale] = { ...translations };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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",
|
|
@@ -52,7 +52,12 @@
|
|
|
52
52
|
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
|
|
53
53
|
"client:build": "nuxi generate client",
|
|
54
54
|
"client:dev": "nuxi dev client --port 3300",
|
|
55
|
-
"typecheck": "tsc --noEmit"
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"docs:dev": "vitepress dev docs",
|
|
57
|
+
"docs:build": "vitepress build docs",
|
|
58
|
+
"docs:serve": "vitepress serve docs",
|
|
59
|
+
"docs:clean-dev": "vitepress dev docs --clean-cache",
|
|
60
|
+
"docs:preview": "vitepress preview docs"
|
|
56
61
|
},
|
|
57
62
|
"dependencies": {
|
|
58
63
|
"@nuxt/devtools-kit": "^1.3.9",
|
|
@@ -75,8 +80,12 @@
|
|
|
75
80
|
"execa": "^9.3.0",
|
|
76
81
|
"nuxt": "^3.12.4",
|
|
77
82
|
"typescript": "latest",
|
|
83
|
+
"vitepress": "^1.3.3",
|
|
78
84
|
"vitest": "^2.0.3",
|
|
79
|
-
"vue-tsc": "
|
|
85
|
+
"vue-tsc": "2.0.22"
|
|
80
86
|
},
|
|
87
|
+
"workspaces": [
|
|
88
|
+
"client"
|
|
89
|
+
],
|
|
81
90
|
"packageManager": "yarn@3.7.0+sha256.7bf0c78a106332886ea4e59641fd819b1af953edcd72c4d93a32b1c71000ee67"
|
|
82
91
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"d62c5b85-c72c-4371-bfa7-3402c13237f3","timestamp":1724181280320,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|