nuxt-i18n-micro 1.58.0 → 1.59.1
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/dist/client/200.html +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/569329fc-a258-4243-a57f-6857e7d94336.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/runtime/components/i18n-t.vue +20 -1
- package/dist/runtime/components/i18n-t.vue.d.ts +18 -0
- package/dist/runtime/composables/useI18n.js +1 -0
- package/dist/runtime/plugins/01.plugin.d.ts +7 -4
- package/dist/runtime/plugins/01.plugin.js +38 -8
- package/package.json +1 -1
- package/dist/client/_nuxt/builds/meta/4188ace6-6c20-4aaa-b4d6-d637e487d196.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/EwNUkbJF.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.C2JGrgZX.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/DuZjM2Ym.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C9njAg9E.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},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C9njAg9E.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},1736852822644,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"569329fc-a258-4243-a57f-6857e7d94336",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/EwNUkbJF.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.C2JGrgZX.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/DuZjM2Ym.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C9njAg9E.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},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C9njAg9E.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},1736852822644,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"569329fc-a258-4243-a57f-6857e7d94336",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"569329fc-a258-4243-a57f-6857e7d94336","timestamp":1736852817464}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"569329fc-a258-4243-a57f-6857e7d94336","timestamp":1736852817464,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/EwNUkbJF.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.C2JGrgZX.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/DuZjM2Ym.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C9njAg9E.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},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C9njAg9E.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},1736852822644,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"569329fc-a258-4243-a57f-6857e7d94336",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
|
@@ -34,12 +34,31 @@ export default defineComponent({
|
|
|
34
34
|
customPluralRule: {
|
|
35
35
|
type: Function,
|
|
36
36
|
default: null
|
|
37
|
+
},
|
|
38
|
+
number: {
|
|
39
|
+
type: [Number, String]
|
|
40
|
+
},
|
|
41
|
+
date: {
|
|
42
|
+
type: [Date, String, Number]
|
|
43
|
+
},
|
|
44
|
+
relativeDate: {
|
|
45
|
+
type: [Date, String, Number]
|
|
37
46
|
}
|
|
38
47
|
},
|
|
39
48
|
setup(props, { slots, attrs }) {
|
|
40
49
|
return () => {
|
|
41
50
|
const options = {};
|
|
42
|
-
const { $getLocale, $t, $tc } = useNuxtApp();
|
|
51
|
+
const { $getLocale, $t, $tc, $tn, $td, $tdr } = useNuxtApp();
|
|
52
|
+
if (props.number !== void 0) {
|
|
53
|
+
const numberValue = Number(props.number);
|
|
54
|
+
return h(props.tag, { ...attrs, innerHTML: $t(props.keypath, { number: $tn(numberValue) }) });
|
|
55
|
+
}
|
|
56
|
+
if (props.date !== void 0) {
|
|
57
|
+
return h(props.tag, { ...attrs, innerHTML: $t(props.keypath, { date: $td(props.date) }) });
|
|
58
|
+
}
|
|
59
|
+
if (props.relativeDate !== void 0) {
|
|
60
|
+
return h(props.tag, { ...attrs, innerHTML: $t(props.keypath, { relativeDate: $tdr(props.relativeDate) }) });
|
|
61
|
+
}
|
|
43
62
|
if (props.plural !== void 0) {
|
|
44
63
|
const count = Number.parseInt(props.plural.toString());
|
|
45
64
|
if (props.customPluralRule) {
|
|
@@ -32,6 +32,15 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
32
32
|
type: PropType<PluralFunc>;
|
|
33
33
|
default: null;
|
|
34
34
|
};
|
|
35
|
+
number: {
|
|
36
|
+
type: PropType<number | string>;
|
|
37
|
+
};
|
|
38
|
+
date: {
|
|
39
|
+
type: PropType<Date | string | number>;
|
|
40
|
+
};
|
|
41
|
+
relativeDate: {
|
|
42
|
+
type: PropType<Date | string | number>;
|
|
43
|
+
};
|
|
35
44
|
}>, () => string | VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
36
45
|
[key: string]: any;
|
|
37
46
|
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -66,6 +75,15 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
66
75
|
type: PropType<PluralFunc>;
|
|
67
76
|
default: null;
|
|
68
77
|
};
|
|
78
|
+
number: {
|
|
79
|
+
type: PropType<number | string>;
|
|
80
|
+
};
|
|
81
|
+
date: {
|
|
82
|
+
type: PropType<Date | string | number>;
|
|
83
|
+
};
|
|
84
|
+
relativeDate: {
|
|
85
|
+
type: PropType<Date | string | number>;
|
|
86
|
+
};
|
|
69
87
|
}>> & Readonly<{}>, {
|
|
70
88
|
params: Record<string, string | number | boolean>;
|
|
71
89
|
tag: string;
|
|
@@ -14,13 +14,14 @@ declare const _default: import("nuxt/app").Plugin<{
|
|
|
14
14
|
tc: (key: string, params: number | Params, defaultValue?: string) => string;
|
|
15
15
|
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
16
16
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
17
|
+
tdr(value: Date | number | string, options?: Intl.RelativeTimeFormatOptions): string;
|
|
17
18
|
has: (key: string) => boolean;
|
|
18
19
|
mergeTranslations: (newTranslations: Translations) => void;
|
|
19
20
|
switchLocaleRoute: (toLocale: string) => string | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric;
|
|
20
21
|
switchLocalePath: (toLocale: string) => string;
|
|
21
22
|
switchLocale: (toLocale: string) => void;
|
|
22
|
-
switchRoute: (
|
|
23
|
-
localeRoute: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => RouteLocationResolved;
|
|
23
|
+
switchRoute: (to: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric | string, toLocale?: string) => void;
|
|
24
|
+
localeRoute: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath | string, locale?: string) => RouteLocationResolved;
|
|
24
25
|
localePath: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => string;
|
|
25
26
|
setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
|
|
26
27
|
}> & import("nuxt/app").ObjectPlugin<{
|
|
@@ -36,13 +37,14 @@ declare const _default: import("nuxt/app").Plugin<{
|
|
|
36
37
|
tc: (key: string, params: number | Params, defaultValue?: string) => string;
|
|
37
38
|
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
38
39
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
40
|
+
tdr(value: Date | number | string, options?: Intl.RelativeTimeFormatOptions): string;
|
|
39
41
|
has: (key: string) => boolean;
|
|
40
42
|
mergeTranslations: (newTranslations: Translations) => void;
|
|
41
43
|
switchLocaleRoute: (toLocale: string) => string | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric;
|
|
42
44
|
switchLocalePath: (toLocale: string) => string;
|
|
43
45
|
switchLocale: (toLocale: string) => void;
|
|
44
|
-
switchRoute: (
|
|
45
|
-
localeRoute: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => RouteLocationResolved;
|
|
46
|
+
switchRoute: (to: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric | string, toLocale?: string) => void;
|
|
47
|
+
localeRoute: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath | string, locale?: string) => RouteLocationResolved;
|
|
46
48
|
localePath: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => string;
|
|
47
49
|
setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
|
|
48
50
|
}>;
|
|
@@ -58,6 +60,7 @@ export interface PluginsInjections {
|
|
|
58
60
|
$tc: (key: string, params: number | Params, defaultValue?: string) => string;
|
|
59
61
|
$tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
60
62
|
$td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
63
|
+
$tdr: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
61
64
|
$has: (key: string) => boolean;
|
|
62
65
|
$mergeTranslations: (newTranslations: Translations) => void;
|
|
63
66
|
$switchLocaleRoute: (locale: string) => RouteLocationRaw;
|
|
@@ -97,7 +97,7 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRoute
|
|
|
97
97
|
return navigateTo(switchedRoute, { redirectCode: 200, external: true });
|
|
98
98
|
}
|
|
99
99
|
if (isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
100
|
-
|
|
100
|
+
switchedRoute.force = true;
|
|
101
101
|
}
|
|
102
102
|
return router.push(switchedRoute);
|
|
103
103
|
}
|
|
@@ -192,6 +192,26 @@ function formatNumber(value, locale, options) {
|
|
|
192
192
|
function formatDate(value, locale, options) {
|
|
193
193
|
return new Intl.DateTimeFormat(locale, options).format(new Date(value));
|
|
194
194
|
}
|
|
195
|
+
function formatRelativeTime(value, locale, options) {
|
|
196
|
+
const date = new Date(value);
|
|
197
|
+
const now = /* @__PURE__ */ new Date();
|
|
198
|
+
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1e3);
|
|
199
|
+
const units = [
|
|
200
|
+
{ unit: "year", seconds: 31536e3 },
|
|
201
|
+
{ unit: "month", seconds: 2592e3 },
|
|
202
|
+
{ unit: "day", seconds: 86400 },
|
|
203
|
+
{ unit: "hour", seconds: 3600 },
|
|
204
|
+
{ unit: "minute", seconds: 60 },
|
|
205
|
+
{ unit: "second", seconds: 1 }
|
|
206
|
+
];
|
|
207
|
+
for (const { unit, seconds } of units) {
|
|
208
|
+
const diff = Math.floor(diffInSeconds / seconds);
|
|
209
|
+
if (diff >= 1) {
|
|
210
|
+
return new Intl.RelativeTimeFormat(locale, options).format(-diff, unit);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return new Intl.RelativeTimeFormat(locale, options).format(0, "second");
|
|
214
|
+
}
|
|
195
215
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
196
216
|
if (!nuxtApp.payload.data.translations) {
|
|
197
217
|
nuxtApp.payload.data.translations = {};
|
|
@@ -267,7 +287,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
267
287
|
}, i18nHelper.getLocale());
|
|
268
288
|
}
|
|
269
289
|
router.beforeEach(async (to, from, next) => {
|
|
270
|
-
if (to.fullPath !== from.fullPath) {
|
|
290
|
+
if (to.fullPath !== from.fullPath || isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
271
291
|
await loadGlobalTranslations(to);
|
|
272
292
|
}
|
|
273
293
|
if (next) {
|
|
@@ -322,6 +342,10 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
322
342
|
const locale = i18nHelper.getLocale();
|
|
323
343
|
return formatDate(value, locale, options);
|
|
324
344
|
},
|
|
345
|
+
tdr(value, options) {
|
|
346
|
+
const locale = i18nHelper.getLocale();
|
|
347
|
+
return formatRelativeTime(value, locale, options);
|
|
348
|
+
},
|
|
325
349
|
has: (key) => {
|
|
326
350
|
return !!getTranslation(key);
|
|
327
351
|
},
|
|
@@ -350,22 +374,28 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
350
374
|
const route2 = router.currentRoute.value;
|
|
351
375
|
switchLocale(i18nHelper.getLocale(), toLocale, route2, router, i18nConfig, i18nRouteParams.value);
|
|
352
376
|
},
|
|
353
|
-
switchRoute: (
|
|
377
|
+
switchRoute: (to, toLocale) => {
|
|
354
378
|
const currentRoute = router.currentRoute.value;
|
|
355
379
|
const fromLocale = (currentRoute.params?.locale ?? i18nConfig.defaultLocale).toString();
|
|
356
380
|
const currentLocale2 = toLocale ?? fromLocale;
|
|
357
|
-
|
|
358
|
-
if (typeof route2 === "string" && !isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
381
|
+
if (typeof to === "string" && !isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
359
382
|
if (currentLocale2 !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
|
|
360
|
-
to = router.resolve("/" + fromLocale +
|
|
383
|
+
to = router.resolve("/" + fromLocale + to);
|
|
361
384
|
} else {
|
|
362
|
-
to = router.resolve(
|
|
385
|
+
to = router.resolve(route);
|
|
363
386
|
}
|
|
364
387
|
}
|
|
365
388
|
if (!to) {
|
|
366
389
|
return;
|
|
367
390
|
}
|
|
368
|
-
switchLocale(
|
|
391
|
+
switchLocale(
|
|
392
|
+
i18nHelper.getLocale(),
|
|
393
|
+
toLocale ?? fromLocale,
|
|
394
|
+
to,
|
|
395
|
+
router,
|
|
396
|
+
i18nConfig,
|
|
397
|
+
i18nRouteParams.value
|
|
398
|
+
);
|
|
369
399
|
},
|
|
370
400
|
localeRoute: (to, locale) => {
|
|
371
401
|
const fromLocale = i18nHelper.getLocale();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.59.1",
|
|
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":"4188ace6-6c20-4aaa-b4d6-d637e487d196","timestamp":1736495272272,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|