@feugene/fint-i18n 0.2.3 → 0.3.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/dist/chunks/core-UYOFg8gl.js +384 -0
- package/dist/chunks/loader-registry-B_fUe8pM.js +103 -0
- package/dist/core.js +1 -1
- package/dist/index.js +4 -4
- package/dist/plugins.js +43 -24
- package/dist/types/core/compiler.d.ts +5 -0
- package/dist/types/core/hooks.d.ts +8 -1
- package/dist/types/core/instance.d.ts +52 -9
- package/dist/types/core/loader-registry.d.ts +7 -1
- package/dist/types/core/types.d.ts +34 -1
- package/dist/types/plugins/bridge.d.ts +23 -2
- package/dist/types/plugins/hook-logger.d.ts +3 -1
- package/dist/types/plugins/persistence.d.ts +4 -1
- package/dist/types/vue/directive.d.ts +6 -3
- package/dist/types/vue/global-types.d.ts +35 -0
- package/dist/types/vue/index.d.ts +0 -21
- package/dist/types/vue/inject.d.ts +2 -2
- package/dist/types/vue/plugin.d.ts +7 -2
- package/dist/types/vue/scope.d.ts +27 -4
- package/dist/vue-global-types.js +0 -0
- package/dist/vue.js +80 -33
- package/package.json +21 -7
- package/dist/chunks/core-CJdrAmJT.js +0 -403
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type WritableComputedRef } from 'vue';
|
|
2
2
|
import { HookManager } from './hooks';
|
|
3
|
-
import type { FintI18nOptions, Locale, MessageValue, TranslateOptions } from './types';
|
|
4
|
-
export declare class FintI18n {
|
|
5
|
-
|
|
3
|
+
import type { FintI18nOptions, Locale, LocaleLoaderSource, MessageKey, MessageSchema, MessageValue, TranslateOptions } from './types';
|
|
4
|
+
export declare class FintI18n<Schema extends MessageSchema = any> {
|
|
5
|
+
/**
|
|
6
|
+
* Текущая локаль. Чтение реактивно.
|
|
7
|
+
* Прямая запись в `.value` устарела: она делегирует в `setLocale()` —
|
|
8
|
+
* используйте `setLocale()` напрямую.
|
|
9
|
+
*/
|
|
10
|
+
readonly locale: WritableComputedRef<Locale>;
|
|
6
11
|
fallbackLocale: Locale;
|
|
7
|
-
readonly
|
|
12
|
+
private readonly messagesStore;
|
|
13
|
+
/** Read-only представление словарей. Изменение — только через `mergeMessages()`. */
|
|
14
|
+
readonly messages: Readonly<Record<Locale, MessageSchema>>;
|
|
15
|
+
private readonly localeRef;
|
|
16
|
+
private readonly preloadFallback;
|
|
17
|
+
private readonly unloadUnusedBlocks;
|
|
8
18
|
private compiledMessages;
|
|
9
19
|
private readonly loaderRegistry;
|
|
10
20
|
private loadingBlocks;
|
|
@@ -12,24 +22,46 @@ export declare class FintI18n {
|
|
|
12
22
|
private blockUsageCounters;
|
|
13
23
|
private patternExpansionCache;
|
|
14
24
|
private pendingUsedBlockLoads;
|
|
15
|
-
private
|
|
25
|
+
private localeEpoch;
|
|
26
|
+
private missingKeyReported;
|
|
27
|
+
private localeSetterWarned;
|
|
28
|
+
private readonly installedPlugins;
|
|
16
29
|
hooks: HookManager;
|
|
17
30
|
constructor(options: FintI18nOptions);
|
|
18
|
-
|
|
31
|
+
/** Деинициализация: вызывает `uninstall` у установленных плагинов. */
|
|
32
|
+
dispose: () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Зарегистрировать дополнительные лоадеры после создания инстанса
|
|
35
|
+
* (микрофронтенды, динамически подключаемые модули).
|
|
36
|
+
*/
|
|
37
|
+
addLoaders: (source: LocaleLoaderSource) => void;
|
|
38
|
+
/** Локали, известные из зарегистрированных лоадеров. */
|
|
39
|
+
getKnownLocales: () => readonly Locale[];
|
|
40
|
+
t: (key: MessageKey<Schema>, params?: Record<string, any>, options?: TranslateOptions) => string;
|
|
41
|
+
private reportMissingKey;
|
|
42
|
+
private reportError;
|
|
19
43
|
private resolve;
|
|
20
44
|
private setCompiled;
|
|
45
|
+
/**
|
|
46
|
+
* Инвалидировать кэш компиляции для поддерева блока: сам блок и все
|
|
47
|
+
* вложенные ключи. Вызывается перед каждым merge, чтобы перезаписанные
|
|
48
|
+
* сообщения не отдавались из устаревшего кэша.
|
|
49
|
+
*/
|
|
50
|
+
private invalidateCompiled;
|
|
21
51
|
/**
|
|
22
52
|
* Развернуть wildcard-паттерн в список конкретных имён блоков.
|
|
23
|
-
* Результат кэшируется по строке
|
|
53
|
+
* Результат кэшируется по строке паттерна; кэш сбрасывается в addLoaders().
|
|
24
54
|
* Не-паттерны возвращают пустой массив.
|
|
25
55
|
*/
|
|
26
56
|
private expandPattern;
|
|
27
57
|
loadBlock: (blockName: string, locale?: Locale) => Promise<void>;
|
|
58
|
+
private loadConcreteBlock;
|
|
28
59
|
mergeMessages: (locale: Locale, blockName: string, messages: MessageValue) => void;
|
|
29
60
|
private precompileBlock;
|
|
30
61
|
isBlockLoaded: (blockName: string, locale?: Locale) => boolean;
|
|
31
62
|
markBlockLoaded: (blockName: string, locale: Locale) => void;
|
|
32
63
|
loadUsedBlocks: (locale: Locale) => Promise<void>;
|
|
64
|
+
private hasUnloadedUsedBlocks;
|
|
33
65
|
setLocale: (newLocale: Locale) => Promise<void>;
|
|
34
66
|
/**
|
|
35
67
|
* Зарегистрировать использование блока.
|
|
@@ -48,5 +80,16 @@ export declare class FintI18n {
|
|
|
48
80
|
unregisterUsage: (blockName: string) => void;
|
|
49
81
|
private incrementUsage;
|
|
50
82
|
private decrementUsage;
|
|
83
|
+
/**
|
|
84
|
+
* Выгрузить блок из памяти: удалить поддерево сообщений, инвалидировать
|
|
85
|
+
* кэш компиляции и сбросить отметку о загрузке (следующий `loadBlock`
|
|
86
|
+
* загрузит блок заново).
|
|
87
|
+
*
|
|
88
|
+
* Ограничение: если блок был загружен через родительский лоадер
|
|
89
|
+
* (например, `pages.articles` резолвится в `pages`), выгружать нужно
|
|
90
|
+
* по имени загруженного (родительского) блока.
|
|
91
|
+
*/
|
|
92
|
+
unloadBlock: (blockName: string, locale?: Locale) => void;
|
|
93
|
+
private unloadBlockAllLocales;
|
|
51
94
|
}
|
|
52
|
-
export declare function createFintI18n(options: FintI18nOptions): FintI18n
|
|
95
|
+
export declare function createFintI18n<Schema extends MessageSchema = any>(options: FintI18nOptions): FintI18n<Schema>;
|
|
@@ -6,9 +6,15 @@ export interface ResolvedLocaleBlockLoaders {
|
|
|
6
6
|
export declare function isBlockPattern(name: string): boolean;
|
|
7
7
|
export declare class LocaleLoaderRegistry {
|
|
8
8
|
private readonly loaders;
|
|
9
|
-
private
|
|
9
|
+
private knownBlockNames;
|
|
10
10
|
constructor(source?: LocaleLoaderSource);
|
|
11
|
+
/**
|
|
12
|
+
* Зарегистрировать дополнительные лоадеры после создания реестра
|
|
13
|
+
* (микрофронтенды, динамически подключаемые модули).
|
|
14
|
+
*/
|
|
15
|
+
add(source: LocaleLoaderSource): void;
|
|
11
16
|
getKnownBlockNames(): readonly string[];
|
|
17
|
+
getKnownLocales(): Locale[];
|
|
12
18
|
/**
|
|
13
19
|
* Развернуть wildcard-паттерн в список конкретных имён блоков.
|
|
14
20
|
*
|
|
@@ -1,25 +1,58 @@
|
|
|
1
1
|
import type { MessageFunction } from './compiler';
|
|
2
2
|
import type { FintI18n } from './instance';
|
|
3
3
|
export type Locale = string;
|
|
4
|
-
export type LocaleBlockLoader = () => Promise<
|
|
4
|
+
export type LocaleBlockLoader = () => Promise<{
|
|
5
|
+
default: MessageValue;
|
|
6
|
+
} | MessageValue>;
|
|
5
7
|
export type LocaleBlockLoaders = LocaleBlockLoader | LocaleBlockLoader[];
|
|
6
8
|
export type LocaleLoaderCollection = Record<Locale, Record<string, LocaleBlockLoaders>>;
|
|
7
9
|
export type LocaleLoaderSource = LocaleLoaderCollection | LocaleLoaderCollection[];
|
|
8
10
|
export interface FintI18nPlugin {
|
|
9
11
|
name: string;
|
|
10
12
|
install: (instance: FintI18n) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Деинициализация плагина: снятие подписок, слушателей событий и т.п.
|
|
15
|
+
* Вызывается из `FintI18n.dispose()`.
|
|
16
|
+
*/
|
|
17
|
+
uninstall?: (instance: FintI18n) => void;
|
|
11
18
|
}
|
|
12
19
|
export interface FintI18nOptions {
|
|
13
20
|
locale: Locale;
|
|
14
21
|
fallbackLocale?: Locale;
|
|
15
22
|
loaders?: LocaleLoaderSource;
|
|
16
23
|
plugins?: FintI18nPlugin[];
|
|
24
|
+
/**
|
|
25
|
+
* Грузить блоки также для `fallbackLocale` при каждом `loadBlock`.
|
|
26
|
+
* Без этого fallback срабатывает только по уже загруженным сообщениям.
|
|
27
|
+
*/
|
|
28
|
+
preloadFallback?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Выгружать блок из памяти (сообщения + кэш компиляции), когда счётчик
|
|
31
|
+
* его использований опускается до нуля (unmount последнего компонента,
|
|
32
|
+
* вызвавшего `useI18nScope` с этим блоком). По умолчанию выключено.
|
|
33
|
+
*/
|
|
34
|
+
unloadUnusedBlocks?: boolean;
|
|
17
35
|
}
|
|
18
36
|
export type MessagePrimitive = string | number | boolean;
|
|
19
37
|
export interface MessageSchema {
|
|
20
38
|
[key: string]: MessagePrimitive | MessageFunction | MessageSchema;
|
|
21
39
|
}
|
|
22
40
|
export type MessageValue = MessagePrimitive | MessageFunction | MessageSchema;
|
|
41
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
42
|
+
/**
|
|
43
|
+
* Все листовые ключи схемы в dot-нотации:
|
|
44
|
+
* `{ common: { welcome: string } }` → `'common.welcome'`.
|
|
45
|
+
*/
|
|
46
|
+
export type MessageKeys<S> = S extends MessageSchema ? {
|
|
47
|
+
[K in keyof S & string]: S[K] extends MessageSchema ? `${K}.${MessageKeys<S[K]>}` : K;
|
|
48
|
+
}[keyof S & string] : never;
|
|
49
|
+
/**
|
|
50
|
+
* Тип ключа для `t()`: литеральные ключи схемы (автодополнение и проверка
|
|
51
|
+
* опечаток) плюс произвольная строка — для динамически конструируемых ключей
|
|
52
|
+
* и обратной совместимости (`string & {}` не сворачивает union в `string`).
|
|
53
|
+
*/
|
|
54
|
+
export type MessageKey<S> = IsAny<S> extends true ? string : MessageKeys<S> | (string & {});
|
|
23
55
|
export interface TranslateOptions {
|
|
24
56
|
fallbackLocale?: Locale;
|
|
25
57
|
}
|
|
58
|
+
export {};
|
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import type { FintI18n, FintI18nPlugin, Locale } from '../core';
|
|
3
|
+
/**
|
|
4
|
+
* Минимальный структурный контракт vue-i18n:
|
|
5
|
+
* composer (locale — Ref) либо legacy-инстанс (locale — строка).
|
|
6
|
+
*/
|
|
7
|
+
export interface BridgeI18nTarget {
|
|
8
|
+
locale: Ref<Locale> | Locale;
|
|
9
|
+
t: (key: string, params?: Record<string, any>) => string;
|
|
10
|
+
}
|
|
2
11
|
export interface BridgeOptions {
|
|
3
|
-
i18n
|
|
12
|
+
/** vue-i18n composer / legacy-инстанс; объекты с `.global` разворачиваются автоматически. */
|
|
13
|
+
i18n: BridgeI18nTarget | {
|
|
14
|
+
global: BridgeI18nTarget;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Чей перевод приоритетнее при конфликте:
|
|
18
|
+
* - `'fint'` (по умолчанию): vue-i18n опрашивается только если fint-i18n не нашёл ключ;
|
|
19
|
+
* - `'vue-i18n'`: перевод vue-i18n перекрывает найденный fint-i18n.
|
|
20
|
+
*/
|
|
21
|
+
priority?: 'fint' | 'vue-i18n';
|
|
4
22
|
}
|
|
5
23
|
export declare class BridgePlugin implements FintI18nPlugin {
|
|
6
24
|
name: string;
|
|
7
25
|
private options;
|
|
26
|
+
private stopLocaleWatch?;
|
|
27
|
+
private hookUnsubscribers;
|
|
8
28
|
constructor(options: BridgeOptions);
|
|
9
29
|
install(fintI18n: FintI18n): void;
|
|
30
|
+
uninstall(): void;
|
|
10
31
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FintI18n, FintI18nPlugin } from '
|
|
1
|
+
import type { FintI18n, FintI18nPlugin } from '../core';
|
|
2
2
|
type LoggerFn = (message?: any, ...optionalParams: any[]) => void;
|
|
3
3
|
export interface HookLoggerPluginOptions {
|
|
4
4
|
logger?: LoggerFn;
|
|
@@ -7,8 +7,10 @@ export interface HookLoggerPluginOptions {
|
|
|
7
7
|
export declare class HookLoggerPlugin implements FintI18nPlugin {
|
|
8
8
|
name: string;
|
|
9
9
|
private options;
|
|
10
|
+
private hookUnsubscribers;
|
|
10
11
|
constructor(options?: HookLoggerPluginOptions);
|
|
11
12
|
install(i18n: FintI18n): void;
|
|
13
|
+
uninstall(): void;
|
|
12
14
|
private registerHook;
|
|
13
15
|
}
|
|
14
16
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FintI18n, FintI18nPlugin } from '
|
|
1
|
+
import type { FintI18n, FintI18nPlugin } from '../core';
|
|
2
2
|
export interface PersistenceOptions {
|
|
3
3
|
key?: string;
|
|
4
4
|
storage?: Storage;
|
|
@@ -7,6 +7,9 @@ export interface PersistenceOptions {
|
|
|
7
7
|
export declare class PersistencePlugin implements FintI18nPlugin {
|
|
8
8
|
name: string;
|
|
9
9
|
private options;
|
|
10
|
+
private offLocaleChange?;
|
|
11
|
+
private storageListener?;
|
|
10
12
|
constructor(options?: PersistenceOptions);
|
|
11
13
|
install(i18n: FintI18n): void;
|
|
14
|
+
uninstall(): void;
|
|
12
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { FintI18n } from '
|
|
1
|
+
import { type Directive } from 'vue';
|
|
2
|
+
import type { FintI18n } from '../core';
|
|
3
3
|
export type VTDirectiveValue = string | {
|
|
4
4
|
path: string;
|
|
5
5
|
params?: Record<string, any>;
|
|
@@ -11,8 +11,11 @@ export interface VTDirectiveModifiers {
|
|
|
11
11
|
/**
|
|
12
12
|
* Create v-t directive.
|
|
13
13
|
*
|
|
14
|
+
* Reactive: element text is re-rendered on locale change and when
|
|
15
|
+
* lazily loaded blocks arrive (via a per-element watchEffect).
|
|
16
|
+
*
|
|
14
17
|
* Modifiers:
|
|
15
|
-
* - `.once`: render only once
|
|
18
|
+
* - `.once`: render only once, no reactivity
|
|
16
19
|
* - `.preserve`: keep current text if key not found
|
|
17
20
|
*/
|
|
18
21
|
export declare function createVTDirective(i18n: FintI18n): Directive<HTMLElement, VTDirectiveValue>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in глобальная аугментация типов Vue: `$t`, `$i18n` и директива `v-t`.
|
|
3
|
+
*
|
|
4
|
+
* Подключается явно — только если используется стандартная регистрация
|
|
5
|
+
* (`installI18n` с `globalInstall: true` и директивой под именем `t`):
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import '@feugene/fint-i18n/vue/global-types'
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Если глобальные свойства отключены или директива переименована,
|
|
12
|
+
* не импортируйте этот модуль — объявите собственный `declare module 'vue'`.
|
|
13
|
+
*/
|
|
14
|
+
import type { Directive } from 'vue';
|
|
15
|
+
import type { FintI18n } from '../core';
|
|
16
|
+
import type { VTDirectiveValue } from './directive';
|
|
17
|
+
declare module '@vue/runtime-core' {
|
|
18
|
+
interface GlobalDirectives {
|
|
19
|
+
vT: Directive<HTMLElement, VTDirectiveValue>;
|
|
20
|
+
}
|
|
21
|
+
interface ComponentCustomProperties {
|
|
22
|
+
$t: FintI18n['t'];
|
|
23
|
+
$i18n: FintI18n;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
declare module 'vue' {
|
|
27
|
+
interface GlobalDirectives {
|
|
28
|
+
vT: Directive<HTMLElement, VTDirectiveValue>;
|
|
29
|
+
}
|
|
30
|
+
interface ComponentCustomProperties {
|
|
31
|
+
$t: FintI18n['t'];
|
|
32
|
+
$i18n: FintI18n;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -2,24 +2,3 @@ export * from './scope';
|
|
|
2
2
|
export * from './inject';
|
|
3
3
|
export * from './directive';
|
|
4
4
|
export * from './plugin';
|
|
5
|
-
import type { FintI18n } from '@/core';
|
|
6
|
-
import type { Directive } from 'vue';
|
|
7
|
-
import type { VTDirectiveValue } from './directive';
|
|
8
|
-
declare module '@vue/runtime-core' {
|
|
9
|
-
interface GlobalDirectives {
|
|
10
|
-
vT: Directive<HTMLElement, VTDirectiveValue>;
|
|
11
|
-
}
|
|
12
|
-
interface ComponentCustomProperties {
|
|
13
|
-
$t: FintI18n['t'];
|
|
14
|
-
$i18n: FintI18n;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
declare module 'vue' {
|
|
18
|
-
interface GlobalDirectives {
|
|
19
|
-
vT: Directive<HTMLElement, VTDirectiveValue>;
|
|
20
|
-
}
|
|
21
|
-
interface ComponentCustomProperties {
|
|
22
|
-
$t: FintI18n['t'];
|
|
23
|
-
$i18n: FintI18n;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type InjectionKey } from 'vue';
|
|
2
|
-
import type { FintI18n } from '
|
|
2
|
+
import type { FintI18n, MessageSchema } from '../core';
|
|
3
3
|
export declare const FINT_I18N_KEY: InjectionKey<FintI18n>;
|
|
4
|
-
export declare function useFintI18n(): FintI18n
|
|
4
|
+
export declare function useFintI18n<Schema extends MessageSchema = any>(): FintI18n<Schema>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { App } from 'vue';
|
|
2
|
-
import type { FintI18n } from '
|
|
1
|
+
import type { App, Plugin } from 'vue';
|
|
2
|
+
import type { FintI18n } from '../core';
|
|
3
3
|
export type GlobalInstallFn = (app: App, i18n: FintI18n) => void;
|
|
4
4
|
export interface InstallI18nOptions {
|
|
5
5
|
directive?: string | boolean;
|
|
@@ -12,3 +12,8 @@ export interface InstallI18nOptions {
|
|
|
12
12
|
globalInstall?: boolean | GlobalInstallFn;
|
|
13
13
|
}
|
|
14
14
|
export declare function installI18n(app: App, i18n: FintI18n, options?: InstallI18nOptions): void;
|
|
15
|
+
/**
|
|
16
|
+
* Стандартный Vue-плагин поверх `installI18n` — для конвенционального
|
|
17
|
+
* `app.use(createFintI18nPlugin(i18n))`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createFintI18nPlugin(i18n: FintI18n, options?: InstallI18nOptions): Plugin;
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ComputedRef, type Ref } from 'vue';
|
|
2
|
+
import type { Locale } from '../core';
|
|
3
|
+
export interface UseI18nScopeOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Префиксовать ключи именем блока: `t('login')` → `t('auth.login')`.
|
|
6
|
+
* Работает только с одиночным конкретным блоком (не паттерном).
|
|
7
|
+
*/
|
|
8
|
+
prefix?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface I18nScope {
|
|
2
11
|
t: (key: string, params?: Record<string, any>) => string;
|
|
3
|
-
locale:
|
|
4
|
-
setLocale: (l:
|
|
5
|
-
}
|
|
12
|
+
locale: ComputedRef<Locale>;
|
|
13
|
+
setLocale: (l: Locale) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export interface I18nScopeSync extends I18nScope {
|
|
16
|
+
/** Становится `true`, когда все блоки скоупа загружены. */
|
|
17
|
+
ready: Ref<boolean>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Асинхронный скоуп блоков: дожидается загрузки.
|
|
21
|
+
* Требует `await` в `<script setup>` (т.е. `<Suspense>` выше по дереву).
|
|
22
|
+
*/
|
|
23
|
+
export declare function useI18nScope(blocks: string | string[], options?: UseI18nScopeOptions): Promise<I18nScope>;
|
|
24
|
+
/**
|
|
25
|
+
* Синхронный вариант useI18nScope — не требует Suspense.
|
|
26
|
+
* Блоки загружаются в фоне; `ready` сигнализирует о готовности.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useI18nScopeSync(blocks: string | string[], options?: UseI18nScopeOptions): I18nScopeSync;
|
|
File without changes
|
package/dist/vue.js
CHANGED
|
@@ -1,56 +1,103 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as e } from "./chunks/loader-registry-B_fUe8pM.js";
|
|
2
|
+
import { computed as t, inject as n, onUnmounted as r, ref as i, shallowRef as a, watchEffect as o } from "vue";
|
|
2
3
|
//#region src/vue/inject.ts
|
|
3
|
-
var
|
|
4
|
-
function
|
|
5
|
-
let
|
|
6
|
-
if (!
|
|
7
|
-
return
|
|
4
|
+
var s = Symbol.for("FintI18n");
|
|
5
|
+
function c() {
|
|
6
|
+
let e = n(s);
|
|
7
|
+
if (!e) throw Error("[fint-i18n] Instance not found. Did you call installI18n(app, i18n)?");
|
|
8
|
+
return e;
|
|
8
9
|
}
|
|
9
10
|
//#endregion
|
|
10
11
|
//#region src/vue/scope.ts
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
function l(n, i) {
|
|
13
|
+
let a = c(), o = Array.isArray(n) ? n : [n];
|
|
14
|
+
r(() => {
|
|
15
|
+
o.forEach((e) => a.unregisterUsage(e));
|
|
15
16
|
});
|
|
16
|
-
let
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
let s = o.map((e) => (a.registerUsage(e), a.loadBlock(e))), l = "";
|
|
18
|
+
return i.prefix && (o.length === 1 && !e(o[0]) ? l = `${o[0]}.` : console.warn("[fint-i18n] `prefix` option is ignored: it requires a single concrete block name")), {
|
|
19
|
+
loads: s,
|
|
20
|
+
scope: {
|
|
21
|
+
t: (e, t) => a.t(l + e, t),
|
|
22
|
+
locale: t(() => a.locale.value),
|
|
23
|
+
setLocale: (e) => a.setLocale(e)
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async function u(e, t = {}) {
|
|
28
|
+
let { loads: n, scope: r } = l(e, t);
|
|
29
|
+
return await Promise.all(n), r;
|
|
30
|
+
}
|
|
31
|
+
function d(e, t = {}) {
|
|
32
|
+
let { loads: n, scope: r } = l(e, t), a = i(!1);
|
|
33
|
+
return Promise.all(n).then(() => {
|
|
34
|
+
a.value = !0;
|
|
35
|
+
}).catch((e) => {
|
|
36
|
+
console.error("[fint-i18n] Failed to load scope blocks:", e);
|
|
37
|
+
}), {
|
|
38
|
+
...r,
|
|
39
|
+
ready: a
|
|
21
40
|
};
|
|
22
41
|
}
|
|
23
42
|
//#endregion
|
|
24
43
|
//#region src/vue/directive.ts
|
|
25
|
-
|
|
44
|
+
var f = /* @__PURE__ */ new WeakMap();
|
|
45
|
+
function p(e) {
|
|
26
46
|
return {
|
|
27
47
|
mounted(t, n) {
|
|
28
|
-
|
|
48
|
+
if (n.modifiers.once) {
|
|
49
|
+
h(t, n, e);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
let r = a(n), i = o(() => h(t, r.value, e));
|
|
53
|
+
f.set(t, {
|
|
54
|
+
binding: r,
|
|
55
|
+
stop: i
|
|
56
|
+
});
|
|
29
57
|
},
|
|
30
58
|
updated(t, n) {
|
|
31
|
-
n.modifiers.once
|
|
59
|
+
if (n.modifiers.once) return;
|
|
60
|
+
let r = f.get(t);
|
|
61
|
+
r ? r.binding.value = n : h(t, n, e);
|
|
62
|
+
},
|
|
63
|
+
unmounted(e) {
|
|
64
|
+
let t = f.get(e);
|
|
65
|
+
t && (t.stop(), f.delete(e));
|
|
66
|
+
},
|
|
67
|
+
getSSRProps(t) {
|
|
68
|
+
let n = m(t.value);
|
|
69
|
+
return n ? { textContent: e.t(n.key, n.params) } : {};
|
|
32
70
|
}
|
|
33
71
|
};
|
|
34
72
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
73
|
+
function m(e) {
|
|
74
|
+
return typeof e == "string" ? { key: e } : e && typeof e == "object" ? {
|
|
75
|
+
key: e.path,
|
|
76
|
+
params: e.params
|
|
77
|
+
} : null;
|
|
78
|
+
}
|
|
79
|
+
function h(e, t, n) {
|
|
80
|
+
let r = m(t.value);
|
|
81
|
+
if (!r) return;
|
|
82
|
+
let i = n.t(r.key, r.params);
|
|
83
|
+
i === r.key && t.modifiers.preserve || (e.textContent = i);
|
|
42
84
|
}
|
|
43
85
|
//#endregion
|
|
44
86
|
//#region src/vue/plugin.ts
|
|
45
|
-
function
|
|
87
|
+
function g(e, t) {
|
|
46
88
|
e.config.globalProperties.$t = t.t, e.config.globalProperties.$i18n = t;
|
|
47
89
|
}
|
|
48
|
-
function
|
|
49
|
-
e.provide(
|
|
50
|
-
let
|
|
51
|
-
typeof
|
|
52
|
-
let
|
|
53
|
-
|
|
90
|
+
function _(e, t, n = {}) {
|
|
91
|
+
e.provide(s, t);
|
|
92
|
+
let r = n.globalInstall ?? !0;
|
|
93
|
+
typeof r == "function" ? r(e, t) : r && g(e, t);
|
|
94
|
+
let i = n.directive === !1 ? null : typeof n.directive == "string" ? n.directive : "t";
|
|
95
|
+
i && e.directive(i, p(t));
|
|
96
|
+
}
|
|
97
|
+
function v(e, t = {}) {
|
|
98
|
+
return { install(n) {
|
|
99
|
+
_(n, e, t);
|
|
100
|
+
} };
|
|
54
101
|
}
|
|
55
102
|
//#endregion
|
|
56
|
-
export {
|
|
103
|
+
export { s as FINT_I18N_KEY, v as createFintI18nPlugin, p as createVTDirective, _ as installI18n, c as useFintI18n, u as useI18nScope, d as useI18nScopeSync };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feugene/fint-i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Lightweight Vue 3 i18n library with lazy-loading blocks and template caching",
|
|
5
|
-
"author": "
|
|
5
|
+
"author": "Fureev Eugene<https://feugene.org>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/efureev/fint-i18n#readme",
|
|
8
8
|
"repository": {
|
|
@@ -22,24 +22,38 @@
|
|
|
22
22
|
],
|
|
23
23
|
"type": "module",
|
|
24
24
|
"files": [
|
|
25
|
-
"dist"
|
|
25
|
+
"dist",
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"README.md"
|
|
26
28
|
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
31
|
+
},
|
|
27
32
|
"exports": {
|
|
28
33
|
".": {
|
|
29
34
|
"types": "./dist/types/index.d.ts",
|
|
30
|
-
"import": "./dist/index.js"
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"default": "./dist/index.js"
|
|
31
37
|
},
|
|
32
38
|
"./core": {
|
|
33
39
|
"types": "./dist/types/core/index.d.ts",
|
|
34
|
-
"import": "./dist/core.js"
|
|
40
|
+
"import": "./dist/core.js",
|
|
41
|
+
"default": "./dist/core.js"
|
|
35
42
|
},
|
|
36
43
|
"./vue": {
|
|
37
44
|
"types": "./dist/types/vue/index.d.ts",
|
|
38
|
-
"import": "./dist/vue.js"
|
|
45
|
+
"import": "./dist/vue.js",
|
|
46
|
+
"default": "./dist/vue.js"
|
|
47
|
+
},
|
|
48
|
+
"./vue/global-types": {
|
|
49
|
+
"types": "./dist/types/vue/global-types.d.ts",
|
|
50
|
+
"import": "./dist/vue-global-types.js",
|
|
51
|
+
"default": "./dist/vue-global-types.js"
|
|
39
52
|
},
|
|
40
53
|
"./plugins": {
|
|
41
54
|
"types": "./dist/types/plugins/index.d.ts",
|
|
42
|
-
"import": "./dist/plugins.js"
|
|
55
|
+
"import": "./dist/plugins.js",
|
|
56
|
+
"default": "./dist/plugins.js"
|
|
43
57
|
}
|
|
44
58
|
},
|
|
45
59
|
"sideEffects": false,
|