@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 +21 -0
- package/README.md +69 -0
- package/dist/components/i18n-group.d.ts +24 -0
- package/dist/components/i18n-link.d.ts +25 -0
- package/dist/components/i18n-switcher.d.ts +88 -0
- package/dist/components/i18n-t.d.ts +94 -0
- package/dist/composables/use-locale-head.d.ts +62 -0
- package/dist/composer.d.ts +47 -0
- package/dist/devtools/bridge/vue-bridge.d.ts +14 -0
- package/dist/devtools/index.d.ts +9 -0
- package/dist/index.cjs +68 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.mjs +12503 -0
- package/dist/injection.d.ts +6 -0
- package/dist/plugin.d.ts +5 -0
- package/dist/router.d.ts +27 -0
- package/dist/use-i18n.d.ts +35 -0
- package/dist/vue-shim.d.ts +17 -0
- package/package.json +47 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InjectionKey } from 'vue';
|
|
2
|
+
import { VueI18n } from './composer';
|
|
3
|
+
import { Locale } from '@i18n-micro/types';
|
|
4
|
+
export declare const I18nInjectionKey: InjectionKey<VueI18n>;
|
|
5
|
+
export declare const I18nLocalesKey: InjectionKey<Locale[]>;
|
|
6
|
+
export declare const I18nDefaultLocaleKey: InjectionKey<string>;
|
package/dist/plugin.d.ts
ADDED
package/dist/router.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useRoute, RouteLocationRaw } from 'vue-router';
|
|
2
|
+
import { Params, CleanTranslation, Locale, TranslationKey } from '@i18n-micro/types';
|
|
3
|
+
export interface UseI18nOptions {
|
|
4
|
+
locales?: Locale[];
|
|
5
|
+
defaultLocale?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function useI18n(options?: UseI18nOptions): {
|
|
8
|
+
locale: import('vue').WritableComputedRef<string, string>;
|
|
9
|
+
fallbackLocale: import('vue').WritableComputedRef<string, string>;
|
|
10
|
+
currentRoute: import('vue').WritableComputedRef<string, string>;
|
|
11
|
+
t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
|
|
12
|
+
ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
|
|
13
|
+
tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
14
|
+
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
15
|
+
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
16
|
+
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
17
|
+
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
18
|
+
setRoute: (routeName: string) => void;
|
|
19
|
+
getRoute: () => string;
|
|
20
|
+
getRouteName: (r?: ReturnType<typeof useRoute>) => string;
|
|
21
|
+
getLocale: (r?: ReturnType<typeof useRoute>) => string;
|
|
22
|
+
getLocales: () => Locale[];
|
|
23
|
+
defaultLocale: () => string;
|
|
24
|
+
getLocaleName: () => string | null;
|
|
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;
|
|
34
|
+
clearCache: () => void;
|
|
35
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Params, CleanTranslation, TranslationKey } from '@i18n-micro/types';
|
|
2
|
+
// Расширяем модуль '@vue/runtime-core', чтобы типы работали корректно во всех средах
|
|
3
|
+
declare module '@vue/runtime-core' {
|
|
4
|
+
interface ComponentCustomProperties {
|
|
5
|
+
$t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation
|
|
6
|
+
$ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string
|
|
7
|
+
$tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string
|
|
8
|
+
$tn: (value: number, options?: Intl.NumberFormatOptions) => string
|
|
9
|
+
$td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string
|
|
10
|
+
$tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string
|
|
11
|
+
$has: (key: TranslationKey, routeName?: string) => boolean
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
$i18n: any
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@i18n-micro/vue",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@i18n-micro/core": "1.0.27",
|
|
23
|
+
"@i18n-micro/types": "1.0.15",
|
|
24
|
+
"@i18n-micro/devtools-ui": "1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"vue": "^3.3.0",
|
|
28
|
+
"vue-router": "^4.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"vue": "^3.3.0",
|
|
32
|
+
"vue-router": "^4.0.0",
|
|
33
|
+
"vite": "^5.0.0",
|
|
34
|
+
"vite-plugin-dts": "^4.3.0",
|
|
35
|
+
"jest": "^29.7.0",
|
|
36
|
+
"ts-jest": "^29.1.2",
|
|
37
|
+
"@types/jest": "^29.5.0",
|
|
38
|
+
"@vue/test-utils": "^2.4.0",
|
|
39
|
+
"jest-environment-jsdom": "^29.7.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "vite build",
|
|
43
|
+
"dev": "cd playground && vite",
|
|
44
|
+
"test": "jest",
|
|
45
|
+
"typecheck": "tsc --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|