@i18n-micro/vue 1.0.0 → 1.1.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/components/i18n-group.d.ts +6 -24
- package/dist/components/i18n-link.d.ts +29 -5
- package/dist/components/i18n-switcher.d.ts +58 -0
- package/dist/components/i18n-t.d.ts +1 -1
- package/dist/composer.d.ts +5 -15
- package/dist/index.cjs +1 -68
- package/dist/index.d.ts +4 -6
- package/dist/index.mjs +433 -12257
- package/dist/injection.d.ts +2 -0
- package/dist/plugin.d.ts +18 -1
- package/dist/router/adapter.d.ts +9 -0
- package/dist/router/types.d.ts +43 -0
- package/dist/use-i18n.d.ts +28 -22
- package/package.json +16 -11
- package/dist/devtools/bridge/vue-bridge.d.ts +0 -14
- package/dist/devtools/index.d.ts +0 -9
- package/dist/router.d.ts +0 -27
package/dist/injection.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { InjectionKey } from 'vue';
|
|
2
2
|
import { VueI18n } from './composer';
|
|
3
3
|
import { Locale } from '@i18n-micro/types';
|
|
4
|
+
import { I18nRoutingStrategy } from './router/types';
|
|
4
5
|
export declare const I18nInjectionKey: InjectionKey<VueI18n>;
|
|
5
6
|
export declare const I18nLocalesKey: InjectionKey<Locale[]>;
|
|
6
7
|
export declare const I18nDefaultLocaleKey: InjectionKey<string>;
|
|
8
|
+
export declare const I18nRouterKey: InjectionKey<I18nRoutingStrategy>;
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { Plugin } from 'vue';
|
|
2
2
|
import { VueI18n, VueI18nOptions } from './composer';
|
|
3
|
-
|
|
3
|
+
import { Locale } from '@i18n-micro/types';
|
|
4
|
+
import { I18nRoutingStrategy } from './router/types';
|
|
5
|
+
export interface CreateI18nOptions extends VueI18nOptions {
|
|
6
|
+
routingStrategy?: I18nRoutingStrategy;
|
|
7
|
+
/**
|
|
8
|
+
* Array of locale configurations
|
|
9
|
+
* If provided, will be automatically provided to the app via I18nLocalesKey
|
|
10
|
+
*/
|
|
11
|
+
locales?: Locale[];
|
|
12
|
+
/**
|
|
13
|
+
* Default locale code
|
|
14
|
+
* If provided, will be automatically provided to the app via I18nDefaultLocaleKey
|
|
15
|
+
*/
|
|
16
|
+
defaultLocale?: string;
|
|
17
|
+
}
|
|
18
|
+
export type I18nPlugin = Plugin & {
|
|
4
19
|
global: VueI18n;
|
|
20
|
+
setRoutingStrategy: (strategy: I18nRoutingStrategy) => void;
|
|
5
21
|
};
|
|
22
|
+
export declare function createI18n(options: CreateI18nOptions): I18nPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Router } from 'vue-router';
|
|
2
|
+
import { I18nRoutingStrategy } from './types';
|
|
3
|
+
import { Locale } from '@i18n-micro/types';
|
|
4
|
+
/**
|
|
5
|
+
* Factory for Vue Router adapter
|
|
6
|
+
* Implements routing utilities for Vue Router
|
|
7
|
+
* Uses vue-router APIs for navigation and path resolution
|
|
8
|
+
*/
|
|
9
|
+
export declare function createVueRouterAdapter(router: Router, locales: Locale[], defaultLocale: string): I18nRoutingStrategy;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Component } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Routing strategy interface for i18n
|
|
4
|
+
* Implement this interface to integrate with any router library
|
|
5
|
+
*/
|
|
6
|
+
export interface I18nRoutingStrategy {
|
|
7
|
+
/**
|
|
8
|
+
* Returns current path (without locale prefix if needed, or full path)
|
|
9
|
+
* Used for determining active classes in links
|
|
10
|
+
*/
|
|
11
|
+
getCurrentPath: () => string;
|
|
12
|
+
/**
|
|
13
|
+
* Component to use for rendering links (e.g., RouterLink)
|
|
14
|
+
*/
|
|
15
|
+
linkComponent?: string | Component;
|
|
16
|
+
/**
|
|
17
|
+
* Function to navigate to another route/locale
|
|
18
|
+
*/
|
|
19
|
+
push: (target: {
|
|
20
|
+
path: string;
|
|
21
|
+
}) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Function to replace current route
|
|
24
|
+
*/
|
|
25
|
+
replace: (target: {
|
|
26
|
+
path: string;
|
|
27
|
+
}) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Generate path for specific locale
|
|
30
|
+
*/
|
|
31
|
+
resolvePath?: (to: string | {
|
|
32
|
+
path?: string;
|
|
33
|
+
}, locale: string) => string | {
|
|
34
|
+
path?: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* (Optional) Get current route object for SEO/Meta tags
|
|
38
|
+
*/
|
|
39
|
+
getRoute?: () => {
|
|
40
|
+
fullPath: string;
|
|
41
|
+
query: Record<string, unknown>;
|
|
42
|
+
};
|
|
43
|
+
}
|
package/dist/use-i18n.d.ts
CHANGED
|
@@ -1,35 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { VueI18n } from './composer';
|
|
2
|
+
import { Locale } from '@i18n-micro/types';
|
|
3
3
|
export interface UseI18nOptions {
|
|
4
4
|
locales?: Locale[];
|
|
5
5
|
defaultLocale?: string;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Get the i18n instance from the Vue app context
|
|
9
|
+
* Returns the same instance that was created with createI18n()
|
|
10
|
+
*/
|
|
7
11
|
export declare function useI18n(options?: UseI18nOptions): {
|
|
12
|
+
instance: VueI18n;
|
|
8
13
|
locale: import('vue').WritableComputedRef<string, string>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
getLocales: () => Locale[];
|
|
15
|
+
defaultLocale: () => string;
|
|
16
|
+
getLocaleName: () => string | null;
|
|
17
|
+
localeRoute: (to: string | {
|
|
18
|
+
path?: string;
|
|
19
|
+
}, localeCode?: string) => string | {
|
|
20
|
+
path?: string;
|
|
21
|
+
};
|
|
22
|
+
localePath: (to: string | {
|
|
23
|
+
path?: string;
|
|
24
|
+
}, locale?: string) => string;
|
|
25
|
+
switchLocale: (newLocale: string) => void;
|
|
26
|
+
t: (key: import('@i18n-micro/types').TranslationKey, params?: import('@i18n-micro/types').Params, defaultValue?: string | null, routeName?: string) => import('@i18n-micro/types').CleanTranslation;
|
|
27
|
+
ts: (key: import('@i18n-micro/types').TranslationKey, params?: import('@i18n-micro/types').Params, defaultValue?: string, routeName?: string) => string;
|
|
28
|
+
tc: (key: import('@i18n-micro/types').TranslationKey, count: number | import('@i18n-micro/types').Params, defaultValue?: string) => string;
|
|
14
29
|
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
15
30
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
16
31
|
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
17
|
-
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
32
|
+
has: (key: import('@i18n-micro/types').TranslationKey, routeName?: string) => boolean;
|
|
18
33
|
setRoute: (routeName: string) => void;
|
|
19
34
|
getRoute: () => string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
switchLocaleRoute: ((locale: string) => RouteLocationRaw) | undefined;
|
|
26
|
-
switchLocalePath: ((locale: string) => string) | undefined;
|
|
27
|
-
switchLocale: ((locale: string) => void) | undefined;
|
|
28
|
-
localeRoute: ((to: RouteLocationRaw | string, locale?: string) => RouteLocationRaw | string) | undefined;
|
|
29
|
-
localePath: ((to: RouteLocationRaw | string, locale?: string) => string) | undefined;
|
|
30
|
-
addTranslations: (locale: string, translations: Record<string, unknown>, merge?: boolean) => void;
|
|
31
|
-
addRouteTranslations: (locale: string, routeName: string, translations: Record<string, unknown>, merge?: boolean) => void;
|
|
32
|
-
mergeTranslations: (locale: string, routeName: string, translations: Record<string, unknown>) => void;
|
|
33
|
-
mergeGlobalTranslations: (locale: string, translations: Record<string, unknown>) => void;
|
|
35
|
+
getLocale: () => string;
|
|
36
|
+
addTranslations: (locale: string, translations: import('@i18n-micro/types').Translations, merge?: boolean) => void;
|
|
37
|
+
addRouteTranslations: (locale: string, routeName: string, translations: import('@i18n-micro/types').Translations, merge?: boolean) => void;
|
|
38
|
+
mergeTranslations: (locale: string, routeName: string, translations: import('@i18n-micro/types').Translations) => void;
|
|
39
|
+
mergeGlobalTranslations: (locale: string, translations: import('@i18n-micro/types').Translations) => void;
|
|
34
40
|
clearCache: () => void;
|
|
35
41
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -19,28 +19,33 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@i18n-micro/
|
|
23
|
-
"@i18n-micro/
|
|
24
|
-
"@i18n-micro/devtools-ui": "1.0.0"
|
|
22
|
+
"@i18n-micro/types": "1.0.16",
|
|
23
|
+
"@i18n-micro/core": "1.0.28"
|
|
25
24
|
},
|
|
26
25
|
"peerDependencies": {
|
|
27
26
|
"vue": "^3.3.0",
|
|
28
27
|
"vue-router": "^4.0.0"
|
|
29
28
|
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"vue-router": {
|
|
31
|
+
"optional": true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
30
34
|
"devDependencies": {
|
|
31
|
-
"vue": "^3.
|
|
32
|
-
"vue-router": "^4.
|
|
33
|
-
"vite": "^
|
|
34
|
-
"vite-plugin-dts": "^4.
|
|
35
|
+
"vue": "^3.5.25",
|
|
36
|
+
"vue-router": "^4.6.3",
|
|
37
|
+
"vite": "^7.2.7",
|
|
38
|
+
"vite-plugin-dts": "^4.5.4",
|
|
35
39
|
"jest": "^29.7.0",
|
|
36
|
-
"ts-jest": "^29.
|
|
37
|
-
"@types/jest": "^29.5.
|
|
38
|
-
"@vue/test-utils": "^2.4.
|
|
40
|
+
"ts-jest": "^29.4.6",
|
|
41
|
+
"@types/jest": "^29.5.14",
|
|
42
|
+
"@vue/test-utils": "^2.4.6",
|
|
39
43
|
"jest-environment-jsdom": "^29.7.0"
|
|
40
44
|
},
|
|
41
45
|
"scripts": {
|
|
42
46
|
"build": "vite build",
|
|
43
47
|
"dev": "cd playground && vite",
|
|
48
|
+
"dev:ssr": "cd playground && node server.js",
|
|
44
49
|
"test": "jest",
|
|
45
50
|
"typecheck": "tsc --noEmit"
|
|
46
51
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
package/dist/devtools/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
package/dist/router.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Router, RouteLocationNormalizedLoaded } from 'vue-router';
|
|
2
|
-
import { VueI18n } from './composer';
|
|
3
|
-
export interface RouterIntegrationOptions {
|
|
4
|
-
router: Router;
|
|
5
|
-
i18n: VueI18n;
|
|
6
|
-
defaultLocale?: string;
|
|
7
|
-
locales?: string[];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Get route name from Vue Router route
|
|
11
|
-
* Extracts route name from route.name or route.path
|
|
12
|
-
*/
|
|
13
|
-
export declare function getRouteName(route: RouteLocationNormalizedLoaded): string;
|
|
14
|
-
/**
|
|
15
|
-
* Get locale from route
|
|
16
|
-
* Checks route.params.locale or extracts from path
|
|
17
|
-
*/
|
|
18
|
-
export declare function getLocaleFromRoute(route: RouteLocationNormalizedLoaded, defaultLocale?: string, locales?: string[]): string;
|
|
19
|
-
/**
|
|
20
|
-
* Setup router integration for i18n
|
|
21
|
-
* Automatically updates route and locale when router changes, AND updates URL when locale changes.
|
|
22
|
-
*/
|
|
23
|
-
export declare function setupRouterIntegration(options: RouterIntegrationOptions): () => void;
|
|
24
|
-
/**
|
|
25
|
-
* Switch locale and navigate to localized route
|
|
26
|
-
*/
|
|
27
|
-
export declare function switchLocaleRoute(router: Router, i18n: VueI18n, newLocale: string, locales?: string[]): void;
|