nuxt-i18n-micro 3.30.3 → 4.0.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/LICENSE +1 -1
- package/README.md +2 -2
- package/dist/client/200.html +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/BVna_KKx.js +3 -0
- package/dist/client/_nuxt/Bw81RhAv.js +1 -0
- package/dist/client/_nuxt/CPz_jhsD.js +1 -0
- package/dist/client/_nuxt/CmvObVGq.js +1 -0
- package/dist/client/_nuxt/DKUOBR6F.js +5 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/f0c8d4bf-40d2-4915-8b4a-ebe46bde61c8.json +1 -0
- package/dist/client/_nuxt/{entry.BM-mexAv.css → entry.PSWtHhay.css} +1 -1
- package/dist/client/_nuxt/error-404.xs3fxhVJ.css +1 -0
- package/dist/client/_nuxt/error-500.C2S-4iLg.css +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.d.mts +14 -5
- package/dist/module.json +4 -1
- package/dist/module.mjs +850 -475
- package/dist/runtime/components/i18n-group.d.vue.ts +17 -9
- package/dist/runtime/components/i18n-group.vue +2 -4
- package/dist/runtime/components/i18n-group.vue.d.ts +17 -9
- package/dist/runtime/components/i18n-link.d.vue.ts +9 -6
- package/dist/runtime/components/i18n-link.vue +7 -28
- package/dist/runtime/components/i18n-link.vue.d.ts +9 -6
- package/dist/runtime/components/i18n-switcher.d.vue.ts +128 -54
- package/dist/runtime/components/i18n-switcher.vue +56 -156
- package/dist/runtime/components/i18n-switcher.vue.d.ts +128 -54
- package/dist/runtime/components/i18n-t.d.vue.ts +59 -116
- package/dist/runtime/components/i18n-t.vue +24 -71
- package/dist/runtime/components/i18n-t.vue.d.ts +59 -116
- package/dist/runtime/composables/useI18n.js +2 -38
- package/dist/runtime/composables/useI18nHead.js +21 -6
- package/dist/runtime/composables/useI18nLocale.d.ts +4 -1
- package/dist/runtime/composables/useI18nLocale.js +20 -22
- package/dist/runtime/composables/useLocaleHead.d.ts +26 -31
- package/dist/runtime/composables/useLocaleHead.js +47 -167
- package/dist/runtime/devtools/bridge.d.ts +2 -2
- package/dist/runtime/devtools/vue-devtools.d.ts +2 -2
- package/dist/runtime/devtools/vue-devtools.js +5 -5
- package/dist/runtime/middleware/i18n-redirect.global.d.ts +3 -2
- package/dist/runtime/middleware/i18n-redirect.global.js +30 -41
- package/dist/runtime/plugins/01.plugin.d.ts +156 -34
- package/dist/runtime/plugins/01.plugin.js +184 -138
- package/dist/runtime/plugins/02.meta.js +36 -43
- package/dist/runtime/plugins/04.vue-devtools.js +1 -1
- package/dist/runtime/plugins/06.redirect.d.ts +3 -3
- package/dist/runtime/plugins/06.redirect.js +65 -91
- package/dist/runtime/server/{utils → internal}/dev-live-translations.js +4 -3
- package/dist/runtime/server/internal/server-translation-cache.d.ts +9 -0
- package/dist/runtime/server/internal/server-translation-cache.js +10 -0
- package/dist/runtime/server/internal/shared-cache.d.ts +24 -0
- package/dist/runtime/server/internal/shared-cache.js +71 -0
- package/dist/runtime/server/internal/translation-watcher.d.ts +79 -0
- package/dist/runtime/server/internal/translation-watcher.js +105 -0
- package/dist/runtime/server/middleware/i18n.global.js +24 -37
- package/dist/runtime/server/payload-source.assets.d.ts +1 -0
- package/dist/runtime/server/payload-source.assets.js +3 -8
- package/dist/runtime/server/payload-source.fs.d.ts +1 -0
- package/dist/runtime/server/payload-source.fs.js +18 -7
- package/dist/runtime/server/plugins/failed-read.d.ts +7 -0
- package/dist/runtime/server/plugins/failed-read.js +23 -0
- package/dist/runtime/server/plugins/payload-cache.d.ts +6 -0
- package/dist/runtime/server/plugins/payload-cache.js +16 -0
- package/dist/runtime/server/plugins/watcher.dev.js +15 -79
- package/dist/runtime/server/routes/i18n.js +13 -14
- package/dist/runtime/server/utils/locale-detector.d.ts +32 -2
- package/dist/runtime/server/utils/locale-detector.js +48 -27
- package/dist/runtime/server/utils/locale-server-middleware.js +14 -33
- package/dist/runtime/server/utils/payload-cache.d.ts +4 -0
- package/dist/runtime/server/utils/payload-cache.js +13 -0
- package/dist/runtime/server/utils/server-loader.d.ts +17 -6
- package/dist/runtime/server/utils/server-loader.js +105 -51
- package/dist/runtime/server/utils/translation-server-middleware.js +18 -35
- package/dist/runtime/utils/cache-keys.d.ts +6 -0
- package/dist/runtime/utils/cache-keys.js +2 -0
- package/dist/runtime/utils/i18n-api.d.ts +185 -0
- package/dist/runtime/utils/i18n-api.js +196 -0
- package/dist/runtime/utils/i18n-config.d.ts +18 -0
- package/dist/runtime/utils/i18n-config.js +47 -0
- package/dist/runtime/utils/i18n-navigation.d.ts +26 -0
- package/dist/runtime/utils/i18n-navigation.js +96 -0
- package/dist/runtime/utils/nuxt-i18n-server.d.ts +26 -0
- package/dist/runtime/utils/nuxt-i18n-server.js +83 -0
- package/dist/runtime/utils/nuxt-i18n.d.ts +81 -96
- package/dist/runtime/utils/nuxt-i18n.js +180 -252
- package/dist/runtime/utils/page-head.d.ts +12 -0
- package/dist/runtime/utils/page-head.js +6 -0
- package/dist/runtime/utils/request-url.d.ts +6 -0
- package/dist/runtime/utils/request-url.js +11 -0
- package/dist/runtime/utils/storage.d.ts +31 -19
- package/dist/runtime/utils/storage.js +100 -49
- package/dist/runtime/utils/translation-entry.d.ts +6 -0
- package/dist/runtime/utils/translation-entry.js +16 -0
- package/dist/types.d.mts +4 -6
- package/internals.d.mts +9 -2
- package/package.json +78 -79
- package/dist/client/_nuxt/BOxWElQP.js +0 -21
- package/dist/client/_nuxt/CUWB4CwN.js +0 -3
- package/dist/client/_nuxt/CmUbe-uv.js +0 -1
- package/dist/client/_nuxt/DAzShkZF.js +0 -1
- package/dist/client/_nuxt/MokPP5zi.js +0 -1
- package/dist/client/_nuxt/builds/meta/60974e48-d00e-4f9b-9467-9d4b322519da.json +0 -1
- package/dist/client/_nuxt/error-404.D9Svp6Hk.css +0 -1
- package/dist/client/_nuxt/error-500.B-mjI9_9.css +0 -1
- package/dist/runtime/plugins/03.define.d.ts +0 -7
- package/dist/runtime/plugins/03.define.js +0 -42
- package/dist/runtime/plugins/05.hooks.d.ts +0 -2
- package/dist/runtime/plugins/05.hooks.js +0 -47
- package/dist/runtime/server/utils/server-translation-cache.d.ts +0 -11
- package/dist/runtime/server/utils/server-translation-cache.js +0 -20
- /package/dist/runtime/server/{utils → internal}/dev-live-translations.d.ts +0 -0
|
@@ -1,57 +1,108 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { Locale } from '@i18n-micro/types';
|
|
2
|
+
import type { CSSProperties, PropType, SlotsType } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* A locale switcher: a button showing the current locale and a dropdown of the rest,
|
|
5
|
+
* each linking to the equivalent route in that locale.
|
|
6
|
+
*
|
|
7
|
+
* It ships small inline default styles; each `custom*Style` prop is merged on top of the
|
|
8
|
+
* matching part, and the slots add markup around it. Locales with `disabled: true` are not listed.
|
|
9
|
+
* A click on a link is one navigation; with a modifier key it is the browser's (a new tab).
|
|
10
|
+
*/
|
|
11
|
+
declare const _default: typeof __VLS_export;
|
|
12
|
+
export default _default;
|
|
13
|
+
declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
14
|
+
/** Display name per locale code, overriding the `displayName` from the locale config. */
|
|
15
|
+
customLabels: {
|
|
16
|
+
type: PropType<Record<string, string>>;
|
|
17
|
+
default: () => {};
|
|
18
|
+
};
|
|
19
|
+
/** Inline style for the outer wrapper. */
|
|
20
|
+
customWrapperStyle: {
|
|
21
|
+
type: PropType<CSSProperties>;
|
|
22
|
+
default: () => {};
|
|
23
|
+
};
|
|
24
|
+
/** Inline style for the button that opens the dropdown. */
|
|
25
|
+
customButtonStyle: {
|
|
26
|
+
type: PropType<CSSProperties>;
|
|
27
|
+
default: () => {};
|
|
28
|
+
};
|
|
29
|
+
/** Inline style for the dropdown panel. */
|
|
30
|
+
customDropdownStyle: {
|
|
31
|
+
type: PropType<CSSProperties>;
|
|
32
|
+
default: () => {};
|
|
33
|
+
};
|
|
34
|
+
/** Inline style for each item in the dropdown. */
|
|
35
|
+
customItemStyle: {
|
|
36
|
+
type: PropType<CSSProperties>;
|
|
37
|
+
default: () => {};
|
|
38
|
+
};
|
|
39
|
+
/** Inline style for the link inside an item. */
|
|
40
|
+
customLinkStyle: {
|
|
41
|
+
type: PropType<CSSProperties>;
|
|
42
|
+
default: () => {};
|
|
43
|
+
};
|
|
44
|
+
/** Inline style for the link of the currently active locale. */
|
|
45
|
+
customActiveLinkStyle: {
|
|
46
|
+
type: PropType<CSSProperties>;
|
|
47
|
+
default: () => {};
|
|
48
|
+
};
|
|
49
|
+
/** Inline style for the *current* locale button when it is `disabled: true` in config. */
|
|
50
|
+
customDisabledLinkStyle: {
|
|
51
|
+
type: PropType<CSSProperties>;
|
|
52
|
+
default: () => {};
|
|
53
|
+
};
|
|
54
|
+
/** Inline style for the caret icon on the button. */
|
|
55
|
+
customIconStyle: {
|
|
56
|
+
type: PropType<CSSProperties>;
|
|
57
|
+
default: () => {};
|
|
58
|
+
};
|
|
59
|
+
}>, () => unknown, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
3
60
|
/** Display name per locale code, overriding the `displayName` from the locale config. */
|
|
4
|
-
customLabels
|
|
61
|
+
customLabels: {
|
|
62
|
+
type: PropType<Record<string, string>>;
|
|
63
|
+
default: () => {};
|
|
64
|
+
};
|
|
5
65
|
/** Inline style for the outer wrapper. */
|
|
6
|
-
customWrapperStyle
|
|
66
|
+
customWrapperStyle: {
|
|
67
|
+
type: PropType<CSSProperties>;
|
|
68
|
+
default: () => {};
|
|
69
|
+
};
|
|
7
70
|
/** Inline style for the button that opens the dropdown. */
|
|
8
|
-
customButtonStyle
|
|
71
|
+
customButtonStyle: {
|
|
72
|
+
type: PropType<CSSProperties>;
|
|
73
|
+
default: () => {};
|
|
74
|
+
};
|
|
9
75
|
/** Inline style for the dropdown panel. */
|
|
10
|
-
customDropdownStyle
|
|
76
|
+
customDropdownStyle: {
|
|
77
|
+
type: PropType<CSSProperties>;
|
|
78
|
+
default: () => {};
|
|
79
|
+
};
|
|
11
80
|
/** Inline style for each item in the dropdown. */
|
|
12
|
-
customItemStyle
|
|
81
|
+
customItemStyle: {
|
|
82
|
+
type: PropType<CSSProperties>;
|
|
83
|
+
default: () => {};
|
|
84
|
+
};
|
|
13
85
|
/** Inline style for the link inside an item. */
|
|
14
|
-
customLinkStyle
|
|
86
|
+
customLinkStyle: {
|
|
87
|
+
type: PropType<CSSProperties>;
|
|
88
|
+
default: () => {};
|
|
89
|
+
};
|
|
15
90
|
/** Inline style for the link of the currently active locale. */
|
|
16
|
-
customActiveLinkStyle
|
|
91
|
+
customActiveLinkStyle: {
|
|
92
|
+
type: PropType<CSSProperties>;
|
|
93
|
+
default: () => {};
|
|
94
|
+
};
|
|
17
95
|
/** Inline style for the *current* locale button when it is `disabled: true` in config. */
|
|
18
|
-
customDisabledLinkStyle
|
|
96
|
+
customDisabledLinkStyle: {
|
|
97
|
+
type: PropType<CSSProperties>;
|
|
98
|
+
default: () => {};
|
|
99
|
+
};
|
|
19
100
|
/** Inline style for the caret icon on the button. */
|
|
20
|
-
customIconStyle
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
locale: any;
|
|
26
|
-
}, __VLS_23: {
|
|
27
|
-
locale: any;
|
|
28
|
-
}, __VLS_25: {
|
|
29
|
-
locale: any;
|
|
30
|
-
}, __VLS_27: {}, __VLS_29: {};
|
|
31
|
-
type __VLS_Slots = {} & {
|
|
32
|
-
'before-button'?: (props: typeof __VLS_1) => any;
|
|
33
|
-
} & {
|
|
34
|
-
'before-selected-locale'?: (props: typeof __VLS_3) => any;
|
|
35
|
-
} & {
|
|
36
|
-
'after-selected-locale'?: (props: typeof __VLS_5) => any;
|
|
37
|
-
} & {
|
|
38
|
-
'before-dropdown'?: (props: typeof __VLS_7) => any;
|
|
39
|
-
} & {
|
|
40
|
-
'before-dropdown-items'?: (props: typeof __VLS_9) => any;
|
|
41
|
-
} & {
|
|
42
|
-
'before-item'?: (props: typeof __VLS_11) => any;
|
|
43
|
-
} & {
|
|
44
|
-
'before-link-content'?: (props: typeof __VLS_21) => any;
|
|
45
|
-
} & {
|
|
46
|
-
'after-link-content'?: (props: typeof __VLS_23) => any;
|
|
47
|
-
} & {
|
|
48
|
-
'after-item'?: (props: typeof __VLS_25) => any;
|
|
49
|
-
} & {
|
|
50
|
-
'after-dropdown-items'?: (props: typeof __VLS_27) => any;
|
|
51
|
-
} & {
|
|
52
|
-
'after-dropdown'?: (props: typeof __VLS_29) => any;
|
|
53
|
-
};
|
|
54
|
-
declare const __VLS_base: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
101
|
+
customIconStyle: {
|
|
102
|
+
type: PropType<CSSProperties>;
|
|
103
|
+
default: () => {};
|
|
104
|
+
};
|
|
105
|
+
}>> & Readonly<{}>, {
|
|
55
106
|
customLabels: Record<string, string>;
|
|
56
107
|
customWrapperStyle: CSSProperties;
|
|
57
108
|
customButtonStyle: CSSProperties;
|
|
@@ -61,12 +112,35 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {}, {}, {}, {}, i
|
|
|
61
112
|
customActiveLinkStyle: CSSProperties;
|
|
62
113
|
customDisabledLinkStyle: CSSProperties;
|
|
63
114
|
customIconStyle: CSSProperties;
|
|
64
|
-
}, {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
115
|
+
}, SlotsType<{
|
|
116
|
+
/** Content before the button that opens the dropdown. */
|
|
117
|
+
'before-button': () => unknown;
|
|
118
|
+
/** Content before the active locale label inside the button. */
|
|
119
|
+
'before-selected-locale': () => unknown;
|
|
120
|
+
/** Content after the active locale label inside the button. */
|
|
121
|
+
'after-selected-locale': () => unknown;
|
|
122
|
+
/** Content between the button and the dropdown panel. */
|
|
123
|
+
'before-dropdown': () => unknown;
|
|
124
|
+
/** Content at the top of the dropdown, above the locale list. */
|
|
125
|
+
'before-dropdown-items': () => unknown;
|
|
126
|
+
/** Content before each locale entry. */
|
|
127
|
+
'before-item': (scope: {
|
|
128
|
+
locale: Locale;
|
|
129
|
+
}) => unknown;
|
|
130
|
+
/** Content before a locale's label inside its link. */
|
|
131
|
+
'before-link-content': (scope: {
|
|
132
|
+
locale: Locale;
|
|
133
|
+
}) => unknown;
|
|
134
|
+
/** Content after a locale's label inside its link. */
|
|
135
|
+
'after-link-content': (scope: {
|
|
136
|
+
locale: Locale;
|
|
137
|
+
}) => unknown;
|
|
138
|
+
/** Content after each locale entry. */
|
|
139
|
+
'after-item': (scope: {
|
|
140
|
+
locale: Locale;
|
|
141
|
+
}) => unknown;
|
|
142
|
+
/** Content at the bottom of the dropdown, below the locale list. */
|
|
143
|
+
'after-dropdown-items': () => unknown;
|
|
144
|
+
/** Content after the dropdown panel. */
|
|
145
|
+
'after-dropdown': () => unknown;
|
|
146
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { type I18nTRenderProps } from '@i18n-micro/core/render';
|
|
1
2
|
import type { PluralFunc } from '@i18n-micro/types';
|
|
2
|
-
import type {
|
|
3
|
+
import type { FunctionalComponent, PropType } from 'vue';
|
|
3
4
|
/**
|
|
4
5
|
* Renders one translation into an element, with pluralization, interpolation and
|
|
5
6
|
* number/date formatting handled for you.
|
|
@@ -8,121 +9,63 @@ import type { PropType, VNode } from 'vue';
|
|
|
8
9
|
* several are set the first of that list wins — the order the render function checks them.
|
|
9
10
|
*
|
|
10
11
|
* @slot default — receives `{ translation }`, for wrapping the resolved string in markup
|
|
11
|
-
* @slot {name} — any other named slot replaces
|
|
12
|
+
* @slot {name} — any other named slot replaces every `{name}` placeholder inside the translation
|
|
12
13
|
*/
|
|
13
14
|
declare const _default: typeof __VLS_export;
|
|
14
15
|
export default _default;
|
|
15
|
-
declare const __VLS_export:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
keypath: {
|
|
72
|
-
type: PropType<string>;
|
|
73
|
-
required: true;
|
|
74
|
-
};
|
|
75
|
-
/** Count selecting the plural form. Set it to use `$tc` instead of `$t`. */
|
|
76
|
-
plural: {
|
|
77
|
-
type: PropType<number | string>;
|
|
78
|
-
};
|
|
79
|
-
/** Element to render. */
|
|
80
|
-
tag: {
|
|
81
|
-
type: PropType<string>;
|
|
82
|
-
default: string;
|
|
83
|
-
};
|
|
84
|
-
/** Interpolation values substituted into the translation. */
|
|
85
|
-
params: {
|
|
86
|
-
type: PropType<Record<string, string | number | boolean>>;
|
|
87
|
-
default: () => {};
|
|
88
|
-
};
|
|
89
|
-
/** Rendered instead of the component when `hideIfEmpty` suppresses an empty translation. */
|
|
90
|
-
defaultValue: {
|
|
91
|
-
type: PropType<string>;
|
|
92
|
-
default: string;
|
|
93
|
-
};
|
|
94
|
-
/** Render the translation as HTML rather than text. Only for content you control. */
|
|
95
|
-
html: {
|
|
96
|
-
type: PropType<boolean>;
|
|
97
|
-
default: boolean;
|
|
98
|
-
};
|
|
99
|
-
/** Render nothing when the translation resolves to an empty string. */
|
|
100
|
-
hideIfEmpty: {
|
|
101
|
-
type: PropType<boolean>;
|
|
102
|
-
default: boolean;
|
|
103
|
-
};
|
|
104
|
-
/** Plural rule for this element only, overriding the configured one. */
|
|
105
|
-
customPluralRule: {
|
|
106
|
-
type: PropType<PluralFunc>;
|
|
107
|
-
default: null;
|
|
108
|
-
};
|
|
109
|
-
/** Formats the value with `$tn` and passes it to the translation as `{number}`. */
|
|
110
|
-
number: {
|
|
111
|
-
type: PropType<number | string>;
|
|
112
|
-
};
|
|
113
|
-
/** Formats the value with `$td` and passes it to the translation as `{date}`. */
|
|
114
|
-
date: {
|
|
115
|
-
type: PropType<Date | string | number>;
|
|
116
|
-
};
|
|
117
|
-
/** Formats the value with `$tdr` and passes it to the translation as `{relativeDate}`. */
|
|
118
|
-
relativeDate: {
|
|
119
|
-
type: PropType<Date | string | number>;
|
|
120
|
-
};
|
|
121
|
-
}>> & Readonly<{}>, {
|
|
122
|
-
params: Record<string, string | number | boolean>;
|
|
123
|
-
tag: string;
|
|
124
|
-
html: boolean;
|
|
125
|
-
defaultValue: string;
|
|
126
|
-
hideIfEmpty: boolean;
|
|
127
|
-
customPluralRule: PluralFunc;
|
|
128
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
16
|
+
declare const __VLS_export: FunctionalComponent<I18nTRenderProps, {}, any, {}> & {
|
|
17
|
+
displayName: string;
|
|
18
|
+
inheritAttrs: boolean;
|
|
19
|
+
props: {
|
|
20
|
+
/** Translation key to render. */
|
|
21
|
+
keypath: {
|
|
22
|
+
type: PropType<string>;
|
|
23
|
+
required: boolean;
|
|
24
|
+
};
|
|
25
|
+
/** Count selecting the plural form. Set it to use `$tc` instead of `$t`. `null` means unset. */
|
|
26
|
+
plural: {
|
|
27
|
+
type: PropType<number | string | null>;
|
|
28
|
+
};
|
|
29
|
+
/** Element to render. */
|
|
30
|
+
tag: {
|
|
31
|
+
type: PropType<string>;
|
|
32
|
+
default: string;
|
|
33
|
+
};
|
|
34
|
+
/** Interpolation values substituted into the translation. */
|
|
35
|
+
params: {
|
|
36
|
+
type: PropType<Record<string, string | number | boolean>>;
|
|
37
|
+
};
|
|
38
|
+
/** Rendered instead of the component when `hideIfEmpty` suppresses an empty translation. */
|
|
39
|
+
defaultValue: {
|
|
40
|
+
type: PropType<string>;
|
|
41
|
+
default: string;
|
|
42
|
+
};
|
|
43
|
+
/** Render the translation as HTML rather than text. Only for translations you control: `params` are escaped, the translation is not. */
|
|
44
|
+
html: {
|
|
45
|
+
type: PropType<boolean>;
|
|
46
|
+
default: boolean;
|
|
47
|
+
};
|
|
48
|
+
/** Render nothing when the translation resolves to an empty string. */
|
|
49
|
+
hideIfEmpty: {
|
|
50
|
+
type: PropType<boolean>;
|
|
51
|
+
default: boolean;
|
|
52
|
+
};
|
|
53
|
+
/** Plural rule for this element only, overriding the configured one. Its answer is used as is; `null` renders empty. */
|
|
54
|
+
customPluralRule: {
|
|
55
|
+
type: PropType<PluralFunc>;
|
|
56
|
+
default: null;
|
|
57
|
+
};
|
|
58
|
+
/** Formats the value with `$tn` and passes it to the translation as `{number}`, alongside `params`. */
|
|
59
|
+
number: {
|
|
60
|
+
type: PropType<number | string | null>;
|
|
61
|
+
};
|
|
62
|
+
/** Formats the value with `$td` and passes it to the translation as `{date}`, alongside `params`. */
|
|
63
|
+
date: {
|
|
64
|
+
type: PropType<Date | string | number | null>;
|
|
65
|
+
};
|
|
66
|
+
/** Formats the value with `$tdr` and passes it to the translation as `{relativeDate}`, alongside `params`. */
|
|
67
|
+
relativeDate: {
|
|
68
|
+
type: PropType<Date | string | number | null>;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { renderI18nT } from "@i18n-micro/core/render";
|
|
3
|
+
import { Fragment, h } from "vue";
|
|
4
|
+
import { useNuxtApp } from "#imports";
|
|
5
|
+
const renderApi = { h, Fragment };
|
|
6
|
+
const hosts = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
function hostOf(injections) {
|
|
8
|
+
const { $t, $tc, $tn, $td, $tdr, $has, $getLocale, $pluralFunc, $pluralLocale } = injections;
|
|
9
|
+
const host = { t: $t, tc: $tc, tn: $tn, td: $td, tdr: $tdr, has: $has, getLocale: $getLocale, pluralFunc: $pluralFunc, pluralLocale: $pluralLocale };
|
|
10
|
+
hosts.set($t, host);
|
|
11
|
+
return host;
|
|
12
|
+
}
|
|
13
|
+
const render = (props, { slots, attrs }) => {
|
|
14
|
+
const injections = useNuxtApp();
|
|
15
|
+
return renderI18nT(renderApi, hosts.get(injections.$t) ?? hostOf(injections), props, slots, attrs);
|
|
16
|
+
};
|
|
17
|
+
export default Object.assign(render, {
|
|
18
|
+
displayName: "I18nT",
|
|
6
19
|
inheritAttrs: false,
|
|
7
20
|
props: {
|
|
8
21
|
/** Translation key to render. */
|
|
@@ -10,7 +23,7 @@ export default defineComponent({
|
|
|
10
23
|
type: String,
|
|
11
24
|
required: true
|
|
12
25
|
},
|
|
13
|
-
/** Count selecting the plural form. Set it to use `$tc` instead of `$t`. */
|
|
26
|
+
/** Count selecting the plural form. Set it to use `$tc` instead of `$t`. `null` means unset. */
|
|
14
27
|
plural: {
|
|
15
28
|
type: [Number, String]
|
|
16
29
|
},
|
|
@@ -21,15 +34,14 @@ export default defineComponent({
|
|
|
21
34
|
},
|
|
22
35
|
/** Interpolation values substituted into the translation. */
|
|
23
36
|
params: {
|
|
24
|
-
type: Object
|
|
25
|
-
default: () => ({})
|
|
37
|
+
type: Object
|
|
26
38
|
},
|
|
27
39
|
/** Rendered instead of the component when `hideIfEmpty` suppresses an empty translation. */
|
|
28
40
|
defaultValue: {
|
|
29
41
|
type: String,
|
|
30
42
|
default: ""
|
|
31
43
|
},
|
|
32
|
-
/** Render the translation as HTML rather than text. Only for
|
|
44
|
+
/** Render the translation as HTML rather than text. Only for translations you control: `params` are escaped, the translation is not. */
|
|
33
45
|
html: {
|
|
34
46
|
type: Boolean,
|
|
35
47
|
default: false
|
|
@@ -39,82 +51,23 @@ export default defineComponent({
|
|
|
39
51
|
type: Boolean,
|
|
40
52
|
default: false
|
|
41
53
|
},
|
|
42
|
-
/** Plural rule for this element only, overriding the configured one. */
|
|
54
|
+
/** Plural rule for this element only, overriding the configured one. Its answer is used as is; `null` renders empty. */
|
|
43
55
|
customPluralRule: {
|
|
44
56
|
type: Function,
|
|
45
57
|
default: null
|
|
46
58
|
},
|
|
47
|
-
/** Formats the value with `$tn` and passes it to the translation as `{number}`. */
|
|
59
|
+
/** Formats the value with `$tn` and passes it to the translation as `{number}`, alongside `params`. */
|
|
48
60
|
number: {
|
|
49
61
|
type: [Number, String]
|
|
50
62
|
},
|
|
51
|
-
/** Formats the value with `$td` and passes it to the translation as `{date}`. */
|
|
63
|
+
/** Formats the value with `$td` and passes it to the translation as `{date}`, alongside `params`. */
|
|
52
64
|
date: {
|
|
53
65
|
type: [Date, String, Number]
|
|
54
66
|
},
|
|
55
|
-
/** Formats the value with `$tdr` and passes it to the translation as `{relativeDate}`. */
|
|
67
|
+
/** Formats the value with `$tdr` and passes it to the translation as `{relativeDate}`, alongside `params`. */
|
|
56
68
|
relativeDate: {
|
|
57
69
|
type: [Date, String, Number]
|
|
58
70
|
}
|
|
59
|
-
},
|
|
60
|
-
setup(props, { slots, attrs }) {
|
|
61
|
-
return () => {
|
|
62
|
-
const options = {};
|
|
63
|
-
const { $getLocale, $_t, $tc, $tn, $td, $tdr } = useNuxtApp();
|
|
64
|
-
const route = useRoute();
|
|
65
|
-
const $t = $_t(route);
|
|
66
|
-
const safeAttrs = { ...attrs };
|
|
67
|
-
delete safeAttrs.innerHTML;
|
|
68
|
-
const renderText = (translation2) => props.html ? hyperscript(props.tag, { ...safeAttrs, innerHTML: translation2 }) : hyperscript(props.tag, safeAttrs, translation2);
|
|
69
|
-
if (props.number !== void 0) {
|
|
70
|
-
const numberValue = Number(props.number);
|
|
71
|
-
return renderText(String($t(props.keypath, { number: $tn(numberValue) }) ?? ""));
|
|
72
|
-
}
|
|
73
|
-
if (props.date !== void 0) {
|
|
74
|
-
return renderText(String($t(props.keypath, { date: $td(props.date) }) ?? ""));
|
|
75
|
-
}
|
|
76
|
-
if (props.relativeDate !== void 0) {
|
|
77
|
-
return renderText(String($t(props.keypath, { relativeDate: $tdr(props.relativeDate) }) ?? ""));
|
|
78
|
-
}
|
|
79
|
-
if (props.plural !== void 0) {
|
|
80
|
-
const count = Number.parseInt(props.plural.toString(), 10);
|
|
81
|
-
if (props.customPluralRule) {
|
|
82
|
-
return renderText(String(props.customPluralRule(props.keypath, count, props.params, $getLocale(), $t) ?? ""));
|
|
83
|
-
} else {
|
|
84
|
-
return renderText($tc(props.keypath, { count, ...props.params }));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const translation = ($t(props.keypath, { ...props.params, ...options }) ?? "").toString();
|
|
88
|
-
if (props.hideIfEmpty && !translation.trim()) {
|
|
89
|
-
return props.defaultValue ?? null;
|
|
90
|
-
}
|
|
91
|
-
if (props.html) {
|
|
92
|
-
return renderText(translation);
|
|
93
|
-
}
|
|
94
|
-
if (slots.default) {
|
|
95
|
-
return hyperscript(props.tag, safeAttrs, slots.default({ translation }));
|
|
96
|
-
}
|
|
97
|
-
const children = [];
|
|
98
|
-
let lastIndex = 0;
|
|
99
|
-
const placements = Object.entries(slots).map(([slotName, slotFn]) => {
|
|
100
|
-
const placeholder = `{${slotName}}`;
|
|
101
|
-
return { placeholder, slotFn, index: translation.indexOf(placeholder) };
|
|
102
|
-
}).filter(({ index }) => index !== -1).sort((a, b) => a.index - b.index);
|
|
103
|
-
for (const { placeholder, slotFn, index } of placements) {
|
|
104
|
-
if (index > lastIndex) {
|
|
105
|
-
children.push(translation.slice(lastIndex, index));
|
|
106
|
-
}
|
|
107
|
-
children.push(hyperscript(slotFn));
|
|
108
|
-
lastIndex = index + placeholder.length;
|
|
109
|
-
}
|
|
110
|
-
if (lastIndex < translation.length) {
|
|
111
|
-
children.push(translation.slice(lastIndex));
|
|
112
|
-
}
|
|
113
|
-
if (slots.default) {
|
|
114
|
-
return hyperscript(props.tag, safeAttrs, slots.default({ children }));
|
|
115
|
-
}
|
|
116
|
-
return hyperscript(props.tag, safeAttrs, children);
|
|
117
|
-
};
|
|
118
71
|
}
|
|
119
72
|
});
|
|
120
73
|
</script>
|