@vielzeug/i18nit 1.1.3 → 1.2.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/README.md +216 -214
- package/dist/i18nit.cjs +1 -1
- package/dist/i18nit.cjs.map +1 -1
- package/dist/i18nit.js +105 -141
- package/dist/i18nit.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +19 -31
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
export declare function createI18n(config?: I18nConfig): I18n;
|
|
2
2
|
|
|
3
|
-
declare class I18n {
|
|
3
|
+
export declare class I18n {
|
|
4
4
|
private locale;
|
|
5
5
|
private fallbacks;
|
|
6
|
+
private escape;
|
|
6
7
|
private catalogs;
|
|
7
8
|
private loaders;
|
|
8
9
|
private loading;
|
|
9
10
|
private subscribers;
|
|
10
|
-
private escape;
|
|
11
|
-
private missingKey;
|
|
12
|
-
private missingVar;
|
|
13
11
|
constructor(config?: I18nConfig);
|
|
14
12
|
setLocale(locale: Locale): void;
|
|
15
13
|
getLocale(): Locale;
|
|
@@ -25,25 +23,30 @@ declare class I18n {
|
|
|
25
23
|
hasLocale(locale: Locale): boolean;
|
|
26
24
|
has(key: string, locale?: Locale): boolean;
|
|
27
25
|
load(locale: Locale): Promise<void>;
|
|
28
|
-
register(locale: Locale, loader: () => Promise<Messages>): void;
|
|
26
|
+
register(locale: Locale, loader: (locale: Locale) => Promise<Messages>): void;
|
|
29
27
|
hasAsync(key: string, locale?: Locale): Promise<boolean>;
|
|
30
28
|
/**
|
|
31
|
-
*
|
|
29
|
+
* Load multiple locales in parallel.
|
|
30
|
+
* Useful for preloading all needed locales at app startup.
|
|
32
31
|
*/
|
|
33
|
-
|
|
32
|
+
loadAll(locales: Locale[]): Promise<void>;
|
|
34
33
|
/**
|
|
35
|
-
* Translates a key with
|
|
34
|
+
* Translates a key with optional variables and options.
|
|
35
|
+
* Synchronous - locale must be loaded first via load() or provided in config.
|
|
36
36
|
*/
|
|
37
|
-
|
|
37
|
+
t(key: string, vars?: Record<string, unknown>, options?: TranslateOptions): string;
|
|
38
38
|
number(value: number, options?: Intl.NumberFormatOptions, locale?: Locale): string;
|
|
39
39
|
date(value: Date | number, options?: Intl.DateTimeFormatOptions, locale?: Locale): string;
|
|
40
40
|
namespace(ns: string): {
|
|
41
41
|
t: (key: string, vars?: Record<string, unknown>, options?: TranslateOptions) => string;
|
|
42
|
-
tl: (key: string, vars?: Record<string, unknown>, options?: TranslateOptions) => Promise<string>;
|
|
43
42
|
};
|
|
44
|
-
subscribe(handler:
|
|
43
|
+
subscribe(handler: (locale: Locale) => void): () => void;
|
|
45
44
|
private notifySubscribers;
|
|
46
45
|
private findMessage;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a value is a MessageValue (string or PluralMessages) rather than a nested Messages object
|
|
48
|
+
*/
|
|
49
|
+
private isMessageValue;
|
|
47
50
|
private getLocaleChain;
|
|
48
51
|
private formatMessage;
|
|
49
52
|
}
|
|
@@ -52,31 +55,17 @@ export declare type I18nConfig = {
|
|
|
52
55
|
locale?: Locale;
|
|
53
56
|
fallback?: Locale | Locale[];
|
|
54
57
|
messages?: Record<Locale, Messages>;
|
|
55
|
-
loaders?: Record<Locale, () => Promise<Messages>>;
|
|
58
|
+
loaders?: Record<Locale, (locale: Locale) => Promise<Messages>>;
|
|
56
59
|
escape?: boolean;
|
|
57
|
-
missingKey?: (key: string, locale: Locale) => string;
|
|
58
|
-
missingVar?: 'preserve' | 'empty' | 'error';
|
|
59
60
|
};
|
|
60
61
|
|
|
61
62
|
export declare type Locale = string;
|
|
62
63
|
|
|
63
|
-
export declare type
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
number: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
67
|
-
date: (value: Date | number, options?: Intl.DateTimeFormatOptions) => string;
|
|
68
|
-
}) => string;
|
|
69
|
-
|
|
70
|
-
export declare type Messages = Record<string, MessageValue>;
|
|
71
|
-
|
|
72
|
-
export declare type MessageValue = string | PluralMessages | MessageFunction;
|
|
64
|
+
export declare type Messages = {
|
|
65
|
+
[key: string]: MessageValue | Messages;
|
|
66
|
+
};
|
|
73
67
|
|
|
74
|
-
export declare
|
|
75
|
-
readonly key: string;
|
|
76
|
-
readonly variable: string;
|
|
77
|
-
readonly locale: Locale;
|
|
78
|
-
constructor(key: string, variable: string, locale: Locale);
|
|
79
|
-
}
|
|
68
|
+
export declare type MessageValue = string | PluralMessages;
|
|
80
69
|
|
|
81
70
|
export declare type PluralForm = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
|
|
82
71
|
|
|
@@ -86,7 +75,6 @@ export declare type PluralMessages = Partial<Record<PluralForm, string>> & {
|
|
|
86
75
|
|
|
87
76
|
export declare type TranslateOptions = {
|
|
88
77
|
locale?: Locale;
|
|
89
|
-
fallback?: string;
|
|
90
78
|
escape?: boolean;
|
|
91
79
|
};
|
|
92
80
|
|
package/dist/index.js
CHANGED