@i18n-micro/vue 1.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 ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @i18n-micro/vue
2
+
3
+ Vue 3 plugin for internationalization using the same core logic as Nuxt I18n Micro. Provides reactive translations, route-specific support, and full TypeScript support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @i18n-micro/vue
9
+ # or
10
+ npm install @i18n-micro/vue
11
+ # or
12
+ yarn add @i18n-micro/vue
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { createApp } from 'vue'
19
+ import { createI18n } from '@i18n-micro/vue'
20
+
21
+ const app = createApp(App)
22
+
23
+ const i18n = createI18n({
24
+ locale: 'en',
25
+ fallbackLocale: 'en',
26
+ messages: {
27
+ en: {
28
+ greeting: 'Hello, {name}!',
29
+ apples: 'no apples | one apple | {count} apples',
30
+ },
31
+ fr: {
32
+ greeting: 'Bonjour, {name}!',
33
+ apples: 'pas de pommes | une pomme | {count} pommes',
34
+ },
35
+ },
36
+ })
37
+
38
+ app.use(i18n)
39
+ app.mount('#app')
40
+ ```
41
+
42
+ ### Usage in Components
43
+
44
+ ```vue
45
+ <template>
46
+ <div>
47
+ <p>{{ t('greeting', { name: 'World' }) }}</p>
48
+ <p>{{ tc('apples', 5) }}</p>
49
+ </div>
50
+ </template>
51
+
52
+ <script setup>
53
+ import { useI18n } from '@i18n-micro/vue'
54
+
55
+ const { t, tc, locale } = useI18n()
56
+
57
+ // Change locale reactively
58
+ locale.value = 'fr'
59
+ </script>
60
+ ```
61
+
62
+ ## Resources
63
+
64
+ - **Repository**: [https://github.com/s00d/nuxt-i18n-micro](https://github.com/s00d/nuxt-i18n-micro)
65
+ - **Documentation**: [https://s00d.github.io/nuxt-i18n-micro/](https://s00d.github.io/nuxt-i18n-micro/)
66
+
67
+ ## License
68
+
69
+ MIT
@@ -0,0 +1,24 @@
1
+ import { PropType } from 'vue';
2
+ export declare const I18nGroup: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
3
+ prefix: {
4
+ type: PropType<string>;
5
+ required: true;
6
+ };
7
+ groupClass: {
8
+ type: PropType<string>;
9
+ default: string;
10
+ };
11
+ }>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
12
+ [key: string]: any;
13
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
14
+ prefix: {
15
+ type: PropType<string>;
16
+ required: true;
17
+ };
18
+ groupClass: {
19
+ type: PropType<string>;
20
+ default: string;
21
+ };
22
+ }>> & Readonly<{}>, {
23
+ groupClass: string;
24
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,25 @@
1
+ import { PropType, CSSProperties, DefineComponent } from 'vue';
2
+ import { RouteLocationRaw, RouteLocationNormalizedLoaded } from 'vue-router';
3
+ export declare const I18nLink: DefineComponent<import('vue').ExtractPropTypes<{
4
+ to: {
5
+ type: PropType<RouteLocationRaw | RouteLocationNormalizedLoaded | string>;
6
+ required: true;
7
+ };
8
+ activeStyle: {
9
+ type: PropType<CSSProperties>;
10
+ default: () => {};
11
+ };
12
+ }>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
13
+ [key: string]: any;
14
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
15
+ to: {
16
+ type: PropType<RouteLocationRaw | RouteLocationNormalizedLoaded | string>;
17
+ required: true;
18
+ };
19
+ activeStyle: {
20
+ type: PropType<CSSProperties>;
21
+ default: () => {};
22
+ };
23
+ }>> & Readonly<{}>, {
24
+ activeStyle: CSSProperties;
25
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,88 @@
1
+ import { PropType, CSSProperties, VNode } from 'vue';
2
+ export declare const I18nSwitcher: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
3
+ customLabels: {
4
+ type: PropType<Record<string, string>>;
5
+ default: () => {};
6
+ };
7
+ customWrapperStyle: {
8
+ type: PropType<CSSProperties>;
9
+ default: () => {};
10
+ };
11
+ customButtonStyle: {
12
+ type: PropType<CSSProperties>;
13
+ default: () => {};
14
+ };
15
+ customDropdownStyle: {
16
+ type: PropType<CSSProperties>;
17
+ default: () => {};
18
+ };
19
+ customItemStyle: {
20
+ type: PropType<CSSProperties>;
21
+ default: () => {};
22
+ };
23
+ customLinkStyle: {
24
+ type: PropType<CSSProperties>;
25
+ default: () => {};
26
+ };
27
+ customActiveLinkStyle: {
28
+ type: PropType<CSSProperties>;
29
+ default: () => {};
30
+ };
31
+ customDisabledLinkStyle: {
32
+ type: PropType<CSSProperties>;
33
+ default: () => {};
34
+ };
35
+ customIconStyle: {
36
+ type: PropType<CSSProperties>;
37
+ default: () => {};
38
+ };
39
+ }>, () => VNode<import('vue').RendererNode, import('vue').RendererElement, {
40
+ [key: string]: any;
41
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
42
+ customLabels: {
43
+ type: PropType<Record<string, string>>;
44
+ default: () => {};
45
+ };
46
+ customWrapperStyle: {
47
+ type: PropType<CSSProperties>;
48
+ default: () => {};
49
+ };
50
+ customButtonStyle: {
51
+ type: PropType<CSSProperties>;
52
+ default: () => {};
53
+ };
54
+ customDropdownStyle: {
55
+ type: PropType<CSSProperties>;
56
+ default: () => {};
57
+ };
58
+ customItemStyle: {
59
+ type: PropType<CSSProperties>;
60
+ default: () => {};
61
+ };
62
+ customLinkStyle: {
63
+ type: PropType<CSSProperties>;
64
+ default: () => {};
65
+ };
66
+ customActiveLinkStyle: {
67
+ type: PropType<CSSProperties>;
68
+ default: () => {};
69
+ };
70
+ customDisabledLinkStyle: {
71
+ type: PropType<CSSProperties>;
72
+ default: () => {};
73
+ };
74
+ customIconStyle: {
75
+ type: PropType<CSSProperties>;
76
+ default: () => {};
77
+ };
78
+ }>> & Readonly<{}>, {
79
+ customLabels: Record<string, string>;
80
+ customWrapperStyle: CSSProperties;
81
+ customButtonStyle: CSSProperties;
82
+ customDropdownStyle: CSSProperties;
83
+ customItemStyle: CSSProperties;
84
+ customLinkStyle: CSSProperties;
85
+ customActiveLinkStyle: CSSProperties;
86
+ customDisabledLinkStyle: CSSProperties;
87
+ customIconStyle: CSSProperties;
88
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,94 @@
1
+ import { PropType, VNode } from 'vue';
2
+ import { PluralFunc, TranslationKey } from '@i18n-micro/types';
3
+ export declare const I18nT: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
4
+ keypath: {
5
+ type: PropType<TranslationKey>;
6
+ required: true;
7
+ };
8
+ plural: {
9
+ type: PropType<number | string>;
10
+ };
11
+ tag: {
12
+ type: PropType<string>;
13
+ default: string;
14
+ };
15
+ params: {
16
+ type: PropType<Record<string, string | number | boolean>>;
17
+ default: () => {};
18
+ };
19
+ defaultValue: {
20
+ type: PropType<string>;
21
+ default: string;
22
+ };
23
+ html: {
24
+ type: PropType<boolean>;
25
+ default: boolean;
26
+ };
27
+ hideIfEmpty: {
28
+ type: PropType<boolean>;
29
+ default: boolean;
30
+ };
31
+ customPluralRule: {
32
+ type: PropType<PluralFunc>;
33
+ default: null;
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
+ };
44
+ }>, () => string | VNode<import('vue').RendererNode, import('vue').RendererElement, {
45
+ [key: string]: any;
46
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
47
+ keypath: {
48
+ type: PropType<TranslationKey>;
49
+ required: true;
50
+ };
51
+ plural: {
52
+ type: PropType<number | string>;
53
+ };
54
+ tag: {
55
+ type: PropType<string>;
56
+ default: string;
57
+ };
58
+ params: {
59
+ type: PropType<Record<string, string | number | boolean>>;
60
+ default: () => {};
61
+ };
62
+ defaultValue: {
63
+ type: PropType<string>;
64
+ default: string;
65
+ };
66
+ html: {
67
+ type: PropType<boolean>;
68
+ default: boolean;
69
+ };
70
+ hideIfEmpty: {
71
+ type: PropType<boolean>;
72
+ default: boolean;
73
+ };
74
+ customPluralRule: {
75
+ type: PropType<PluralFunc>;
76
+ default: null;
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
+ };
87
+ }>> & Readonly<{}>, {
88
+ params: Record<string, string | number | boolean>;
89
+ tag: string;
90
+ defaultValue: string;
91
+ html: boolean;
92
+ hideIfEmpty: boolean;
93
+ customPluralRule: PluralFunc;
94
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,62 @@
1
+ interface MetaLink {
2
+ [key: string]: string | undefined;
3
+ rel: string;
4
+ href: string;
5
+ hreflang?: string;
6
+ }
7
+ interface MetaTag {
8
+ [key: string]: string;
9
+ property: string;
10
+ content: string;
11
+ }
12
+ interface MetaObject {
13
+ htmlAttrs: {
14
+ lang?: string;
15
+ dir?: 'ltr' | 'rtl' | 'auto';
16
+ };
17
+ link: MetaLink[];
18
+ meta: MetaTag[];
19
+ }
20
+ export interface UseLocaleHeadOptions {
21
+ addDirAttribute?: boolean;
22
+ identifierAttribute?: string;
23
+ addSeoAttributes?: boolean;
24
+ baseUrl?: string | (() => string);
25
+ }
26
+ export declare function useLocaleHead(options?: UseLocaleHeadOptions): {
27
+ metaObject: import('vue').Ref<{
28
+ htmlAttrs: {
29
+ lang?: string | undefined;
30
+ dir?: "ltr" | "rtl" | "auto" | undefined;
31
+ };
32
+ link: {
33
+ [x: string]: string | undefined;
34
+ rel: string;
35
+ href: string;
36
+ hreflang?: string | undefined;
37
+ }[];
38
+ meta: {
39
+ [x: string]: string;
40
+ property: string;
41
+ content: string;
42
+ }[];
43
+ }, MetaObject | {
44
+ htmlAttrs: {
45
+ lang?: string | undefined;
46
+ dir?: "ltr" | "rtl" | "auto" | undefined;
47
+ };
48
+ link: {
49
+ [x: string]: string | undefined;
50
+ rel: string;
51
+ href: string;
52
+ hreflang?: string | undefined;
53
+ }[];
54
+ meta: {
55
+ [x: string]: string;
56
+ property: string;
57
+ content: string;
58
+ }[];
59
+ }>;
60
+ updateMeta: (canonicalQueryWhitelist?: string[]) => void;
61
+ };
62
+ export {};
@@ -0,0 +1,47 @@
1
+ import { Ref } from 'vue';
2
+ import { TranslationCache } from '@i18n-micro/core';
3
+ import { Translations, Params, PluralFunc, CleanTranslation, TranslationKey } from '@i18n-micro/types';
4
+ export interface VueI18nOptions {
5
+ locale: string;
6
+ fallbackLocale?: string;
7
+ messages?: Record<string, Translations>;
8
+ plural?: PluralFunc;
9
+ missingWarn?: boolean;
10
+ missingHandler?: (locale: string, key: string, routeName: string) => void;
11
+ }
12
+ export declare class VueI18n {
13
+ private _locale;
14
+ private _fallbackLocale;
15
+ private _currentRoute;
16
+ private helper;
17
+ private formatter;
18
+ private pluralFunc;
19
+ private missingWarn;
20
+ private missingHandler?;
21
+ readonly cache: TranslationCache;
22
+ private listeners;
23
+ constructor(options: VueI18nOptions);
24
+ get locale(): Ref<string>;
25
+ set locale(val: Ref<string> | string);
26
+ get fallbackLocale(): Ref<string>;
27
+ set fallbackLocale(val: Ref<string> | string);
28
+ get currentRoute(): Ref<string>;
29
+ setRoute(routeName: string): void;
30
+ getRoute(): string;
31
+ t(key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string): CleanTranslation;
32
+ ts(key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string): string;
33
+ tc(key: TranslationKey, count: number | Params, defaultValue?: string): string;
34
+ tn(value: number, options?: Intl.NumberFormatOptions): string;
35
+ td(value: Date | number | string, options?: Intl.DateTimeFormatOptions): string;
36
+ tdr(value: Date | number | string, options?: Intl.RelativeTimeFormatOptions): string;
37
+ has(key: TranslationKey, _routeName?: string): boolean;
38
+ addTranslations(locale: string, translations: Translations, merge?: boolean): void;
39
+ addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
40
+ mergeTranslations(locale: string, routeName: string, translations: Translations): void;
41
+ mergeGlobalTranslations(locale: string, translations: Translations): void;
42
+ clearCache(): void;
43
+ subscribeToChanges(cb: () => void): () => void;
44
+ private notifyListeners;
45
+ getAllTranslations(): Record<string, Translations>;
46
+ getCache(): TranslationCache;
47
+ }
@@ -0,0 +1,14 @@
1
+ import { I18nDevToolsBridge } from '@i18n-micro/devtools-ui';
2
+ import { Locale } from '@i18n-micro/types';
3
+ import { VueI18n } from '../../composer';
4
+ export interface VueBridgeOptions {
5
+ i18n: VueI18n;
6
+ locales?: Locale[];
7
+ defaultLocale?: string;
8
+ translationDir?: string;
9
+ }
10
+ /**
11
+ * Create a Vue bridge that adapts VueI18n API to I18nDevToolsBridge interface
12
+ * Creates a virtual file system structure: locales/{lang}.json and locales/pages/{route}/{lang}.json
13
+ */
14
+ export declare function createVueBridge(options: VueBridgeOptions): I18nDevToolsBridge;
@@ -0,0 +1,9 @@
1
+ import { VueI18n } from '../composer';
2
+ import { Locale } from '@i18n-micro/types';
3
+ export interface VueDevToolsOptions {
4
+ i18n: VueI18n;
5
+ locales?: Locale[];
6
+ defaultLocale?: string;
7
+ translationDir?: string;
8
+ }
9
+ export declare function setupVueDevTools(options: VueDevToolsOptions): void;