nuxt-i18n-micro 1.58.0 → 1.59.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/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/cd075107-392f-495b-8345-ce296b14f76e.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 +3 -0
- package/dist/runtime/plugins/01.plugin.js +26 -2
- 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},1736500540286,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"cd075107-392f-495b-8345-ce296b14f76e",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},1736500540286,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"cd075107-392f-495b-8345-ce296b14f76e",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"cd075107-392f-495b-8345-ce296b14f76e","timestamp":1736500534009}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"cd075107-392f-495b-8345-ce296b14f76e","timestamp":1736500534009,"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},1736500540286,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"cd075107-392f-495b-8345-ce296b14f76e",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,6 +14,7 @@ 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;
|
|
@@ -36,6 +37,7 @@ 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;
|
|
@@ -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
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.59.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":"4188ace6-6c20-4aaa-b4d6-d637e487d196","timestamp":1736495272272,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|