gt-i18n 0.8.14 → 0.9.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/CHANGELOG.md +26 -0
- package/dist/{TranslationsCache-EwvK0L53.d.cts → TranslationsCache-DQt4Es4G.d.cts} +13 -4
- package/dist/{TranslationsCache-liJZngtP.d.mts → TranslationsCache-DdoHhP9C.d.mts} +13 -4
- package/dist/fallbacks.d.cts +1 -1
- package/dist/fallbacks.d.mts +1 -1
- package/dist/{functions-B2Dn3llc.d.mts → functions-DdlVwVU8.d.mts} +9 -4
- package/dist/{functions-9y6F4zXC.d.cts → functions-DsYQxTQp.d.cts} +9 -4
- package/dist/{index-DUcoQ9y0.d.mts → index-Bc5qKE7T.d.mts} +3 -3
- package/dist/{index-jpLs__jj.d.cts → index-UDlCzB02.d.cts} +3 -3
- package/dist/{index-DA9KV2bF.d.mts → index-XRxZZ8E4.d.mts} +2 -2
- package/dist/{index-VdD5_a-R.d.cts → index-v3fx8YUH.d.cts} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/internal-types.d.cts +4 -4
- package/dist/internal-types.d.mts +4 -4
- package/dist/internal.cjs +75 -11
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +31 -8
- package/dist/internal.d.mts +31 -8
- package/dist/internal.mjs +76 -12
- package/dist/internal.mjs.map +1 -1
- package/dist/{localeResolver-07Ie-MOQ.d.mts → localeResolver-DPayN_xR.d.mts} +3 -3
- package/dist/{localeResolver-BAUJEFj8.d.cts → localeResolver-DcN9SGPs.d.cts} +3 -3
- package/dist/{options-Bd7cus3W.d.mts → options-C1xolwBY.d.cts} +6 -2
- package/dist/{options-x-8rtagw.d.cts → options-DeF1NEbe.d.mts} +6 -2
- package/dist/types.d.cts +4 -4
- package/dist/types.d.mts +4 -4
- package/dist/{versionId-Bx4jT2_n.mjs → versionId-D0t6HuUM.mjs} +187 -34
- package/dist/versionId-D0t6HuUM.mjs.map +1 -0
- package/dist/{versionId-SL-n6mTD.cjs → versionId-qtCCdgKr.cjs} +204 -33
- package/dist/versionId-qtCCdgKr.cjs.map +1 -0
- package/package.json +5 -4
- package/dist/versionId-Bx4jT2_n.mjs.map +0 -1
- package/dist/versionId-SL-n6mTD.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# gt-i18n
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1359](https://github.com/generaltranslation/gt/pull/1359) [`528bb4a`](https://github.com/generaltranslation/gt/commit/528bb4a34b3eeab6f676137ab0f09e85dff213b0) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Enable dictionary-backed getTranslations with t and t.obj, and expose it from gt-node.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#1354](https://github.com/generaltranslation/gt/pull/1354) [`663af94`](https://github.com/generaltranslation/gt/commit/663af94207bc244de30046d96130e913f48c9add) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add dictionary lookup with runtime fallback.
|
|
12
|
+
|
|
13
|
+
- [#1355](https://github.com/generaltranslation/gt/pull/1355) [`a88c86d`](https://github.com/generaltranslation/gt/commit/a88c86df7842299063f1a2f6f7404e021c905016) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add dictionary cache object get and set primitives.
|
|
14
|
+
|
|
15
|
+
- [#1358](https://github.com/generaltranslation/gt/pull/1358) [`0f252ff`](https://github.com/generaltranslation/gt/commit/0f252fff408c701811cba61565beaf15bf9cdd95) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add dictionary object lookup with runtime fallback.
|
|
16
|
+
|
|
17
|
+
- [#1356](https://github.com/generaltranslation/gt/pull/1356) [`ee3a6ee`](https://github.com/generaltranslation/gt/commit/ee3a6eea113fbc5c2f5f0e8771d878a305f7bc7f) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add dictionary object lookup on the i18n manager.
|
|
18
|
+
|
|
19
|
+
- [#1357](https://github.com/generaltranslation/gt/pull/1357) [`375d75f`](https://github.com/generaltranslation/gt/commit/375d75f7a6525d83e19a5cf015a375a0f50537d2) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add runtime fallback primitives for dictionary object cache misses.
|
|
20
|
+
|
|
21
|
+
- [#1349](https://github.com/generaltranslation/gt/pull/1349) [`e123485`](https://github.com/generaltranslation/gt/commit/e12348563700ed886f64b2e00d7964355fb4558a) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Return dictionary metadata from dictionary cache lookups.
|
|
22
|
+
|
|
23
|
+
- [#1351](https://github.com/generaltranslation/gt/pull/1351) [`40e26b9`](https://github.com/generaltranslation/gt/commit/40e26b914295101d1be00f738fc33eb4ba9c495a) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add runtime translation fallback for dictionary cache misses.
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`9eae4d9`](https://github.com/generaltranslation/gt/commit/9eae4d93476688b621c739683c8bac64cbf50bf0)]:
|
|
26
|
+
- generaltranslation@8.2.12
|
|
27
|
+
- @generaltranslation/supported-locales@2.0.70
|
|
28
|
+
|
|
3
29
|
## 0.8.14
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as DictionaryOptions } from "./options-C1xolwBY.cjs";
|
|
2
2
|
import { Content } from "generaltranslation/types";
|
|
3
3
|
import { RuntimeTranslateManyOptions } from "generaltranslation/internal";
|
|
4
4
|
|
|
@@ -21,7 +21,11 @@ type Dictionary = {
|
|
|
21
21
|
[key: string]: DictionaryValue;
|
|
22
22
|
};
|
|
23
23
|
type DictionaryValue = DictionaryLeaf | Dictionary;
|
|
24
|
-
type DictionaryEntry =
|
|
24
|
+
type DictionaryEntry = {
|
|
25
|
+
entry: string;
|
|
26
|
+
options: DictionaryOptions;
|
|
27
|
+
};
|
|
28
|
+
type DictionaryObject = DictionaryValue;
|
|
25
29
|
type DictionaryPath = string;
|
|
26
30
|
type DictionaryKey = DictionaryPath;
|
|
27
31
|
//#endregion
|
|
@@ -72,6 +76,11 @@ type LifecycleCallbacks<TranslationValue extends Translation> = {
|
|
|
72
76
|
id: DictionaryPath;
|
|
73
77
|
dictionaryEntry: DictionaryEntry;
|
|
74
78
|
}) => void;
|
|
79
|
+
onDictionaryObjectCacheHit?: (params: {
|
|
80
|
+
locale: Locale;
|
|
81
|
+
id: DictionaryPath;
|
|
82
|
+
dictionaryValue: DictionaryValue;
|
|
83
|
+
}) => void;
|
|
75
84
|
onLocalesDictionaryCacheHit?: (params: {
|
|
76
85
|
locale: Locale;
|
|
77
86
|
dictionary: Dictionary;
|
|
@@ -93,5 +102,5 @@ type TranslationBatchConfig = {
|
|
|
93
102
|
*/
|
|
94
103
|
type Hash = string;
|
|
95
104
|
//#endregion
|
|
96
|
-
export { Dictionary as a, DictionaryLeaf as c,
|
|
97
|
-
//# sourceMappingURL=TranslationsCache-
|
|
105
|
+
export { Dictionary as a, DictionaryLeaf as c, DictionaryValue as d, Locale as f, DictionaryLoader as i, DictionaryObject as l, TranslationBatchConfig as n, DictionaryEntry as o, Translation as p, LifecycleCallbacks as r, DictionaryKey as s, Hash as t, DictionaryPath as u };
|
|
106
|
+
//# sourceMappingURL=TranslationsCache-DQt4Es4G.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as DictionaryOptions } from "./options-DeF1NEbe.mjs";
|
|
2
2
|
import { RuntimeTranslateManyOptions } from "generaltranslation/internal";
|
|
3
3
|
import { Content } from "generaltranslation/types";
|
|
4
4
|
|
|
@@ -21,7 +21,11 @@ type Dictionary = {
|
|
|
21
21
|
[key: string]: DictionaryValue;
|
|
22
22
|
};
|
|
23
23
|
type DictionaryValue = DictionaryLeaf | Dictionary;
|
|
24
|
-
type DictionaryEntry =
|
|
24
|
+
type DictionaryEntry = {
|
|
25
|
+
entry: string;
|
|
26
|
+
options: DictionaryOptions;
|
|
27
|
+
};
|
|
28
|
+
type DictionaryObject = DictionaryValue;
|
|
25
29
|
type DictionaryPath = string;
|
|
26
30
|
type DictionaryKey = DictionaryPath;
|
|
27
31
|
//#endregion
|
|
@@ -72,6 +76,11 @@ type LifecycleCallbacks<TranslationValue extends Translation> = {
|
|
|
72
76
|
id: DictionaryPath;
|
|
73
77
|
dictionaryEntry: DictionaryEntry;
|
|
74
78
|
}) => void;
|
|
79
|
+
onDictionaryObjectCacheHit?: (params: {
|
|
80
|
+
locale: Locale;
|
|
81
|
+
id: DictionaryPath;
|
|
82
|
+
dictionaryValue: DictionaryValue;
|
|
83
|
+
}) => void;
|
|
75
84
|
onLocalesDictionaryCacheHit?: (params: {
|
|
76
85
|
locale: Locale;
|
|
77
86
|
dictionary: Dictionary;
|
|
@@ -93,5 +102,5 @@ type TranslationBatchConfig = {
|
|
|
93
102
|
*/
|
|
94
103
|
type Hash = string;
|
|
95
104
|
//#endregion
|
|
96
|
-
export { Dictionary as a, DictionaryLeaf as c,
|
|
97
|
-
//# sourceMappingURL=TranslationsCache-
|
|
105
|
+
export { Dictionary as a, DictionaryLeaf as c, DictionaryValue as d, Locale as f, DictionaryLoader as i, DictionaryObject as l, TranslationBatchConfig as n, DictionaryEntry as o, Translation as p, LifecycleCallbacks as r, DictionaryKey as s, Hash as t, DictionaryPath as u };
|
|
106
|
+
//# sourceMappingURL=TranslationsCache-DdoHhP9C.d.mts.map
|
package/dist/fallbacks.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as gtFallback, t as mFallback } from "./index-
|
|
1
|
+
import { n as gtFallback, t as mFallback } from "./index-v3fx8YUH.cjs";
|
|
2
2
|
export { gtFallback, mFallback };
|
package/dist/fallbacks.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as gtFallback, t as mFallback } from "./index-
|
|
1
|
+
import { n as gtFallback, t as mFallback } from "./index-XRxZZ8E4.mjs";
|
|
2
2
|
export { gtFallback, mFallback };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as JsxTranslationOptions, i as DictionaryTranslationOptions, s as InlineTranslationOptions } from "./options-DeF1NEbe.mjs";
|
|
2
2
|
import { JsxChildren } from "generaltranslation/types";
|
|
3
3
|
|
|
4
4
|
//#region src/translation-functions/types/functions.d.ts
|
|
5
|
+
type DictionaryObjectTranslation = string | {
|
|
6
|
+
[key: string]: DictionaryObjectTranslation;
|
|
7
|
+
};
|
|
5
8
|
/**
|
|
6
9
|
* Synchronous resolution function type
|
|
7
10
|
* @param {string} message - The message to translate.
|
|
@@ -48,7 +51,9 @@ type MFunctionType = <T extends string | null | undefined>(encodedMsg: T, option
|
|
|
48
51
|
* @returns {string} The translated message.
|
|
49
52
|
* TODO: next major version, remove the "...type" suffix, it's redundant
|
|
50
53
|
*/
|
|
51
|
-
type TFunctionType = (id: string, options?: DictionaryTranslationOptions) => string
|
|
54
|
+
type TFunctionType = ((id: string, options?: DictionaryTranslationOptions) => string) & {
|
|
55
|
+
obj: (id: string) => DictionaryObjectTranslation;
|
|
56
|
+
};
|
|
52
57
|
/**
|
|
53
58
|
* Type for the resolveJsxTranslation() function
|
|
54
59
|
* @param {JsxChildren} children - The children to resolve the translation for.
|
|
@@ -57,5 +62,5 @@ type TFunctionType = (id: string, options?: DictionaryTranslationOptions) => str
|
|
|
57
62
|
*/
|
|
58
63
|
type ResolveJsxTranslationFunction = (locale: string, children: JsxChildren, options?: JsxTranslationOptions) => JsxChildren | undefined;
|
|
59
64
|
//#endregion
|
|
60
|
-
export {
|
|
61
|
-
//# sourceMappingURL=functions-
|
|
65
|
+
export { SyncResolutionFunction as a, ResolveJsxTranslationFunction as i, GTFunctionType as n, SyncResolutionFunctionWithFallback as o, MFunctionType as r, TFunctionType as s, DictionaryObjectTranslation as t };
|
|
66
|
+
//# sourceMappingURL=functions-DdlVwVU8.d.mts.map
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as JsxTranslationOptions, i as DictionaryTranslationOptions, s as InlineTranslationOptions } from "./options-C1xolwBY.cjs";
|
|
2
2
|
import { JsxChildren } from "generaltranslation/types";
|
|
3
3
|
|
|
4
4
|
//#region src/translation-functions/types/functions.d.ts
|
|
5
|
+
type DictionaryObjectTranslation = string | {
|
|
6
|
+
[key: string]: DictionaryObjectTranslation;
|
|
7
|
+
};
|
|
5
8
|
/**
|
|
6
9
|
* Synchronous resolution function type
|
|
7
10
|
* @param {string} message - The message to translate.
|
|
@@ -48,7 +51,9 @@ type MFunctionType = <T extends string | null | undefined>(encodedMsg: T, option
|
|
|
48
51
|
* @returns {string} The translated message.
|
|
49
52
|
* TODO: next major version, remove the "...type" suffix, it's redundant
|
|
50
53
|
*/
|
|
51
|
-
type TFunctionType = (id: string, options?: DictionaryTranslationOptions) => string
|
|
54
|
+
type TFunctionType = ((id: string, options?: DictionaryTranslationOptions) => string) & {
|
|
55
|
+
obj: (id: string) => DictionaryObjectTranslation;
|
|
56
|
+
};
|
|
52
57
|
/**
|
|
53
58
|
* Type for the resolveJsxTranslation() function
|
|
54
59
|
* @param {JsxChildren} children - The children to resolve the translation for.
|
|
@@ -57,5 +62,5 @@ type TFunctionType = (id: string, options?: DictionaryTranslationOptions) => str
|
|
|
57
62
|
*/
|
|
58
63
|
type ResolveJsxTranslationFunction = (locale: string, children: JsxChildren, options?: JsxTranslationOptions) => JsxChildren | undefined;
|
|
59
64
|
//#endregion
|
|
60
|
-
export {
|
|
61
|
-
//# sourceMappingURL=functions-
|
|
65
|
+
export { SyncResolutionFunction as a, ResolveJsxTranslationFunction as i, GTFunctionType as n, SyncResolutionFunctionWithFallback as o, MFunctionType as r, TFunctionType as s, DictionaryObjectTranslation as t };
|
|
66
|
+
//# sourceMappingURL=functions-DsYQxTQp.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as _$
|
|
1
|
+
import * as _$generaltranslation_internal0 from "generaltranslation/internal";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/locale.d.ts
|
|
4
4
|
/**
|
|
@@ -39,7 +39,7 @@ declare function getDefaultLocale(): string;
|
|
|
39
39
|
* @example
|
|
40
40
|
* const localeProperties = getLocaleProperties('en-US');
|
|
41
41
|
*/
|
|
42
|
-
declare function getLocaleProperties(locale?: string): _$
|
|
42
|
+
declare function getLocaleProperties(locale?: string): _$generaltranslation_internal0.LocaleProperties;
|
|
43
43
|
//#endregion
|
|
44
44
|
//#region src/helpers/versionId.d.ts
|
|
45
45
|
/**
|
|
@@ -53,4 +53,4 @@ declare function getLocaleProperties(locale?: string): _$generaltranslation_type
|
|
|
53
53
|
declare function getVersionId(): string | undefined;
|
|
54
54
|
//#endregion
|
|
55
55
|
export { getLocales as a, getLocaleProperties as i, getDefaultLocale as n, getLocale as r, getVersionId as t };
|
|
56
|
-
//# sourceMappingURL=index-
|
|
56
|
+
//# sourceMappingURL=index-Bc5qKE7T.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as _$
|
|
1
|
+
import * as _$generaltranslation_internal0 from "generaltranslation/internal";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/locale.d.ts
|
|
4
4
|
/**
|
|
@@ -39,7 +39,7 @@ declare function getDefaultLocale(): string;
|
|
|
39
39
|
* @example
|
|
40
40
|
* const localeProperties = getLocaleProperties('en-US');
|
|
41
41
|
*/
|
|
42
|
-
declare function getLocaleProperties(locale?: string): _$
|
|
42
|
+
declare function getLocaleProperties(locale?: string): _$generaltranslation_internal0.LocaleProperties;
|
|
43
43
|
//#endregion
|
|
44
44
|
//#region src/helpers/versionId.d.ts
|
|
45
45
|
/**
|
|
@@ -53,4 +53,4 @@ declare function getLocaleProperties(locale?: string): _$generaltranslation_type
|
|
|
53
53
|
declare function getVersionId(): string | undefined;
|
|
54
54
|
//#endregion
|
|
55
55
|
export { getLocales as a, getLocaleProperties as i, getDefaultLocale as n, getLocale as r, getVersionId as t };
|
|
56
|
-
//# sourceMappingURL=index-
|
|
56
|
+
//# sourceMappingURL=index-UDlCzB02.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as GTFunctionType, r as MFunctionType } from "./functions-DdlVwVU8.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/translation-functions/fallbacks/gtFallback.d.ts
|
|
4
4
|
/**
|
|
@@ -57,4 +57,4 @@ declare const gtFallback: GTFunctionType;
|
|
|
57
57
|
declare const mFallback: MFunctionType;
|
|
58
58
|
//#endregion
|
|
59
59
|
export { gtFallback as n, mFallback as t };
|
|
60
|
-
//# sourceMappingURL=index-
|
|
60
|
+
//# sourceMappingURL=index-XRxZZ8E4.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as GTFunctionType, r as MFunctionType } from "./functions-DsYQxTQp.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/translation-functions/fallbacks/gtFallback.d.ts
|
|
4
4
|
/**
|
|
@@ -57,4 +57,4 @@ declare const gtFallback: GTFunctionType;
|
|
|
57
57
|
declare const mFallback: MFunctionType;
|
|
58
58
|
//#endregion
|
|
59
59
|
export { gtFallback as n, mFallback as t };
|
|
60
|
-
//# sourceMappingURL=index-
|
|
60
|
+
//# sourceMappingURL=index-v3fx8YUH.d.cts.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_isEncodedTranslationOptions = require("./isEncodedTranslationOptions-D7ltjc4f.cjs");
|
|
3
|
-
const require_versionId = require("./versionId-
|
|
3
|
+
const require_versionId = require("./versionId-qtCCdgKr.cjs");
|
|
4
4
|
const require_mFallback = require("./mFallback-CoPRtKyL.cjs");
|
|
5
5
|
let generaltranslation_internal = require("generaltranslation/internal");
|
|
6
6
|
let generaltranslation_core = require("generaltranslation/core");
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as gtFallback, t as mFallback } from "./index-
|
|
1
|
+
import { s as InlineTranslationOptions } from "./options-C1xolwBY.cjs";
|
|
2
|
+
import { n as gtFallback, t as mFallback } from "./index-v3fx8YUH.cjs";
|
|
3
3
|
import { t as RegisterableMessages } from "./message-C62MTLwE.cjs";
|
|
4
|
-
import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-
|
|
4
|
+
import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-UDlCzB02.cjs";
|
|
5
5
|
import { declareStatic, declareVar, decodeVars, derive } from "generaltranslation/internal";
|
|
6
6
|
|
|
7
7
|
//#region src/translation-functions/t.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as gtFallback, t as mFallback } from "./index-
|
|
1
|
+
import { s as InlineTranslationOptions } from "./options-DeF1NEbe.mjs";
|
|
2
|
+
import { n as gtFallback, t as mFallback } from "./index-XRxZZ8E4.mjs";
|
|
3
3
|
import { t as RegisterableMessages } from "./message-BN4DirTg.mjs";
|
|
4
|
-
import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-
|
|
4
|
+
import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-Bc5qKE7T.mjs";
|
|
5
5
|
import { declareStatic, declareVar, decodeVars, derive } from "generaltranslation/internal";
|
|
6
6
|
|
|
7
7
|
//#region src/translation-functions/t.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as extractVariables, i as createInterpolationFailureMessage, n as decodeOptions, o as logger_default } from "./isEncodedTranslationOptions-DdHEzDDM.mjs";
|
|
2
|
-
import { a as getLocales, d as resolveStringContentWithFallback, i as getLocaleProperties, m as getCurrentLocale, n as getDefaultLocale, r as getLocale, t as getVersionId
|
|
2
|
+
import { S as hashMessage, a as getLocales, d as resolveStringContentWithFallback, i as getLocaleProperties, m as getCurrentLocale, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./versionId-D0t6HuUM.mjs";
|
|
3
3
|
import { n as gtFallback, r as decodeMsg, t as mFallback } from "./mFallback-BQX_yiE-.mjs";
|
|
4
4
|
import { VAR_IDENTIFIER, declareStatic, declareVar, decodeVars, derive, encode, libraryDefaultLocale } from "generaltranslation/internal";
|
|
5
5
|
import { formatMessage } from "generaltranslation/core";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as ConditionStore, c as
|
|
3
|
-
import { a as Dictionary, c as DictionaryLeaf, i as DictionaryLoader, l as
|
|
4
|
-
export { BaseTranslationOptions, type ConditionStore, type ConditionStoreConfig, type Dictionary, type DictionaryEntry, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, type DictionaryOptions, type DictionaryPath, DictionaryTranslationOptions, type DictionaryValue, EncodedTranslationOptions, GTConfig, type I18nManagerConfig, type I18nManagerConstructorParams, InlineResolveOptions, InlineTranslationOptions, JsxTranslationOptions, type LifecycleCallbacks, type LocaleCandidates, LookupOptions, NormalizedLookupOptions, RenderMethod, ResolutionOptions, RuntimeTranslationOptions, type ScopedConditionStore, type TranslationsLoader, type WritableConditionStore };
|
|
1
|
+
import { a as EncodedTranslationOptions, c as JsxTranslationOptions, d as ResolutionOptions, f as RuntimeTranslationOptions, i as DictionaryTranslationOptions, l as LookupOptions, n as DictionaryLookupOptions, o as InlineResolveOptions, r as DictionaryOptions, s as InlineTranslationOptions, t as BaseTranslationOptions, u as NormalizedLookupOptions } from "./options-C1xolwBY.cjs";
|
|
2
|
+
import { a as ConditionStore, c as I18nManagerConfig, d as WritableConditionStore, f as TranslationsLoader, l as I18nManagerConstructorParams, m as RenderMethod, o as ConditionStoreConfig, p as GTConfig, s as DictionaryConfig, t as LocaleCandidates, u as ScopedConditionStore } from "./localeResolver-DcN9SGPs.cjs";
|
|
3
|
+
import { a as Dictionary, c as DictionaryLeaf, d as DictionaryValue, i as DictionaryLoader, l as DictionaryObject, o as DictionaryEntry, r as LifecycleCallbacks, s as DictionaryKey, u as DictionaryPath } from "./TranslationsCache-DQt4Es4G.cjs";
|
|
4
|
+
export { BaseTranslationOptions, type ConditionStore, type ConditionStoreConfig, type Dictionary, type DictionaryConfig, type DictionaryEntry, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, DictionaryLookupOptions, type DictionaryObject, type DictionaryOptions, type DictionaryPath, DictionaryTranslationOptions, type DictionaryValue, EncodedTranslationOptions, GTConfig, type I18nManagerConfig, type I18nManagerConstructorParams, InlineResolveOptions, InlineTranslationOptions, JsxTranslationOptions, type LifecycleCallbacks, type LocaleCandidates, LookupOptions, NormalizedLookupOptions, RenderMethod, ResolutionOptions, RuntimeTranslationOptions, type ScopedConditionStore, type TranslationsLoader, type WritableConditionStore };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as ConditionStore, c as
|
|
3
|
-
import { a as Dictionary, c as DictionaryLeaf, i as DictionaryLoader, l as
|
|
4
|
-
export { BaseTranslationOptions, type ConditionStore, type ConditionStoreConfig, type Dictionary, type DictionaryEntry, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, type DictionaryOptions, type DictionaryPath, DictionaryTranslationOptions, type DictionaryValue, EncodedTranslationOptions, GTConfig, type I18nManagerConfig, type I18nManagerConstructorParams, InlineResolveOptions, InlineTranslationOptions, JsxTranslationOptions, type LifecycleCallbacks, type LocaleCandidates, LookupOptions, NormalizedLookupOptions, RenderMethod, ResolutionOptions, RuntimeTranslationOptions, type ScopedConditionStore, type TranslationsLoader, type WritableConditionStore };
|
|
1
|
+
import { a as EncodedTranslationOptions, c as JsxTranslationOptions, d as ResolutionOptions, f as RuntimeTranslationOptions, i as DictionaryTranslationOptions, l as LookupOptions, n as DictionaryLookupOptions, o as InlineResolveOptions, r as DictionaryOptions, s as InlineTranslationOptions, t as BaseTranslationOptions, u as NormalizedLookupOptions } from "./options-DeF1NEbe.mjs";
|
|
2
|
+
import { a as ConditionStore, c as I18nManagerConfig, d as WritableConditionStore, f as TranslationsLoader, l as I18nManagerConstructorParams, m as RenderMethod, o as ConditionStoreConfig, p as GTConfig, s as DictionaryConfig, t as LocaleCandidates, u as ScopedConditionStore } from "./localeResolver-DPayN_xR.mjs";
|
|
3
|
+
import { a as Dictionary, c as DictionaryLeaf, d as DictionaryValue, i as DictionaryLoader, l as DictionaryObject, o as DictionaryEntry, r as LifecycleCallbacks, s as DictionaryKey, u as DictionaryPath } from "./TranslationsCache-DdoHhP9C.mjs";
|
|
4
|
+
export { BaseTranslationOptions, type ConditionStore, type ConditionStoreConfig, type Dictionary, type DictionaryConfig, type DictionaryEntry, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, DictionaryLookupOptions, type DictionaryObject, type DictionaryOptions, type DictionaryPath, DictionaryTranslationOptions, type DictionaryValue, EncodedTranslationOptions, GTConfig, type I18nManagerConfig, type I18nManagerConstructorParams, InlineResolveOptions, InlineTranslationOptions, JsxTranslationOptions, type LifecycleCallbacks, type LocaleCandidates, LookupOptions, NormalizedLookupOptions, RenderMethod, ResolutionOptions, RuntimeTranslationOptions, type ScopedConditionStore, type TranslationsLoader, type WritableConditionStore };
|
package/dist/internal.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_isEncodedTranslationOptions = require("./isEncodedTranslationOptions-D7ltjc4f.cjs");
|
|
3
|
-
const require_versionId = require("./versionId-
|
|
3
|
+
const require_versionId = require("./versionId-qtCCdgKr.cjs");
|
|
4
4
|
let generaltranslation_internal = require("generaltranslation/internal");
|
|
5
5
|
let generaltranslation_core = require("generaltranslation/core");
|
|
6
6
|
//#region src/translation-functions/internal/getGT.ts
|
|
@@ -91,24 +91,21 @@ async function getMessages() {
|
|
|
91
91
|
* @returns A promise of the t function
|
|
92
92
|
* @important Must be used inside of a request context
|
|
93
93
|
*
|
|
94
|
-
* @deprecated not yet supported
|
|
95
|
-
*
|
|
96
94
|
* @example
|
|
97
95
|
* const t = await getTranslations();
|
|
98
96
|
* const title = await t('page.title');
|
|
99
97
|
*/
|
|
100
98
|
async function getTranslations() {
|
|
99
|
+
const i18nManager = require_versionId.getI18nManager();
|
|
100
|
+
const locale = require_versionId.getCurrentLocale();
|
|
101
|
+
await i18nManager.loadDictionary(locale);
|
|
102
|
+
const sourceLocale = i18nManager.getDefaultLocale();
|
|
101
103
|
/**
|
|
102
104
|
* Dictionary resolution
|
|
103
105
|
* @param {string} id - The id of the translation to translate.
|
|
104
|
-
* @param {DictionaryTranslationOptions} options - The options for
|
|
106
|
+
* @param {DictionaryTranslationOptions} options - The options for interpolation.
|
|
105
107
|
* @returns {string} The translated message.
|
|
106
108
|
*
|
|
107
|
-
* @deprecated not yet supported
|
|
108
|
-
*
|
|
109
|
-
* This is a placeholder for the t() function.
|
|
110
|
-
* TODO: Implement the t() function.
|
|
111
|
-
*
|
|
112
109
|
* @example
|
|
113
110
|
* // Simple dictionary lookup without interpolation
|
|
114
111
|
* const t = await getTranslations();
|
|
@@ -119,11 +116,78 @@ async function getTranslations() {
|
|
|
119
116
|
* const t = await getTranslations();
|
|
120
117
|
* const greeting = t('user.greeting', { name: 'Bob' });
|
|
121
118
|
*/
|
|
122
|
-
const t = (
|
|
123
|
-
|
|
119
|
+
const t = ((id, options = {}) => {
|
|
120
|
+
const sourceEntry = i18nManager.lookupDictionary(sourceLocale, id);
|
|
121
|
+
if (sourceEntry === void 0) throw new Error(`Dictionary entry ${id} cannot be found`);
|
|
122
|
+
return renderEntry({
|
|
123
|
+
sourceLocale,
|
|
124
|
+
targetLocale: locale,
|
|
125
|
+
sourceEntry,
|
|
126
|
+
targetEntry: i18nManager.lookupDictionary(locale, id),
|
|
127
|
+
options
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
t.obj = (id) => {
|
|
131
|
+
const sourceObject = i18nManager.lookupDictionaryObj(sourceLocale, id);
|
|
132
|
+
if (sourceObject === void 0) throw new Error(`Dictionary entry ${id} cannot be found`);
|
|
133
|
+
return renderObject({
|
|
134
|
+
sourceObject,
|
|
135
|
+
targetObject: i18nManager.lookupDictionaryObj(locale, id)
|
|
136
|
+
});
|
|
124
137
|
};
|
|
125
138
|
return t;
|
|
126
139
|
}
|
|
140
|
+
function renderEntry({ sourceLocale, targetLocale, sourceEntry, targetEntry, options = {} }) {
|
|
141
|
+
const dictionaryOptions = require_versionId.resolveDictionaryLookupOptions(sourceEntry.options);
|
|
142
|
+
const interpolationOptions = require_isEncodedTranslationOptions.extractVariables(options);
|
|
143
|
+
const lookupOptions = require_versionId.createLookupOptions(targetLocale, {
|
|
144
|
+
...dictionaryOptions,
|
|
145
|
+
...interpolationOptions
|
|
146
|
+
}, dictionaryOptions.$format ?? "ICU");
|
|
147
|
+
return require_versionId.interpolateMessage({
|
|
148
|
+
source: sourceEntry.entry,
|
|
149
|
+
target: targetEntry?.entry,
|
|
150
|
+
options: lookupOptions,
|
|
151
|
+
sourceLocale
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function renderObject({ sourceObject, targetObject }) {
|
|
155
|
+
const targetEntry = require_versionId.getDictionaryEntry(targetObject);
|
|
156
|
+
if (targetEntry !== void 0) return targetEntry.entry;
|
|
157
|
+
if (require_versionId.isDictionaryValue(targetObject)) {
|
|
158
|
+
if (!require_versionId.isDictionaryValue(sourceObject)) return renderObject({
|
|
159
|
+
sourceObject: targetObject,
|
|
160
|
+
targetObject: void 0
|
|
161
|
+
});
|
|
162
|
+
return renderDictionaryObject({
|
|
163
|
+
sourceObject,
|
|
164
|
+
targetObject
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const sourceEntry = require_versionId.getDictionaryEntry(sourceObject);
|
|
168
|
+
if (sourceEntry !== void 0) return sourceEntry.entry;
|
|
169
|
+
if (require_versionId.isDictionaryValue(sourceObject)) return renderDictionaryObject({
|
|
170
|
+
sourceObject,
|
|
171
|
+
targetObject: void 0
|
|
172
|
+
});
|
|
173
|
+
throw new Error("Dictionary object cannot be rendered");
|
|
174
|
+
}
|
|
175
|
+
function renderDictionaryObject({ sourceObject, targetObject }) {
|
|
176
|
+
if (!require_versionId.isDictionaryValue(sourceObject)) return renderObject({
|
|
177
|
+
sourceObject,
|
|
178
|
+
targetObject
|
|
179
|
+
});
|
|
180
|
+
const result = {};
|
|
181
|
+
const keys = new Set([...Object.keys(sourceObject), ...require_versionId.isDictionaryValue(targetObject) ? Object.keys(targetObject) : []]);
|
|
182
|
+
for (const key of keys) {
|
|
183
|
+
const renderedChild = renderObject({
|
|
184
|
+
sourceObject: sourceObject[key],
|
|
185
|
+
targetObject: require_versionId.isDictionaryValue(targetObject) ? targetObject[key] : void 0
|
|
186
|
+
});
|
|
187
|
+
if (renderedChild !== void 0) result[key] = renderedChild;
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
127
191
|
//#endregion
|
|
128
192
|
//#region src/translation-functions/internal/tx.ts
|
|
129
193
|
/**
|
package/dist/internal.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.cjs","names":["getI18nManager","getCurrentLocale","createLookupOptions","interpolateMessage","decodeOptions","isEncodedTranslationOptions","resolveStringContentWithRuntimeFallback","getCurrentLocale","resolveStringContent","resolveStringContentWithFallback","resolveJsx","setConditionStore","libraryDefaultLocale","LocaleConfig"],"sources":["../src/translation-functions/internal/getGT.ts","../src/translation-functions/internal/getMessages.ts","../src/translation-functions/internal/getTranslations.ts","../src/translation-functions/internal/tx.ts","../src/translation-functions/internal/sync-translation-resolution.ts","../src/translation-functions/internal/jsx-resolution.ts","../src/i18n-manager/condition-store/createConditionStoreSingleton.ts","../src/i18n-manager/condition-store/localeResolver.ts"],"sourcesContent":["import {\n getCurrentLocale,\n getI18nManager,\n} from '../../i18n-manager/singleton-operations';\nimport { InlineTranslationOptions } from '../types/options';\nimport { GTFunctionType } from '../types/functions';\nimport { interpolateMessage } from '../utils/interpolation/interpolateMessage';\nimport { createLookupOptions } from './helpers';\nimport type { StringFormat } from 'generaltranslation/types';\n\n/**\n * Returns the gt function that registers a string at build time and resolves its translation at runtime.\n * @returns A promise of the gt function\n *\n * @example\n * const gt = await getGT();\n * const greeting = gt('Hello, world!');\n */\nexport async function getGT(): Promise<GTFunctionType> {\n // Get the translation resolver\n const i18nManager = getI18nManager();\n const locale = getCurrentLocale();\n await i18nManager.loadTranslations(locale);\n const sourceLocale = i18nManager.getDefaultLocale();\n\n /**\n * Registers a message at build time and resolves its translation at runtime.\n * @param {string} message - The message to translate\n * @param {InlineTranslationOptions} options - The options for the translation\n * @returns The translated message\n *\n * @example\n * // Simple translation without interpolation\n * const gt = await getGT();\n * const greeting = gt('Hello, world!');\n *\n * @example\n * // Translation with interpolation\n * const gt = await getGT();\n * const welcome = gt('Hello, {name}!', { name: 'Alice' });\n */\n const gt: GTFunctionType = (\n message: string,\n options: InlineTranslationOptions = {}\n ) => {\n const targetLocale = options.$locale ?? locale;\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n options,\n 'ICU'\n );\n\n // Lookup translation\n const translation = i18nManager.lookupTranslation(\n lookupOptions.$locale,\n message,\n lookupOptions\n );\n\n // Format result\n return interpolateMessage({\n source: message,\n target: translation,\n options: lookupOptions,\n sourceLocale,\n });\n };\n\n return gt;\n}\n","import { InlineResolveOptions } from '../types/options';\nimport { decodeOptions } from '../msg/decodeOptions';\nimport { isEncodedTranslationOptions } from '../utils/isEncodedTranslationOptions';\nimport { getGT } from './getGT';\nimport { MFunctionType } from '../types/functions';\n\n/**\n * Returns the m function that resolves a registered message to its translation.\n * @returns A promise of the m function\n *\n * @example\n * // Registration\n * const registeredMessage = msg('Hello, world!');\n *\n * // Resolution\n * const m = await getMessages();\n * const greeting = m(registeredMessage);\n */\nexport async function getMessages(): Promise<MFunctionType> {\n // Get the gt function\n const gt = await getGT();\n\n /**\n * Resolves a registered message to its translation.\n * @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.\n * @param {InlineTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @example\n * // Simple message without interpolation\n * const m = await getMessages();\n * const greeting = m(msg('Hello, world!'));\n *\n * @example\n * // Message with interpolation\n * const m = await getMessages();\n * const welcome = m(msg('Welcome, {user}!'), { user: 'Alice' });\n */\n const m: MFunctionType = <T extends string | null | undefined>(\n encodedMsg: T,\n options: InlineResolveOptions = {}\n ): T extends string ? string : T => {\n // Return if the encoded message is null or undefined\n if (encodedMsg == null) return encodedMsg as T extends string ? string : T;\n\n // Get any encoded options\n const decodedOptions = decodeOptions(encodedMsg) ?? {};\n\n // Return early if string already interpolated eg: mFallback(msg('Hello, {name}!', { name: 'Brian' }))\n if (isEncodedTranslationOptions(decodedOptions)) {\n return gt(decodedOptions.$_source, decodedOptions) as T extends string\n ? string\n : T;\n }\n\n // Use gt to interpolate\n // Separate from decoded options to match behavior in @gt/react-core\n return gt(encodedMsg, options) as T extends string ? string : T;\n };\n\n return m;\n}\n","import { DictionaryTranslationOptions } from '../types/options';\nimport { TFunctionType } from '../types/functions';\n\n/**\n * Returns the t function that translates a dictionary entry based on its id and options.\n * @returns A promise of the t function\n * @important Must be used inside of a request context\n *\n * @deprecated not yet supported\n *\n * @example\n * const t = await getTranslations();\n * const title = await t('page.title');\n */\nexport async function getTranslations(): Promise<TFunctionType> {\n /**\n * Dictionary resolution\n * @param {string} id - The id of the translation to translate.\n * @param {DictionaryTranslationOptions} options - The options for the translation.\n * @returns {string} The translated message.\n *\n * @deprecated not yet supported\n *\n * This is a placeholder for the t() function.\n * TODO: Implement the t() function.\n *\n * @example\n * // Simple dictionary lookup without interpolation\n * const t = await getTranslations();\n * const title = t('page.title');\n *\n * @example\n * // Dictionary lookup with interpolation\n * const t = await getTranslations();\n * const greeting = t('user.greeting', { name: 'Bob' });\n */\n const t: TFunctionType = (\n _id: string,\n _options?: DictionaryTranslationOptions\n ): string => {\n throw new Error('t() is not implemented');\n };\n\n return t;\n}\n","import { RuntimeTranslationOptions } from '../types/options';\nimport type { StringFormat } from 'generaltranslation/types';\nimport { resolveStringContentWithRuntimeFallback } from './helpers';\nimport { getCurrentLocale } from '../../i18n-manager/singleton-operations';\n\ntype RuntimeTranslationOptionsWithFormat = Omit<\n RuntimeTranslationOptions,\n '$format'\n> & {\n $format?: StringFormat;\n};\n\n/**\n * Translates a message at runtime.\n * @param {string} message - The message to translate.\n * @param {RuntimeTranslationOptions} options - The options for the translation.\n * @returns {Promise<string>} The translated message.\n *\n * @example\n * // Simple runtime translation without interpolation\n * const status = await tx('Processing complete', { $locale: 'es-MX' });\n *\n * @example\n * // Runtime translation with interpolation\n * const progress = await tx(`Processing ${status}`, { $locale: 'es-MX' });\n */\nexport async function tx(\n content: string,\n options: RuntimeTranslationOptionsWithFormat = {}\n): Promise<string> {\n const locale = options.$locale ?? getCurrentLocale();\n return resolveStringContentWithRuntimeFallback(locale, content, {\n $format: 'STRING',\n ...options,\n });\n}\n","import { InlineTranslationOptions } from '../types/options';\nimport {\n resolveStringContent,\n resolveStringContentWithFallback,\n} from './helpers';\n\n/**\n * Synchronously resolve a translation for a given message and options\n * @param {string} message - The message to translate.\n * @param {InlineTranslationOptions} [options] - The options for the translation.\n * @returns {string | undefined} The translated message or undefined if the message is not found.\n * @deprecated use resolveTranslation instead\n */\nexport function resolveTranslationSync(\n locale: string,\n message: string,\n options: InlineTranslationOptions = {}\n) {\n return resolveStringContent(locale, message, { $format: 'ICU', ...options });\n}\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {InlineTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message or the original message interpolated if the translation is not found.\n * @deprecated use resolveTranslationWithFallback instead\n */\nexport function resolveTranslationSyncWithFallback(\n locale: string,\n message: string,\n options: InlineTranslationOptions = {}\n) {\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...options,\n });\n}\n","import { JsxChildren } from 'generaltranslation/types';\nimport { JsxTranslationOptions } from '../types/options';\nimport { resolveJsx } from './helpers';\n\n/**\n * Given a JsxChildren and any associated metadata needed for a hash calculation, resolve the associated translation.\n * @deprecated use resolveJsx instead\n */\nexport function resolveJsxTranslation(\n locale: string,\n children: JsxChildren,\n options: JsxTranslationOptions = {}\n) {\n return resolveJsx(locale, children, options);\n}\n","import type { ConditionStore } from '../types';\nimport { setConditionStore as setCurrentConditionStore } from '../singleton-operations';\n\nexport function createConditionStoreSingleton<T extends ConditionStore>(\n notInitializedMessage: string\n) {\n let conditionStore: T | undefined;\n\n function getConditionStore(): T {\n if (!conditionStore) {\n throw new Error(notInitializedMessage);\n }\n return conditionStore;\n }\n\n function setConditionStore(nextConditionStore: T): void {\n conditionStore = nextConditionStore;\n setCurrentConditionStore(nextConditionStore);\n }\n\n return {\n getConditionStore,\n setConditionStore,\n };\n}\n","import { LocaleConfig } from 'generaltranslation/core';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport type { ConditionStoreConfig } from '../types';\n\nexport type LocaleCandidates = string | string[] | undefined;\n\nfunction normalizeConditionStoreConfig({\n defaultLocale,\n locales,\n customMapping,\n}: ConditionStoreConfig = {}) {\n const fallbackLocale = defaultLocale || libraryDefaultLocale;\n return {\n defaultLocale: fallbackLocale,\n locales: locales?.length ? locales : [fallbackLocale],\n customMapping,\n };\n}\n\ntype NormalizedConditionStoreConfig = ReturnType<\n typeof normalizeConditionStoreConfig\n>;\n\n/**\n * Return the best supported locale for the candidates, or undefined when none match.\n */\nexport function determineSupportedLocale(\n candidates: LocaleCandidates,\n config: ConditionStoreConfig = {}\n): string | undefined {\n return determineSupportedLocaleWithConfig(\n candidates,\n normalizeConditionStoreConfig(config)\n );\n}\n\nfunction determineSupportedLocaleWithConfig(\n candidates: LocaleCandidates,\n config: NormalizedConditionStoreConfig\n): string | undefined {\n if (\n candidates == null ||\n (Array.isArray(candidates) && candidates.length === 0)\n ) {\n return undefined;\n }\n\n const localeConfig = new LocaleConfig(config);\n return localeConfig.determineLocale(candidates) || undefined;\n}\n\n/**\n * Return the best supported locale for the candidates, falling back to the default locale.\n */\nexport function resolveSupportedLocale(\n candidates: LocaleCandidates,\n config: ConditionStoreConfig = {}\n): string {\n const normalizedConfig = normalizeConditionStoreConfig(config);\n return (\n determineSupportedLocaleWithConfig(candidates, normalizedConfig) ||\n normalizedConfig.defaultLocale\n );\n}\n\nexport function createLocaleResolver(config: ConditionStoreConfig = {}) {\n const normalizedConfig = normalizeConditionStoreConfig(config);\n return (candidates?: LocaleCandidates): string =>\n determineSupportedLocaleWithConfig(candidates, normalizedConfig) ||\n normalizedConfig.defaultLocale;\n}\n"],"mappings":";;;;;;;;;;;;;;AAkBA,eAAsB,QAAiC;CAErD,MAAM,cAAcA,kBAAAA,gBAAgB;CACpC,MAAM,SAASC,kBAAAA,kBAAkB;AACjC,OAAM,YAAY,iBAAiB,OAAO;CAC1C,MAAM,eAAe,YAAY,kBAAkB;;;;;;;;;;;;;;;;;CAkBnD,MAAM,MACJ,SACA,UAAoC,EAAE,KACnC;EAEH,MAAM,gBAAgBC,kBAAAA,oBADD,QAAQ,WAAW,QAGtC,SACA,MACD;AAUD,SAAOC,kBAAAA,mBAAmB;GACxB,QAAQ;GACR,QATkB,YAAY,kBAC9B,cAAc,SACd,SACA,cAMmB;GACnB,SAAS;GACT;GACD,CAAC;;AAGJ,QAAO;;;;;;;;;;;;;;;;AClDT,eAAsB,cAAsC;CAE1D,MAAM,KAAK,MAAM,OAAO;;;;;;;;;;;;;;;;;CAkBxB,MAAM,KACJ,YACA,UAAgC,EAAE,KACA;AAElC,MAAI,cAAc,KAAM,QAAO;EAG/B,MAAM,iBAAiBC,oCAAAA,cA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,eAAe;EACrD;EACD;;;;;AAUH,SAAgB,yBACd,YACA,SAA+B,EAAE,EACb;AACpB,QAAO,mCACL,YACA,8BAA8B,OAAO,CACtC;;AAGH,SAAS,mCACP,YACA,QACoB;AACpB,KACE,cAAc,QACb,MAAM,QAAQ,WAAW,IAAI,WAAW,WAAW,EAEpD;AAIF,QAAO,IADkBC,wBAAAA,aAAa,OACnB,CAAC,gBAAgB,WAAW,IAAI,KAAA;;;;;AAMrD,SAAgB,uBACd,YACA,SAA+B,EAAE,EACzB;CACR,MAAM,mBAAmB,8BAA8B,OAAO;AAC9D,QACE,mCAAmC,YAAY,iBAAiB,IAChE,iBAAiB;;AAIrB,SAAgB,qBAAqB,SAA+B,EAAE,EAAE;CACtE,MAAM,mBAAmB,8BAA8B,OAAO;AAC9D,SAAQ,eACN,mCAAmC,YAAY,iBAAiB,IAChE,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"internal.cjs","names":["getI18nManager","getCurrentLocale","createLookupOptions","interpolateMessage","decodeOptions","isEncodedTranslationOptions","getI18nManager","getCurrentLocale","resolveDictionaryLookupOptions","extractVariables","createLookupOptions","interpolateMessage","getDictionaryEntry","isDictionaryValue","resolveStringContentWithRuntimeFallback","getCurrentLocale","resolveStringContent","resolveStringContentWithFallback","resolveJsx","setConditionStore","libraryDefaultLocale","LocaleConfig"],"sources":["../src/translation-functions/internal/getGT.ts","../src/translation-functions/internal/getMessages.ts","../src/translation-functions/internal/getTranslations.ts","../src/translation-functions/internal/tx.ts","../src/translation-functions/internal/sync-translation-resolution.ts","../src/translation-functions/internal/jsx-resolution.ts","../src/i18n-manager/condition-store/createConditionStoreSingleton.ts","../src/i18n-manager/condition-store/localeResolver.ts"],"sourcesContent":["import {\n getCurrentLocale,\n getI18nManager,\n} from '../../i18n-manager/singleton-operations';\nimport { InlineTranslationOptions } from '../types/options';\nimport { GTFunctionType } from '../types/functions';\nimport { interpolateMessage } from '../utils/interpolation/interpolateMessage';\nimport { createLookupOptions } from './helpers';\nimport type { StringFormat } from 'generaltranslation/types';\n\n/**\n * Returns the gt function that registers a string at build time and resolves its translation at runtime.\n * @returns A promise of the gt function\n *\n * @example\n * const gt = await getGT();\n * const greeting = gt('Hello, world!');\n */\nexport async function getGT(): Promise<GTFunctionType> {\n // Get the translation resolver\n const i18nManager = getI18nManager();\n const locale = getCurrentLocale();\n await i18nManager.loadTranslations(locale);\n const sourceLocale = i18nManager.getDefaultLocale();\n\n /**\n * Registers a message at build time and resolves its translation at runtime.\n * @param {string} message - The message to translate\n * @param {InlineTranslationOptions} options - The options for the translation\n * @returns The translated message\n *\n * @example\n * // Simple translation without interpolation\n * const gt = await getGT();\n * const greeting = gt('Hello, world!');\n *\n * @example\n * // Translation with interpolation\n * const gt = await getGT();\n * const welcome = gt('Hello, {name}!', { name: 'Alice' });\n */\n const gt: GTFunctionType = (\n message: string,\n options: InlineTranslationOptions = {}\n ) => {\n const targetLocale = options.$locale ?? locale;\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n options,\n 'ICU'\n );\n\n // Lookup translation\n const translation = i18nManager.lookupTranslation(\n lookupOptions.$locale,\n message,\n lookupOptions\n );\n\n // Format result\n return interpolateMessage({\n source: message,\n target: translation,\n options: lookupOptions,\n sourceLocale,\n });\n };\n\n return gt;\n}\n","import { InlineResolveOptions } from '../types/options';\nimport { decodeOptions } from '../msg/decodeOptions';\nimport { isEncodedTranslationOptions } from '../utils/isEncodedTranslationOptions';\nimport { getGT } from './getGT';\nimport { MFunctionType } from '../types/functions';\n\n/**\n * Returns the m function that resolves a registered message to its translation.\n * @returns A promise of the m function\n *\n * @example\n * // Registration\n * const registeredMessage = msg('Hello, world!');\n *\n * // Resolution\n * const m = await getMessages();\n * const greeting = m(registeredMessage);\n */\nexport async function getMessages(): Promise<MFunctionType> {\n // Get the gt function\n const gt = await getGT();\n\n /**\n * Resolves a registered message to its translation.\n * @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.\n * @param {InlineTranslationOptions} options - The options to interpolate.\n * @returns - The decoded and interpolated message.\n *\n * @example\n * // Simple message without interpolation\n * const m = await getMessages();\n * const greeting = m(msg('Hello, world!'));\n *\n * @example\n * // Message with interpolation\n * const m = await getMessages();\n * const welcome = m(msg('Welcome, {user}!'), { user: 'Alice' });\n */\n const m: MFunctionType = <T extends string | null | undefined>(\n encodedMsg: T,\n options: InlineResolveOptions = {}\n ): T extends string ? string : T => {\n // Return if the encoded message is null or undefined\n if (encodedMsg == null) return encodedMsg as T extends string ? string : T;\n\n // Get any encoded options\n const decodedOptions = decodeOptions(encodedMsg) ?? {};\n\n // Return early if string already interpolated eg: mFallback(msg('Hello, {name}!', { name: 'Brian' }))\n if (isEncodedTranslationOptions(decodedOptions)) {\n return gt(decodedOptions.$_source, decodedOptions) as T extends string\n ? string\n : T;\n }\n\n // Use gt to interpolate\n // Separate from decoded options to match behavior in @gt/react-core\n return gt(encodedMsg, options) as T extends string ? string : T;\n };\n\n return m;\n}\n","import {\n getCurrentLocale,\n getI18nManager,\n} from '../../i18n-manager/singleton-operations';\nimport { DictionaryTranslationOptions } from '../types/options';\nimport { TFunctionType } from '../types/functions';\nimport { interpolateMessage } from '../utils/interpolation/interpolateMessage';\nimport { createLookupOptions } from './helpers';\nimport { extractVariables } from '../../utils/extractVariables';\nimport type { StringFormat } from 'generaltranslation/types';\nimport type {\n DictionaryEntry,\n DictionaryValue,\n} from '../../i18n-manager/translations-manager/DictionaryCache';\nimport {\n getDictionaryEntry,\n isDictionaryValue,\n resolveDictionaryLookupOptions,\n} from '../../i18n-manager/translations-manager/utils/dictionary-helpers';\nimport type { DictionaryObjectTranslation } from '../types/functions';\n\n/**\n * Returns the t function that translates a dictionary entry based on its id and options.\n * @returns A promise of the t function\n * @important Must be used inside of a request context\n *\n * @example\n * const t = await getTranslations();\n * const title = await t('page.title');\n */\nexport async function getTranslations(): Promise<TFunctionType> {\n const i18nManager = getI18nManager();\n const locale = getCurrentLocale();\n await i18nManager.loadDictionary(locale);\n const sourceLocale = i18nManager.getDefaultLocale();\n\n /**\n * Dictionary resolution\n * @param {string} id - The id of the translation to translate.\n * @param {DictionaryTranslationOptions} options - The options for interpolation.\n * @returns {string} The translated message.\n *\n * @example\n * // Simple dictionary lookup without interpolation\n * const t = await getTranslations();\n * const title = t('page.title');\n *\n * @example\n * // Dictionary lookup with interpolation\n * const t = await getTranslations();\n * const greeting = t('user.greeting', { name: 'Bob' });\n */\n const t = ((\n id: string,\n options: DictionaryTranslationOptions = {}\n ): string => {\n const sourceEntry = i18nManager.lookupDictionary(sourceLocale, id);\n if (sourceEntry === undefined) {\n throw new Error(`Dictionary entry ${id} cannot be found`);\n }\n const targetEntry = i18nManager.lookupDictionary(locale, id);\n return renderEntry({\n sourceLocale,\n targetLocale: locale,\n sourceEntry,\n targetEntry,\n options,\n });\n }) as TFunctionType;\n\n t.obj = (id: string): DictionaryObjectTranslation => {\n const sourceObject = i18nManager.lookupDictionaryObj(sourceLocale, id);\n if (sourceObject === undefined) {\n throw new Error(`Dictionary entry ${id} cannot be found`);\n }\n const targetObject = i18nManager.lookupDictionaryObj(locale, id);\n return renderObject({ sourceObject, targetObject });\n };\n\n return t;\n}\n\nfunction renderEntry({\n sourceLocale,\n targetLocale,\n sourceEntry,\n targetEntry,\n options = {},\n}: {\n sourceLocale: string;\n targetLocale: string;\n sourceEntry: DictionaryEntry;\n targetEntry: DictionaryEntry | undefined;\n options?: DictionaryTranslationOptions;\n}): string {\n const dictionaryOptions = resolveDictionaryLookupOptions(sourceEntry.options);\n const interpolationOptions = extractVariables(options);\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n {\n ...dictionaryOptions,\n ...interpolationOptions,\n },\n dictionaryOptions.$format ?? 'ICU'\n );\n\n return interpolateMessage({\n source: sourceEntry.entry,\n target: targetEntry?.entry,\n options: lookupOptions,\n sourceLocale,\n });\n}\n\nfunction renderObject({\n sourceObject,\n targetObject,\n}: {\n sourceObject: DictionaryValue | undefined;\n targetObject: DictionaryValue | undefined;\n}): DictionaryObjectTranslation {\n const targetEntry = getDictionaryEntry(targetObject);\n if (targetEntry !== undefined) {\n return targetEntry.entry;\n }\n\n if (isDictionaryValue(targetObject)) {\n if (!isDictionaryValue(sourceObject)) {\n return renderObject({\n sourceObject: targetObject,\n targetObject: undefined,\n });\n }\n\n return renderDictionaryObject({\n sourceObject,\n targetObject,\n });\n }\n\n const sourceEntry = getDictionaryEntry(sourceObject);\n if (sourceEntry !== undefined) {\n return sourceEntry.entry;\n }\n\n if (isDictionaryValue(sourceObject)) {\n return renderDictionaryObject({\n sourceObject,\n targetObject: undefined,\n });\n }\n\n throw new Error('Dictionary object cannot be rendered');\n}\n\nfunction renderDictionaryObject({\n sourceObject,\n targetObject,\n}: {\n sourceObject: DictionaryValue;\n targetObject: DictionaryValue | undefined;\n}): DictionaryObjectTranslation {\n if (!isDictionaryValue(sourceObject)) {\n return renderObject({ sourceObject, targetObject });\n }\n const result: Record<string, DictionaryObjectTranslation> = {};\n const keys = new Set([\n ...Object.keys(sourceObject),\n ...(isDictionaryValue(targetObject) ? Object.keys(targetObject) : []),\n ]);\n\n for (const key of keys) {\n const renderedChild = renderObject({\n sourceObject: sourceObject[key],\n targetObject: isDictionaryValue(targetObject)\n ? targetObject[key]\n : undefined,\n });\n if (renderedChild !== undefined) {\n result[key] = renderedChild;\n }\n }\n\n return result;\n}\n","import { RuntimeTranslationOptions } from '../types/options';\nimport type { StringFormat } from 'generaltranslation/types';\nimport { resolveStringContentWithRuntimeFallback } from './helpers';\nimport { getCurrentLocale } from '../../i18n-manager/singleton-operations';\n\ntype RuntimeTranslationOptionsWithFormat = Omit<\n RuntimeTranslationOptions,\n '$format'\n> & {\n $format?: StringFormat;\n};\n\n/**\n * Translates a message at runtime.\n * @param {string} message - The message to translate.\n * @param {RuntimeTranslationOptions} options - The options for the translation.\n * @returns {Promise<string>} The translated message.\n *\n * @example\n * // Simple runtime translation without interpolation\n * const status = await tx('Processing complete', { $locale: 'es-MX' });\n *\n * @example\n * // Runtime translation with interpolation\n * const progress = await tx(`Processing ${status}`, { $locale: 'es-MX' });\n */\nexport async function tx(\n content: string,\n options: RuntimeTranslationOptionsWithFormat = {}\n): Promise<string> {\n const locale = options.$locale ?? getCurrentLocale();\n return resolveStringContentWithRuntimeFallback(locale, content, {\n $format: 'STRING',\n ...options,\n });\n}\n","import { InlineTranslationOptions } from '../types/options';\nimport {\n resolveStringContent,\n resolveStringContentWithFallback,\n} from './helpers';\n\n/**\n * Synchronously resolve a translation for a given message and options\n * @param {string} message - The message to translate.\n * @param {InlineTranslationOptions} [options] - The options for the translation.\n * @returns {string | undefined} The translated message or undefined if the message is not found.\n * @deprecated use resolveTranslation instead\n */\nexport function resolveTranslationSync(\n locale: string,\n message: string,\n options: InlineTranslationOptions = {}\n) {\n return resolveStringContent(locale, message, { $format: 'ICU', ...options });\n}\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {InlineTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message or the original message interpolated if the translation is not found.\n * @deprecated use resolveTranslationWithFallback instead\n */\nexport function resolveTranslationSyncWithFallback(\n locale: string,\n message: string,\n options: InlineTranslationOptions = {}\n) {\n return resolveStringContentWithFallback(locale, message, {\n $format: 'ICU',\n ...options,\n });\n}\n","import { JsxChildren } from 'generaltranslation/types';\nimport { JsxTranslationOptions } from '../types/options';\nimport { resolveJsx } from './helpers';\n\n/**\n * Given a JsxChildren and any associated metadata needed for a hash calculation, resolve the associated translation.\n * @deprecated use resolveJsx instead\n */\nexport function resolveJsxTranslation(\n locale: string,\n children: JsxChildren,\n options: JsxTranslationOptions = {}\n) {\n return resolveJsx(locale, children, options);\n}\n","import type { ConditionStore } from '../types';\nimport { setConditionStore as setCurrentConditionStore } from '../singleton-operations';\n\nexport function createConditionStoreSingleton<T extends ConditionStore>(\n notInitializedMessage: string\n) {\n let conditionStore: T | undefined;\n\n function getConditionStore(): T {\n if (!conditionStore) {\n throw new Error(notInitializedMessage);\n }\n return conditionStore;\n }\n\n function setConditionStore(nextConditionStore: T): void {\n conditionStore = nextConditionStore;\n setCurrentConditionStore(nextConditionStore);\n }\n\n return {\n getConditionStore,\n setConditionStore,\n };\n}\n","import { LocaleConfig } from 'generaltranslation/core';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport type { ConditionStoreConfig } from '../types';\n\nexport type LocaleCandidates = string | string[] | undefined;\n\nfunction normalizeConditionStoreConfig({\n defaultLocale,\n locales,\n customMapping,\n}: ConditionStoreConfig = {}) {\n const fallbackLocale = defaultLocale || libraryDefaultLocale;\n return {\n defaultLocale: fallbackLocale,\n locales: locales?.length ? locales : [fallbackLocale],\n customMapping,\n };\n}\n\ntype NormalizedConditionStoreConfig = ReturnType<\n typeof normalizeConditionStoreConfig\n>;\n\n/**\n * Return the best supported locale for the candidates, or undefined when none match.\n */\nexport function determineSupportedLocale(\n candidates: LocaleCandidates,\n config: ConditionStoreConfig = {}\n): string | undefined {\n return determineSupportedLocaleWithConfig(\n candidates,\n normalizeConditionStoreConfig(config)\n );\n}\n\nfunction determineSupportedLocaleWithConfig(\n candidates: LocaleCandidates,\n config: NormalizedConditionStoreConfig\n): string | undefined {\n if (\n candidates == null ||\n (Array.isArray(candidates) && candidates.length === 0)\n ) {\n return undefined;\n }\n\n const localeConfig = new LocaleConfig(config);\n return localeConfig.determineLocale(candidates) || undefined;\n}\n\n/**\n * Return the best supported locale for the candidates, falling back to the default locale.\n */\nexport function resolveSupportedLocale(\n candidates: LocaleCandidates,\n config: ConditionStoreConfig = {}\n): string {\n const normalizedConfig = normalizeConditionStoreConfig(config);\n return (\n determineSupportedLocaleWithConfig(candidates, normalizedConfig) ||\n normalizedConfig.defaultLocale\n );\n}\n\nexport function createLocaleResolver(config: ConditionStoreConfig = {}) {\n const normalizedConfig = normalizeConditionStoreConfig(config);\n return (candidates?: LocaleCandidates): string =>\n determineSupportedLocaleWithConfig(candidates, normalizedConfig) ||\n normalizedConfig.defaultLocale;\n}\n"],"mappings":";;;;;;;;;;;;;;AAkBA,e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BAAiBC,4BAAAA;AACxC,QAAO;EACL,eAAe;EACf,SAAS,SAAS,SAAS,UAAU,CAAC,eAAe;EACrD;EACD;;;;;AAUH,SAAgB,yBACd,YACA,SAA+B,EAAE,EACb;AACpB,QAAO,mCACL,YACA,8BAA8B,OAAO,CACtC;;AAGH,SAAS,mCACP,YACA,QACoB;AACpB,KACE,cAAc,QACb,MAAM,QAAQ,WAAW,IAAI,WAAW,WAAW,EAEpD;AAIF,QAAO,IADkBC,wBAAAA,aAAa,OACnB,CAAC,gBAAgB,WAAW,IAAI,KAAA;;;;;AAMrD,SAAgB,uBACd,YACA,SAA+B,EAAE,EACzB;CACR,MAAM,mBAAmB,8BAA8B,OAAO;AAC9D,QACE,mCAAmC,YAAY,iBAAiB,IAChE,iBAAiB;;AAIrB,SAAgB,qBAAqB,SAA+B,EAAE,EAAE;CACtE,MAAM,mBAAmB,8BAA8B,OAAO;AAC9D,SAAQ,eACN,mCAAmC,YAAY,iBAAiB,IAChE,iBAAiB"}
|
package/dist/internal.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { n as
|
|
3
|
-
import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-
|
|
4
|
-
import { a as ConditionStore, c as
|
|
5
|
-
import { a as Dictionary, d as
|
|
1
|
+
import { c as JsxTranslationOptions, d as ResolutionOptions, f as RuntimeTranslationOptions, l as LookupOptions, s as InlineTranslationOptions, u as NormalizedLookupOptions } from "./options-C1xolwBY.cjs";
|
|
2
|
+
import { n as GTFunctionType, r as MFunctionType, s as TFunctionType } from "./functions-DsYQxTQp.cjs";
|
|
3
|
+
import { a as getLocales, i as getLocaleProperties, n as getDefaultLocale, r as getLocale, t as getVersionId } from "./index-UDlCzB02.cjs";
|
|
4
|
+
import { a as ConditionStore, c as I18nManagerConfig, f as TranslationsLoader, i as resolveSupportedLocale, l as I18nManagerConstructorParams, n as createLocaleResolver, r as determineSupportedLocale, t as LocaleCandidates } from "./localeResolver-DcN9SGPs.cjs";
|
|
5
|
+
import { a as Dictionary, d as DictionaryValue, f as Locale, l as DictionaryObject, o as DictionaryEntry, p as Translation, t as Hash, u as DictionaryPath } from "./TranslationsCache-DQt4Es4G.cjs";
|
|
6
6
|
import { CustomMapping, DataFormat, JsxChildren, StringContent, StringFormat } from "generaltranslation/types";
|
|
7
7
|
import { GT } from "generaltranslation";
|
|
8
8
|
|
|
@@ -38,8 +38,6 @@ declare function getMessages(): Promise<MFunctionType>;
|
|
|
38
38
|
* @returns A promise of the t function
|
|
39
39
|
* @important Must be used inside of a request context
|
|
40
40
|
*
|
|
41
|
-
* @deprecated not yet supported
|
|
42
|
-
*
|
|
43
41
|
* @example
|
|
44
42
|
* const t = await getTranslations();
|
|
45
43
|
* const title = await t('page.title');
|
|
@@ -141,6 +139,7 @@ type ListenerStore<Events extends BaseEvent> = Partial<{ [EventName in keyof Eve
|
|
|
141
139
|
* @prop {locales-dictionary-cache-miss} - Emitted when a locales dictionary cache miss occurs
|
|
142
140
|
* @prop {dictionary-cache-hit} - Emitted when a dictionary cache hit occurs
|
|
143
141
|
* @prop {dictionary-cache-miss} - Emitted when a dictionary cache miss occurs
|
|
142
|
+
* @prop {dictionary-object-cache-hit} - Emitted when a dictionary object cache hit occurs
|
|
144
143
|
*/
|
|
145
144
|
type I18nEvents<TranslationValue extends Translation> = BaseEvent & {
|
|
146
145
|
'locales-cache-hit': {
|
|
@@ -179,6 +178,11 @@ type I18nEvents<TranslationValue extends Translation> = BaseEvent & {
|
|
|
179
178
|
id: DictionaryPath;
|
|
180
179
|
dictionaryEntry: DictionaryEntry;
|
|
181
180
|
};
|
|
181
|
+
'dictionary-object-cache-hit': {
|
|
182
|
+
locale: Locale;
|
|
183
|
+
id: DictionaryPath;
|
|
184
|
+
dictionaryValue: DictionaryValue;
|
|
185
|
+
};
|
|
182
186
|
};
|
|
183
187
|
//#endregion
|
|
184
188
|
//#region src/i18n-manager/event-subscription/EventEmitter.d.ts
|
|
@@ -289,7 +293,21 @@ declare class I18nManager<TranslationValue extends Translation = Translation> ex
|
|
|
289
293
|
/**
|
|
290
294
|
* Look up a dictionary entry
|
|
291
295
|
*/
|
|
292
|
-
lookupDictionary(locale: string, id: string):
|
|
296
|
+
lookupDictionary(locale: string, id: string): DictionaryEntry | undefined;
|
|
297
|
+
/**
|
|
298
|
+
* Look up a dictionary entry or subtree
|
|
299
|
+
*/
|
|
300
|
+
lookupDictionaryObj(locale: string, id: string): DictionaryObject | undefined;
|
|
301
|
+
/**
|
|
302
|
+
* Look up a dictionary entry
|
|
303
|
+
* If it's not found, use the fallback (runtime translate)
|
|
304
|
+
*/
|
|
305
|
+
lookupDictionaryWithFallback(locale: string, id: string): Promise<DictionaryEntry | undefined>;
|
|
306
|
+
/**
|
|
307
|
+
* Look up a dictionary entry or subtree
|
|
308
|
+
* If it's not found, use the fallback (runtime translate)
|
|
309
|
+
*/
|
|
310
|
+
lookupDictionaryObjWithFallback(locale: string, id: string): Promise<DictionaryObject | undefined>;
|
|
293
311
|
/**
|
|
294
312
|
* Just lookup a translation
|
|
295
313
|
*/
|
|
@@ -361,6 +379,11 @@ declare class I18nManager<TranslationValue extends Translation = Translation> ex
|
|
|
361
379
|
private resolveCacheLocale;
|
|
362
380
|
private resolveLookupParams;
|
|
363
381
|
private resolveLookupOptions;
|
|
382
|
+
private lookupTranslationWithFallbackResolved;
|
|
383
|
+
/**
|
|
384
|
+
* Runtime lookup function for dictionaries
|
|
385
|
+
*/
|
|
386
|
+
private dictionaryRuntimeTranslate;
|
|
364
387
|
/**
|
|
365
388
|
* A helper function to create a gt class that is locale agnostic
|
|
366
389
|
* This is helpful for when our getLocale function is bound to a
|