@generaltranslation/react-core 1.8.16 → 1.8.18
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 +23 -0
- package/dist/errors.cjs.min.cjs +2 -2
- package/dist/errors.cjs.min.cjs.map +1 -1
- package/dist/errors.d.ts +3 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.esm.min.mjs +2 -2
- package/dist/errors.esm.min.mjs.map +1 -1
- package/dist/index.cjs.min.cjs +2 -2
- package/dist/index.cjs.min.cjs.map +1 -1
- package/dist/index.d.ts +1384 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.min.mjs +2 -2
- package/dist/index.esm.min.mjs.map +1 -1
- package/dist/internal.cjs.min.cjs +2 -2
- package/dist/internal.cjs.min.cjs.map +1 -1
- package/dist/internal.d.ts +764 -31
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.esm.min.mjs +2 -2
- package/dist/internal.esm.min.mjs.map +1 -1
- package/dist/types.d.ts +357 -174
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -20
- package/dist/branches/Branch.d.ts +0 -34
- package/dist/branches/Branch.d.ts.map +0 -1
- package/dist/branches/plurals/Plural.d.ts +0 -38
- package/dist/branches/plurals/Plural.d.ts.map +0 -1
- package/dist/branches/plurals/getPluralBranch.d.ts +0 -9
- package/dist/branches/plurals/getPluralBranch.d.ts.map +0 -1
- package/dist/dictionaries/collectUntranslatedEntries.d.ts +0 -18
- package/dist/dictionaries/collectUntranslatedEntries.d.ts.map +0 -1
- package/dist/dictionaries/getDictionaryEntry.d.ts +0 -4
- package/dist/dictionaries/getDictionaryEntry.d.ts.map +0 -1
- package/dist/dictionaries/getEntryAndMetadata.d.ts +0 -6
- package/dist/dictionaries/getEntryAndMetadata.d.ts.map +0 -1
- package/dist/dictionaries/getSubtree.d.ts +0 -18
- package/dist/dictionaries/getSubtree.d.ts.map +0 -1
- package/dist/dictionaries/indexDict.d.ts +0 -15
- package/dist/dictionaries/indexDict.d.ts.map +0 -1
- package/dist/dictionaries/injectAndMerge.d.ts +0 -9
- package/dist/dictionaries/injectAndMerge.d.ts.map +0 -1
- package/dist/dictionaries/injectEntry.d.ts +0 -18
- package/dist/dictionaries/injectEntry.d.ts.map +0 -1
- package/dist/dictionaries/injectFallbacks.d.ts +0 -18
- package/dist/dictionaries/injectFallbacks.d.ts.map +0 -1
- package/dist/dictionaries/injectHashes.d.ts +0 -11
- package/dist/dictionaries/injectHashes.d.ts.map +0 -1
- package/dist/dictionaries/injectTranslations.d.ts +0 -21
- package/dist/dictionaries/injectTranslations.d.ts.map +0 -1
- package/dist/dictionaries/isDictionaryEntry.d.ts +0 -8
- package/dist/dictionaries/isDictionaryEntry.d.ts.map +0 -1
- package/dist/dictionaries/loadDictionaryHelper.d.ts +0 -3
- package/dist/dictionaries/loadDictionaryHelper.d.ts.map +0 -1
- package/dist/dictionaries/mergeDictionaries.d.ts +0 -3
- package/dist/dictionaries/mergeDictionaries.d.ts.map +0 -1
- package/dist/dictionaries/stripMetadataFromEntries.d.ts +0 -6
- package/dist/dictionaries/stripMetadataFromEntries.d.ts.map +0 -1
- package/dist/errors-dir/constants.d.ts +0 -2
- package/dist/errors-dir/constants.d.ts.map +0 -1
- package/dist/errors-dir/createErrors.d.ts +0 -36
- package/dist/errors-dir/createErrors.d.ts.map +0 -1
- package/dist/errors-dir/internalErrors.d.ts +0 -8
- package/dist/errors-dir/internalErrors.d.ts.map +0 -1
- package/dist/hooks/useDefaultLocale.d.ts +0 -13
- package/dist/hooks/useDefaultLocale.d.ts.map +0 -1
- package/dist/hooks/useGTClass.d.ts +0 -23
- package/dist/hooks/useGTClass.d.ts.map +0 -1
- package/dist/hooks/useLocale.d.ts +0 -11
- package/dist/hooks/useLocale.d.ts.map +0 -1
- package/dist/hooks/useLocaleDirection.d.ts +0 -14
- package/dist/hooks/useLocaleDirection.d.ts.map +0 -1
- package/dist/hooks/useLocaleSelector.d.ts +0 -19
- package/dist/hooks/useLocaleSelector.d.ts.map +0 -1
- package/dist/hooks/useLocales.d.ts +0 -11
- package/dist/hooks/useLocales.d.ts.map +0 -1
- package/dist/hooks/useRegion.d.ts +0 -20
- package/dist/hooks/useRegion.d.ts.map +0 -1
- package/dist/hooks/useRegionSelector.d.ts +0 -82
- package/dist/hooks/useRegionSelector.d.ts.map +0 -1
- package/dist/hooks/useSetLocale.d.ts +0 -12
- package/dist/hooks/useSetLocale.d.ts.map +0 -1
- package/dist/hooks/useVersionId.d.ts +0 -11
- package/dist/hooks/useVersionId.d.ts.map +0 -1
- package/dist/internal/addGTIdentifier.d.ts +0 -4
- package/dist/internal/addGTIdentifier.d.ts.map +0 -1
- package/dist/internal/flattenDictionary.d.ts +0 -11
- package/dist/internal/flattenDictionary.d.ts.map +0 -1
- package/dist/internal/removeInjectedT.d.ts +0 -11
- package/dist/internal/removeInjectedT.d.ts.map +0 -1
- package/dist/internal/writeChildrenAsObjects.d.ts +0 -10
- package/dist/internal/writeChildrenAsObjects.d.ts.map +0 -1
- package/dist/messages/messages.d.ts +0 -2
- package/dist/messages/messages.d.ts.map +0 -1
- package/dist/promises/dangerouslyUsable.d.ts +0 -37
- package/dist/promises/dangerouslyUsable.d.ts.map +0 -1
- package/dist/promises/reactHasUse.d.ts +0 -2
- package/dist/promises/reactHasUse.d.ts.map +0 -1
- package/dist/provider/GTContext.d.ts +0 -4
- package/dist/provider/GTContext.d.ts.map +0 -1
- package/dist/provider/GTProvider.d.ts +0 -3
- package/dist/provider/GTProvider.d.ts.map +0 -1
- package/dist/provider/config/defaultProps.d.ts +0 -4
- package/dist/provider/config/defaultProps.d.ts.map +0 -1
- package/dist/provider/helpers/isSSREnabled.d.ts +0 -5
- package/dist/provider/helpers/isSSREnabled.d.ts.map +0 -1
- package/dist/provider/helpers/validateString.d.ts +0 -6
- package/dist/provider/helpers/validateString.d.ts.map +0 -1
- package/dist/provider/hooks/locales/types.d.ts +0 -13
- package/dist/provider/hooks/locales/types.d.ts.map +0 -1
- package/dist/provider/hooks/locales/useDetermineLocale.d.ts +0 -6
- package/dist/provider/hooks/locales/useDetermineLocale.d.ts.map +0 -1
- package/dist/provider/hooks/locales/useLocaleState.d.ts +0 -20
- package/dist/provider/hooks/locales/useLocaleState.d.ts.map +0 -1
- package/dist/provider/hooks/translation/useCreateInternalUseGTFunction.d.ts +0 -19
- package/dist/provider/hooks/translation/useCreateInternalUseGTFunction.d.ts.map +0 -1
- package/dist/provider/hooks/translation/useCreateInternalUseTranslationsFunction.d.ts +0 -5
- package/dist/provider/hooks/translation/useCreateInternalUseTranslationsFunction.d.ts.map +0 -1
- package/dist/provider/hooks/translation/useCreateInternalUseTranslationsObjFunction.d.ts +0 -4
- package/dist/provider/hooks/translation/useCreateInternalUseTranslationsObjFunction.d.ts.map +0 -1
- package/dist/provider/hooks/types.d.ts +0 -19
- package/dist/provider/hooks/types.d.ts.map +0 -1
- package/dist/provider/hooks/useEnableI18n.d.ts +0 -3
- package/dist/provider/hooks/useEnableI18n.d.ts.map +0 -1
- package/dist/provider/hooks/useErrorChecks.d.ts +0 -10
- package/dist/provider/hooks/useErrorChecks.d.ts.map +0 -1
- package/dist/provider/hooks/useLoadDictionary.d.ts +0 -15
- package/dist/provider/hooks/useLoadDictionary.d.ts.map +0 -1
- package/dist/provider/hooks/useLoadTranslations.d.ts +0 -17
- package/dist/provider/hooks/useLoadTranslations.d.ts.map +0 -1
- package/dist/provider/hooks/useRegionState.d.ts +0 -6
- package/dist/provider/hooks/useRegionState.d.ts.map +0 -1
- package/dist/provider/hooks/useRuntimeTranslation.d.ts +0 -24
- package/dist/provider/hooks/useRuntimeTranslation.d.ts.map +0 -1
- package/dist/rendering/getDefaultRenderSettings.d.ts +0 -6
- package/dist/rendering/getDefaultRenderSettings.d.ts.map +0 -1
- package/dist/rendering/getGTTag.d.ts +0 -3
- package/dist/rendering/getGTTag.d.ts.map +0 -1
- package/dist/rendering/isVariableObject.d.ts +0 -3
- package/dist/rendering/isVariableObject.d.ts.map +0 -1
- package/dist/rendering/renderDefaultChildren.d.ts +0 -8
- package/dist/rendering/renderDefaultChildren.d.ts.map +0 -1
- package/dist/rendering/renderSkeleton.d.ts +0 -8
- package/dist/rendering/renderSkeleton.d.ts.map +0 -1
- package/dist/rendering/renderTranslatedChildren.d.ts +0 -9
- package/dist/rendering/renderTranslatedChildren.d.ts.map +0 -1
- package/dist/rendering/renderVariable.d.ts +0 -4
- package/dist/rendering/renderVariable.d.ts.map +0 -1
- package/dist/translation/T.d.ts +0 -42
- package/dist/translation/T.d.ts.map +0 -1
- package/dist/translation/hooks/useGT.d.ts +0 -21
- package/dist/translation/hooks/useGT.d.ts.map +0 -1
- package/dist/translation/hooks/useMessages.d.ts +0 -19
- package/dist/translation/hooks/useMessages.d.ts.map +0 -1
- package/dist/translation/hooks/useTranslations.d.ts +0 -17
- package/dist/translation/hooks/useTranslations.d.ts.map +0 -1
- package/dist/types-dir/config.d.ts +0 -69
- package/dist/types-dir/config.d.ts.map +0 -1
- package/dist/types-dir/context.d.ts +0 -31
- package/dist/types-dir/context.d.ts.map +0 -1
- package/dist/types-dir/runtime.d.ts +0 -22
- package/dist/types-dir/runtime.d.ts.map +0 -1
- package/dist/types-dir/types.d.ts +0 -90
- package/dist/types-dir/types.d.ts.map +0 -1
- package/dist/ui/LocaleSelector.d.ts +0 -7
- package/dist/ui/LocaleSelector.d.ts.map +0 -1
- package/dist/ui/RegionSelector.d.ts +0 -7
- package/dist/ui/RegionSelector.d.ts.map +0 -1
- package/dist/ui/types.d.ts +0 -18
- package/dist/ui/types.d.ts.map +0 -1
- package/dist/utils/cookies.d.ts +0 -14
- package/dist/utils/cookies.d.ts.map +0 -1
- package/dist/utils/fetchTranslations.d.ts +0 -9
- package/dist/utils/fetchTranslations.d.ts.map +0 -1
- package/dist/utils/types.d.ts +0 -9
- package/dist/utils/types.d.ts.map +0 -1
- package/dist/utils/use.d.ts +0 -4
- package/dist/utils/use.d.ts.map +0 -1
- package/dist/utils/utils.d.ts +0 -8
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/variables/Currency.d.ts +0 -30
- package/dist/variables/Currency.d.ts.map +0 -1
- package/dist/variables/DateTime.d.ts +0 -29
- package/dist/variables/DateTime.d.ts.map +0 -1
- package/dist/variables/Derive.d.ts +0 -76
- package/dist/variables/Derive.d.ts.map +0 -1
- package/dist/variables/Num.d.ts +0 -31
- package/dist/variables/Num.d.ts.map +0 -1
- package/dist/variables/RelativeTime.d.ts +0 -45
- package/dist/variables/RelativeTime.d.ts.map +0 -1
- package/dist/variables/Var.d.ts +0 -32
- package/dist/variables/Var.d.ts.map +0 -1
- package/dist/variables/_getVariableProps.d.ts +0 -11
- package/dist/variables/_getVariableProps.d.ts.map +0 -1
- package/dist/variables/getVariableName.d.ts +0 -11
- package/dist/variables/getVariableName.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,1385 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import * as _$react from "react";
|
|
2
|
+
import React$1, { ReactNode } from "react";
|
|
3
|
+
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
+
import * as _$generaltranslation from "generaltranslation";
|
|
5
|
+
import { GT } from "generaltranslation";
|
|
6
|
+
|
|
7
|
+
//#region src/translation/T.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Build-time translation component that renders its children in the user's given locale.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```jsx
|
|
13
|
+
* // Basic usage:
|
|
14
|
+
* <T id="welcome_message">
|
|
15
|
+
* Hello, <Var>{name}</Var>!
|
|
16
|
+
* </T>
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```jsx
|
|
21
|
+
* // Translating a plural
|
|
22
|
+
* <T id="item_count">
|
|
23
|
+
* <Plural n={3} singular={<>You have <Num children={n}/> item.</>}>
|
|
24
|
+
* You have <Num children={n}/> items.
|
|
25
|
+
* </Plural>
|
|
26
|
+
* </T>
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param {React.ReactNode} children - The content to be translated or displayed.
|
|
30
|
+
* @param {string} [id] - Optional identifier for the translation string. If not provided, a hash will be generated from the content.
|
|
31
|
+
* @param {any} [context] - Additional context for translation key generation.
|
|
32
|
+
*
|
|
33
|
+
* @returns {JSX.Element} The rendered translation or fallback content based on the provided configuration.
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} If a plural translation is requested but the `n` option is not provided.
|
|
36
|
+
*/
|
|
37
|
+
declare function T({
|
|
38
|
+
children,
|
|
39
|
+
id,
|
|
40
|
+
context,
|
|
41
|
+
_hash,
|
|
42
|
+
...options
|
|
43
|
+
}: {
|
|
44
|
+
children: React$1.ReactNode;
|
|
45
|
+
id?: string;
|
|
46
|
+
context?: string;
|
|
47
|
+
_hash?: string;
|
|
48
|
+
$id?: string;
|
|
49
|
+
$context?: string;
|
|
50
|
+
$maxChars?: number;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}): React$1.JSX.Element | undefined;
|
|
53
|
+
declare namespace T {
|
|
54
|
+
var _gtt: string;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region ../format/dist/types-UnF22q9r.d.cts
|
|
58
|
+
//#region src/locales/customLocaleMapping.d.ts
|
|
59
|
+
type CustomMapping = Record<string, string | Partial<LocaleProperties>>; //#endregion
|
|
60
|
+
//#region src/locales/getLocaleProperties.d.ts
|
|
61
|
+
type LocaleProperties = {
|
|
62
|
+
code: string;
|
|
63
|
+
name: string;
|
|
64
|
+
nativeName: string;
|
|
65
|
+
languageCode: string;
|
|
66
|
+
languageName: string;
|
|
67
|
+
nativeLanguageName: string;
|
|
68
|
+
nameWithRegionCode: string;
|
|
69
|
+
nativeNameWithRegionCode: string;
|
|
70
|
+
regionCode: string;
|
|
71
|
+
regionName: string;
|
|
72
|
+
nativeRegionName: string;
|
|
73
|
+
scriptCode: string;
|
|
74
|
+
scriptName: string;
|
|
75
|
+
nativeScriptName: string;
|
|
76
|
+
maximizedCode: string;
|
|
77
|
+
maximizedName: string;
|
|
78
|
+
nativeMaximizedName: string;
|
|
79
|
+
minimizedCode: string;
|
|
80
|
+
minimizedName: string;
|
|
81
|
+
nativeMinimizedName: string;
|
|
82
|
+
emoji: string;
|
|
83
|
+
}; //#endregion
|
|
84
|
+
//#region src/locales/getRegionProperties.d.ts
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/types-dir/jsx/variables.d.ts
|
|
87
|
+
type VariableType = 'v' | 'n' | 'd' | 'c' | 'rt';
|
|
88
|
+
/**
|
|
89
|
+
* Variables are used to store the variable name and type.
|
|
90
|
+
*/
|
|
91
|
+
type Variable = {
|
|
92
|
+
k: string;
|
|
93
|
+
i?: number;
|
|
94
|
+
v?: VariableType;
|
|
95
|
+
}; //#endregion
|
|
96
|
+
//#region src/types-dir/jsx/content.d.ts
|
|
97
|
+
/**
|
|
98
|
+
* Map of data-_gt properties to their corresponding React props
|
|
99
|
+
*/
|
|
100
|
+
declare const HTML_CONTENT_PROPS: {
|
|
101
|
+
readonly pl: "placeholder";
|
|
102
|
+
readonly ti: "title";
|
|
103
|
+
readonly alt: "alt";
|
|
104
|
+
readonly arl: "aria-label";
|
|
105
|
+
readonly arb: "aria-labelledby";
|
|
106
|
+
readonly ard: "aria-describedby";
|
|
107
|
+
};
|
|
108
|
+
type HtmlContentPropKeysRecord = Partial<Record<keyof typeof HTML_CONTENT_PROPS, string>>;
|
|
109
|
+
/**
|
|
110
|
+
* GTProp is an internal property used to contain data for translating and rendering elements.
|
|
111
|
+
* note, transformations are only read on the server side if they are 'plural' or 'branch'
|
|
112
|
+
*/
|
|
113
|
+
type GTProp = {
|
|
114
|
+
b?: Record<string, JsxChildren>;
|
|
115
|
+
t?: 'p' | 'b';
|
|
116
|
+
} & HtmlContentPropKeysRecord;
|
|
117
|
+
type JsxElement = {
|
|
118
|
+
t?: string;
|
|
119
|
+
i?: number;
|
|
120
|
+
d?: GTProp;
|
|
121
|
+
c?: JsxChildren;
|
|
122
|
+
};
|
|
123
|
+
type JsxChild = string | JsxElement | Variable;
|
|
124
|
+
/**
|
|
125
|
+
* The format of the string content
|
|
126
|
+
*/
|
|
127
|
+
type StringFormat = 'ICU' | 'I18NEXT' | 'STRING';
|
|
128
|
+
/**
|
|
129
|
+
* The format of the content.
|
|
130
|
+
*/
|
|
131
|
+
type DataFormat = 'JSX' | StringFormat;
|
|
132
|
+
/**
|
|
133
|
+
* String format content.
|
|
134
|
+
*/
|
|
135
|
+
/**
|
|
136
|
+
* A content type representing JSX elements.
|
|
137
|
+
*/
|
|
138
|
+
type JsxChildren = JsxChild | JsxChild[];
|
|
139
|
+
/**
|
|
140
|
+
* A content type representing ICU messages.
|
|
141
|
+
*/
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region ../i18n/dist/options-D0Lnxv2X.d.cts
|
|
144
|
+
//#region src/translation-functions/types/options.d.ts
|
|
145
|
+
type BaseTranslationOptions = Record<string, unknown>;
|
|
146
|
+
type DictionaryTranslationOptions = BaseTranslationOptions;
|
|
147
|
+
/**
|
|
148
|
+
* Options for string resolution
|
|
149
|
+
* Used by the gt() function
|
|
150
|
+
*/
|
|
151
|
+
type InlineTranslationOptions = BaseTranslationOptions & {
|
|
152
|
+
$context?: string;
|
|
153
|
+
$id?: string; /** The data format for the message (e.g., 'ICU', 'STRING'). Defaults to 'ICU'. */
|
|
154
|
+
$format?: StringFormat; /** The locale to use for formatting the message. */
|
|
155
|
+
$locale?: string;
|
|
156
|
+
/**
|
|
157
|
+
* @deprecated use {@link $locale} instead
|
|
158
|
+
*/
|
|
159
|
+
$_locales?: string | string[];
|
|
160
|
+
$_hash?: string;
|
|
161
|
+
$maxChars?: number; /** @deprecated use {@link EncodedTranslationOptions} instead */
|
|
162
|
+
$_source?: string;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Options for string resolution
|
|
166
|
+
* Used by the m() function
|
|
167
|
+
*/
|
|
168
|
+
/**
|
|
169
|
+
* Options for runtime translation
|
|
170
|
+
* Used by the tx() function
|
|
171
|
+
*/
|
|
172
|
+
type RuntimeTranslationOptions = {
|
|
173
|
+
$locale?: string;
|
|
174
|
+
$format?: DataFormat;
|
|
175
|
+
} & Omit<InlineTranslationOptions, '$id' | '$format'>;
|
|
176
|
+
/**
|
|
177
|
+
* Options for JSX translation
|
|
178
|
+
* Used by the resolveJsxTranslation() function
|
|
179
|
+
*/
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region ../i18n/dist/functions-DI1QpQoC.d.cts
|
|
182
|
+
/**
|
|
183
|
+
* Synchronous resolution function type
|
|
184
|
+
* @param {string} message - The message to translate.
|
|
185
|
+
* @param {InlineTranslationOptions} options - The options for the translation.
|
|
186
|
+
* @returns {string} The translated message.
|
|
187
|
+
*
|
|
188
|
+
* @important This is base type for user API
|
|
189
|
+
*
|
|
190
|
+
* TODO: next major version, this should be <T extends string | null | undefined>(message: T, options?: InlineTranslationOptions) => T extends string ? string : T;
|
|
191
|
+
*/
|
|
192
|
+
type SyncResolutionFunctionWithFallback = (message: string, options?: InlineTranslationOptions) => string;
|
|
193
|
+
/**
|
|
194
|
+
* Type for the gt() function
|
|
195
|
+
* @param {string} message - The message to translate
|
|
196
|
+
* @param {InlineTranslationOptions} options - The options for the translation
|
|
197
|
+
* @returns {string} The translated message
|
|
198
|
+
* TODO: next major version, remove the "...type" suffix, it's redundant
|
|
199
|
+
*/
|
|
200
|
+
type GTFunctionType = SyncResolutionFunctionWithFallback;
|
|
201
|
+
/**
|
|
202
|
+
* Type for the m() function
|
|
203
|
+
* @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.
|
|
204
|
+
* @param {InlineTranslationOptions} options - The options to interpolate.
|
|
205
|
+
* @returns {string | null | undefined} The decoded and interpolated message.
|
|
206
|
+
* TODO: next major version, this should be <T extends string | null | undefined>(message: T, options?: InlineTranslationOptions) => T extends string ? string : T;
|
|
207
|
+
* TODO: next major version, remove the "...type" suffix, it's redundant
|
|
208
|
+
*/
|
|
209
|
+
type MFunctionType = <T extends string | null | undefined>(encodedMsg: T, options?: Record<string, any>) => T extends string ? string : T;
|
|
210
|
+
/**
|
|
211
|
+
* Type for the t() function
|
|
212
|
+
* @param {string} id - The id of the translation to translate.
|
|
213
|
+
* @param {DictionaryTranslationOptions} options - The options for the translation.
|
|
214
|
+
* @returns {string} The translated message.
|
|
215
|
+
* TODO: next major version, remove the "...type" suffix, it's redundant
|
|
216
|
+
*/
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region ../i18n/dist/message-C62MTLwE.d.cts
|
|
219
|
+
//#region src/translation-functions/types/message.d.ts
|
|
220
|
+
/**
|
|
221
|
+
* Valid types for messages that can be registered.
|
|
222
|
+
* msg('Hello, World!')
|
|
223
|
+
* msg(['Hello, World!', 'Welcome, {user}!'])
|
|
224
|
+
*/
|
|
225
|
+
type RegisterableMessages = string | string[] | readonly string[]; //#endregion
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/types-dir/types.d.ts
|
|
228
|
+
/**
|
|
229
|
+
* For dictionaries, we have Entry and MetaEntry
|
|
230
|
+
*/
|
|
231
|
+
type Entry = string;
|
|
232
|
+
type MetaEntry = {
|
|
233
|
+
$context?: string;
|
|
234
|
+
$maxChars?: number;
|
|
235
|
+
$_hash?: string;
|
|
236
|
+
[key: string]: unknown;
|
|
237
|
+
};
|
|
238
|
+
type DictionaryEntry = Entry | [Entry] | [Entry, MetaEntry];
|
|
239
|
+
type Dictionary = {
|
|
240
|
+
[key: string]: Dictionary | DictionaryEntry;
|
|
241
|
+
} | (Dictionary | DictionaryEntry)[];
|
|
242
|
+
/**
|
|
243
|
+
* Translated content types
|
|
244
|
+
* TODO: move these types to JsxElement etc from generaltranslation/types
|
|
245
|
+
* remember to omit the t property (tag name) from the translated element
|
|
246
|
+
*/
|
|
247
|
+
type TranslatedElement = {
|
|
248
|
+
i?: number;
|
|
249
|
+
d?: GTProp;
|
|
250
|
+
c?: TranslatedChildren;
|
|
251
|
+
};
|
|
252
|
+
type TranslatedChild = TranslatedElement | string | Variable;
|
|
253
|
+
type TranslatedChildren = TranslatedChild | TranslatedChild[];
|
|
254
|
+
type Translations = {
|
|
255
|
+
[hash: string]: TranslatedChildren | null;
|
|
256
|
+
};
|
|
257
|
+
type CustomLoader = (locale: string) => Promise<unknown>;
|
|
258
|
+
type RenderMethod = 'skeleton' | 'replace' | 'default';
|
|
259
|
+
type _Message = {
|
|
260
|
+
message: string;
|
|
261
|
+
$id?: string;
|
|
262
|
+
$context?: string;
|
|
263
|
+
$maxChars?: number;
|
|
264
|
+
$_hash?: string;
|
|
265
|
+
};
|
|
266
|
+
type _Messages = _Message[];
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/translation/hooks/useGT.d.ts
|
|
269
|
+
/**
|
|
270
|
+
* Gets the translation function `gt` provided by `<GTProvider>`.
|
|
271
|
+
*
|
|
272
|
+
* @returns {Function} A translation function that accepts an ICU message format string and returns the translation of that string.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* const gt = useGT();
|
|
276
|
+
* console.log(gt('To be or not to be...'));
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* const gt = useGT();
|
|
280
|
+
* gt('My name is {customName}', { customName: "Brian", id: 'my-name', context: 'a proper noun' } )
|
|
281
|
+
*/
|
|
282
|
+
declare function useGT(_messages?: _Messages): (string: string, options?: Record<string, unknown> & {
|
|
283
|
+
$id?: string;
|
|
284
|
+
$context?: string;
|
|
285
|
+
$maxChars?: number;
|
|
286
|
+
$_hash?: string;
|
|
287
|
+
}) => string;
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/translation/hooks/useTranslations.d.ts
|
|
290
|
+
/**
|
|
291
|
+
* Gets the dictionary access function `t` provided by `<GTProvider>`.
|
|
292
|
+
*
|
|
293
|
+
* @param {string} [id] - Optional prefix to prepend to the translation keys.
|
|
294
|
+
* @returns {Function} A translation function that accepts a key string and returns the translated value.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* const t = useTranslations('user');
|
|
298
|
+
* console.log(t('name')); // Translates item 'user.name'
|
|
299
|
+
*
|
|
300
|
+
* const t = useTranslations();
|
|
301
|
+
* console.log(t('hello')); // Translates item 'hello'
|
|
302
|
+
*/
|
|
303
|
+
declare function useTranslations(id?: string): ((id: string, options?: Record<string, unknown>) => string) & {
|
|
304
|
+
obj: (id: string, options?: Record<string, unknown>) => unknown | undefined;
|
|
305
|
+
};
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/hooks/useDefaultLocale.d.ts
|
|
308
|
+
/**
|
|
309
|
+
* Retrieves the application's default locale from the `<GTProvider>` context.
|
|
310
|
+
*
|
|
311
|
+
* If no default locale is passed to the `<GTProvider>`, it defaults to providing 'en'.
|
|
312
|
+
*
|
|
313
|
+
* @returns {string} The application's default locale, e.g., 'en-US'.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* const locale = useDefaultLocale();
|
|
317
|
+
* console.log(locale); // 'en-US'
|
|
318
|
+
*/
|
|
319
|
+
declare function useDefaultLocale(): string;
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region src/hooks/useLocale.d.ts
|
|
322
|
+
/**
|
|
323
|
+
* Retrieves the user's locale from the `<GTProvider>` context.
|
|
324
|
+
*
|
|
325
|
+
* @returns {string} The user's locale, e.g., 'en-US'.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* const locale = useLocale();
|
|
329
|
+
* console.log(locale); // 'en-US'
|
|
330
|
+
*/
|
|
331
|
+
declare function useLocale(): string;
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/hooks/useVersionId.d.ts
|
|
334
|
+
/**
|
|
335
|
+
* Retrieves the version ID from the `<GTProvider>` context.
|
|
336
|
+
*
|
|
337
|
+
* @returns {string | undefined} The version ID for the current source, if set.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* const versionId = useVersionId();
|
|
341
|
+
* console.log(versionId); // 'abc123'
|
|
342
|
+
*/
|
|
343
|
+
declare function useVersionId(): string | undefined;
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region src/hooks/useRegion.d.ts
|
|
346
|
+
/**
|
|
347
|
+
* A React hook that retrieves the user's currently selected region from the `<GTProvider>` context.
|
|
348
|
+
*
|
|
349
|
+
* Returns the `region` value as a string (e.g., `"US"`, `"CA"`) or `undefined` if no region has been set.
|
|
350
|
+
*
|
|
351
|
+
* @returns {string | undefined} The currently active region code, or `undefined` if not set.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```tsx
|
|
355
|
+
* const region = useRegion();
|
|
356
|
+
*
|
|
357
|
+
* if (!region) {
|
|
358
|
+
* console.log("No region set yet");
|
|
359
|
+
* } else {
|
|
360
|
+
* console.log(`Current region: ${region}`);
|
|
361
|
+
* }
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
declare function useRegion(): string | undefined;
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/utils/types.d.ts
|
|
367
|
+
type AuthFromEnvParams = {
|
|
368
|
+
projectId?: string;
|
|
369
|
+
devApiKey?: string;
|
|
370
|
+
};
|
|
371
|
+
type AuthFromEnvReturn = {
|
|
372
|
+
projectId: string;
|
|
373
|
+
devApiKey?: string;
|
|
374
|
+
};
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/provider/hooks/locales/types.d.ts
|
|
377
|
+
type UseDetermineLocaleParams = {
|
|
378
|
+
defaultLocale: string;
|
|
379
|
+
locales: string[];
|
|
380
|
+
enableI18n: boolean;
|
|
381
|
+
locale?: string;
|
|
382
|
+
localeCookieName?: string;
|
|
383
|
+
ssr?: boolean;
|
|
384
|
+
customMapping?: CustomMapping;
|
|
385
|
+
reloadOnLocaleUpdate?: boolean;
|
|
386
|
+
};
|
|
387
|
+
type UseDetermineLocaleReturn = [string, (locale: string) => void];
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/provider/hooks/types.d.ts
|
|
390
|
+
type UseRegionStateParams = {
|
|
391
|
+
_region: string | undefined;
|
|
392
|
+
ssr: boolean;
|
|
393
|
+
regionCookieName: string;
|
|
394
|
+
};
|
|
395
|
+
type UseRegionStateReturn = {
|
|
396
|
+
region: string | undefined;
|
|
397
|
+
setRegion: (region: string | undefined) => void;
|
|
398
|
+
};
|
|
399
|
+
type UseEnableI18nParams = {
|
|
400
|
+
enableI18n: boolean;
|
|
401
|
+
enableI18nCookieName: string;
|
|
402
|
+
enableI18nLoaded?: boolean;
|
|
403
|
+
ssr: boolean;
|
|
404
|
+
};
|
|
405
|
+
type UseEnableI18nReturn = {
|
|
406
|
+
enableI18n: boolean;
|
|
407
|
+
};
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/types-dir/config.d.ts
|
|
410
|
+
type GTConfig = {
|
|
411
|
+
projectId?: string;
|
|
412
|
+
devApiKey?: string;
|
|
413
|
+
locales?: string[];
|
|
414
|
+
defaultLocale?: string;
|
|
415
|
+
dictionary?: string;
|
|
416
|
+
runtimeUrl?: string | null;
|
|
417
|
+
cacheUrl?: string | null;
|
|
418
|
+
renderSettings?: {
|
|
419
|
+
method: RenderMethod;
|
|
420
|
+
timeout?: number;
|
|
421
|
+
};
|
|
422
|
+
_versionId?: string;
|
|
423
|
+
ssr?: boolean;
|
|
424
|
+
localeCookieName?: string;
|
|
425
|
+
customMapping?: CustomMapping;
|
|
426
|
+
modelProvider?: string;
|
|
427
|
+
enableI18n?: boolean;
|
|
428
|
+
};
|
|
429
|
+
type InternalGTProviderProps = {
|
|
430
|
+
children?: React$1.ReactNode;
|
|
431
|
+
projectId?: string;
|
|
432
|
+
devApiKey?: string;
|
|
433
|
+
dictionary?: Dictionary;
|
|
434
|
+
locales?: string[];
|
|
435
|
+
defaultLocale?: string;
|
|
436
|
+
locale?: string;
|
|
437
|
+
region?: string;
|
|
438
|
+
cacheUrl?: string | null;
|
|
439
|
+
runtimeUrl?: string | null;
|
|
440
|
+
renderSettings?: {
|
|
441
|
+
method: RenderMethod;
|
|
442
|
+
timeout?: number;
|
|
443
|
+
};
|
|
444
|
+
_versionId?: string;
|
|
445
|
+
ssr?: boolean;
|
|
446
|
+
localeCookieName?: string;
|
|
447
|
+
translations?: Translations | null;
|
|
448
|
+
loadDictionary?: CustomLoader;
|
|
449
|
+
loadTranslations?: CustomLoader;
|
|
450
|
+
config?: GTConfig;
|
|
451
|
+
fallback?: React$1.ReactNode;
|
|
452
|
+
customMapping?: CustomMapping;
|
|
453
|
+
modelProvider?: string;
|
|
454
|
+
environment: 'development' | 'production' | 'test';
|
|
455
|
+
enableI18n?: boolean; /** Flag to indicate if the enableI18n flag is finished loading asynchronously */
|
|
456
|
+
enableI18nLoaded?: boolean;
|
|
457
|
+
readAuthFromEnv: (params: AuthFromEnvParams) => AuthFromEnvReturn;
|
|
458
|
+
useDetermineLocale: (params: UseDetermineLocaleParams) => UseDetermineLocaleReturn;
|
|
459
|
+
useRegionState: (params: UseRegionStateParams) => UseRegionStateReturn;
|
|
460
|
+
useEnableI18n?: (params: UseEnableI18nParams) => UseEnableI18nReturn;
|
|
461
|
+
reloadOnLocaleUpdate?: boolean;
|
|
462
|
+
[key: string]: unknown;
|
|
463
|
+
};
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/provider/GTProvider.d.ts
|
|
466
|
+
declare function GTProvider({
|
|
467
|
+
children,
|
|
468
|
+
config,
|
|
469
|
+
environment,
|
|
470
|
+
projectId: _projectId,
|
|
471
|
+
devApiKey: _devApiKey,
|
|
472
|
+
_versionId,
|
|
473
|
+
dictionary: _dictionary,
|
|
474
|
+
locales,
|
|
475
|
+
defaultLocale,
|
|
476
|
+
cacheUrl,
|
|
477
|
+
runtimeUrl,
|
|
478
|
+
renderSettings,
|
|
479
|
+
ssr,
|
|
480
|
+
localeCookieName,
|
|
481
|
+
locale: _locale,
|
|
482
|
+
region: _region,
|
|
483
|
+
loadDictionary,
|
|
484
|
+
loadTranslations,
|
|
485
|
+
fallback,
|
|
486
|
+
translations: _translations,
|
|
487
|
+
customMapping,
|
|
488
|
+
enableI18n: _enableI18n,
|
|
489
|
+
enableI18nLoaded,
|
|
490
|
+
reloadOnLocaleUpdate,
|
|
491
|
+
useEnableI18n,
|
|
492
|
+
readAuthFromEnv,
|
|
493
|
+
useDetermineLocale,
|
|
494
|
+
useRegionState,
|
|
495
|
+
...metadata
|
|
496
|
+
}: InternalGTProviderProps): _$react_jsx_runtime0.JSX.Element;
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/variables/Var.d.ts
|
|
499
|
+
/**
|
|
500
|
+
* The `<Var>` component renders a variable value, which can either be passed as `children` or a `value`.
|
|
501
|
+
* If `children` is provided, it will be used; otherwise, the `value` is rendered.
|
|
502
|
+
*
|
|
503
|
+
* @example Inline usage:
|
|
504
|
+
* ```jsx
|
|
505
|
+
* function MyComponent() {
|
|
506
|
+
* const name = 'Archie';
|
|
507
|
+
* return (
|
|
508
|
+
* <T>
|
|
509
|
+
* <p>
|
|
510
|
+
* Hello, <Var> {name} </Var>!
|
|
511
|
+
* </p>
|
|
512
|
+
* </T>
|
|
513
|
+
* );
|
|
514
|
+
* }
|
|
515
|
+
* ```
|
|
516
|
+
*
|
|
517
|
+
*
|
|
518
|
+
* @param {any} [children] - The content to render inside the component. If provided, it will take precedence over `value`.
|
|
519
|
+
* @returns {JSX.Element} The rendered variable component with either `children` or `value`.
|
|
520
|
+
*/
|
|
521
|
+
declare function Var({
|
|
522
|
+
children
|
|
523
|
+
}: {
|
|
524
|
+
children?: unknown;
|
|
525
|
+
name?: string;
|
|
526
|
+
}): React$1.JSX.Element | null;
|
|
527
|
+
declare namespace Var {
|
|
528
|
+
var _gtt: string;
|
|
529
|
+
}
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/variables/Num.d.ts
|
|
532
|
+
/**
|
|
533
|
+
* The `<Num>` component renders a formatted number string, allowing customization of the name, default value, and formatting options.
|
|
534
|
+
* It formats the number according to the current locale and optionally passed formatting options.
|
|
535
|
+
* Must be used inside a `<GTProvider>`.
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* ```jsx
|
|
539
|
+
* <Num
|
|
540
|
+
* options={{ style: "decimal", maximumFractionDigits: 2 }}
|
|
541
|
+
* >
|
|
542
|
+
* 1000
|
|
543
|
+
* </Num>
|
|
544
|
+
* ```
|
|
545
|
+
*
|
|
546
|
+
* @param {number | string | null | undefined} children - Content to render inside the number component.
|
|
547
|
+
* @param {string[]} [locales] - Optional locales to use for number formatting. If wrapped in a `<GTProvider>`, the user's locale is used.
|
|
548
|
+
* @param {Intl.NumberFormatOptions} [options={}] - Optional formatting options for the number, following `Intl.NumberFormatOptions` specifications.
|
|
549
|
+
* @returns {React.JSX.Element} The formatted number component.
|
|
550
|
+
*/
|
|
551
|
+
declare function Num({
|
|
552
|
+
children,
|
|
553
|
+
locales,
|
|
554
|
+
options
|
|
555
|
+
}: {
|
|
556
|
+
children: number | string | null | undefined;
|
|
557
|
+
name?: string;
|
|
558
|
+
locales?: string[];
|
|
559
|
+
options?: Intl.NumberFormatOptions;
|
|
560
|
+
}): React$1.JSX.Element | null;
|
|
561
|
+
declare namespace Num {
|
|
562
|
+
var _gtt: string;
|
|
563
|
+
}
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region src/variables/Currency.d.ts
|
|
566
|
+
/**
|
|
567
|
+
* The `<Currency>` component renders a formatted currency string, allowing customization of name, default value, currency type, and formatting options.
|
|
568
|
+
* Must be used inside a `<GTProvider>`.
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```jsx
|
|
572
|
+
* <Currency currency="USD">
|
|
573
|
+
* 1000
|
|
574
|
+
* </Currency>
|
|
575
|
+
* ```
|
|
576
|
+
*
|
|
577
|
+
* @param {number | string | null | undefined} children - Content to render inside the currency component.
|
|
578
|
+
* @param {string} [currency="USD"] - The currency type (e.g., USD, EUR, etc.).
|
|
579
|
+
* @param {string[]} [locales] - Optional locales to use for currency formatting. If wrapped in a `<GTProvider>`, the user's locale is used.
|
|
580
|
+
* @param {Intl.NumberFormatOptions} [options={}] - Optional formatting options to customize how the currency is displayed.
|
|
581
|
+
* @returns {JSX.Element} The formatted currency component.
|
|
582
|
+
*/
|
|
583
|
+
declare function Currency({
|
|
584
|
+
children,
|
|
585
|
+
currency,
|
|
586
|
+
locales,
|
|
587
|
+
options
|
|
588
|
+
}: {
|
|
589
|
+
children: number | string | null | undefined;
|
|
590
|
+
currency?: string;
|
|
591
|
+
name?: string;
|
|
592
|
+
locales?: string[];
|
|
593
|
+
options?: Intl.NumberFormatOptions;
|
|
594
|
+
}): React$1.JSX.Element | null;
|
|
595
|
+
declare namespace Currency {
|
|
596
|
+
var _gtt: string;
|
|
597
|
+
}
|
|
598
|
+
//#endregion
|
|
599
|
+
//#region src/variables/DateTime.d.ts
|
|
600
|
+
/**
|
|
601
|
+
* The `<DateTime>` component renders a formatted date or time string, allowing customization of the name, default value, and formatting options.
|
|
602
|
+
* It utilizes the current locale and optional format settings to display the date.
|
|
603
|
+
* Must be used inside a `<GTProvider>`.
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* ```jsx
|
|
607
|
+
* <DateTime>
|
|
608
|
+
* {new Date()}
|
|
609
|
+
* </DateTime>
|
|
610
|
+
* ```
|
|
611
|
+
*
|
|
612
|
+
* @param {Date} children - Content to render inside the date component.
|
|
613
|
+
* @param {string[]} [locales] - Optional locales to use for date formatting. If wrapped in a `<GTProvider>`, the user's locale is used.
|
|
614
|
+
* @param {Intl.DateTimeFormatOptions} [options={}] - Optional formatting options for the date, following `Intl.DateTimeFormatOptions` specifications.
|
|
615
|
+
* @returns {JSX.Element} The formatted date or time component.
|
|
616
|
+
*/
|
|
617
|
+
declare function DateTime({
|
|
618
|
+
children,
|
|
619
|
+
locales,
|
|
620
|
+
options
|
|
621
|
+
}: {
|
|
622
|
+
children: Date | null | undefined;
|
|
623
|
+
name?: string;
|
|
624
|
+
locales?: string[];
|
|
625
|
+
options?: Intl.DateTimeFormatOptions;
|
|
626
|
+
}): React$1.JSX.Element | null;
|
|
627
|
+
declare namespace DateTime {
|
|
628
|
+
var _gtt: string;
|
|
629
|
+
}
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region src/variables/RelativeTime.d.ts
|
|
632
|
+
/**
|
|
633
|
+
* The `<RelativeTime>` component renders a localized relative time string
|
|
634
|
+
* (e.g., "2 hours ago", "in 3 days") using `Intl.RelativeTimeFormat`.
|
|
635
|
+
* Must be used inside a `<GTProvider>`.
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```jsx
|
|
639
|
+
* // Auto-select unit from a Date
|
|
640
|
+
* <RelativeTime date={someDate} />
|
|
641
|
+
* // → "2 hours ago"
|
|
642
|
+
* ```
|
|
643
|
+
*
|
|
644
|
+
* @example
|
|
645
|
+
* ```jsx
|
|
646
|
+
* // Explicit value and unit
|
|
647
|
+
* <RelativeTime value={-1} unit="day" />
|
|
648
|
+
* // → "yesterday"
|
|
649
|
+
* ```
|
|
650
|
+
*
|
|
651
|
+
* @param {Date} [date] - A date to compute relative time from now. Mutually exclusive with `value`/`unit`.
|
|
652
|
+
* @param {number} [value] - Explicit numeric value for relative time. Requires `unit`.
|
|
653
|
+
* @param {Intl.RelativeTimeFormatUnit} [unit] - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year'). Required when using `value`.
|
|
654
|
+
* @param {string} [name] - Optional name for the variable, used by the GT CLI for additional context during extraction.
|
|
655
|
+
* @param {string[]} [locales] - Optional locales for formatting. If wrapped in a `<GTProvider>`, the user's locale is used.
|
|
656
|
+
* @param {Intl.RelativeTimeFormatOptions} [options={}] - Optional formatting options following `Intl.RelativeTimeFormatOptions`.
|
|
657
|
+
* @returns {JSX.Element | null} The formatted relative time string.
|
|
658
|
+
*/
|
|
659
|
+
declare function RelativeTime({
|
|
660
|
+
date,
|
|
661
|
+
children,
|
|
662
|
+
value,
|
|
663
|
+
unit,
|
|
664
|
+
baseDate,
|
|
665
|
+
locales,
|
|
666
|
+
options
|
|
667
|
+
}: {
|
|
668
|
+
date?: Date | null | undefined;
|
|
669
|
+
children?: Date | null | undefined; /** Used by the GT CLI for additional context during extraction. */
|
|
670
|
+
name?: string;
|
|
671
|
+
value?: number;
|
|
672
|
+
unit?: Intl.RelativeTimeFormatUnit; /** Base date for computing relative time. Defaults to `new Date()` at render time. Required for hydration safety. */
|
|
673
|
+
baseDate?: Date;
|
|
674
|
+
locales?: string[];
|
|
675
|
+
options?: Intl.RelativeTimeFormatOptions;
|
|
676
|
+
}): React$1.JSX.Element | null;
|
|
677
|
+
declare namespace RelativeTime {
|
|
678
|
+
var _gtt: string;
|
|
679
|
+
}
|
|
680
|
+
//#endregion
|
|
681
|
+
//#region src/variables/Derive.d.ts
|
|
682
|
+
/**
|
|
683
|
+
* Marks JSX children as derivable by the GT compiler and CLI.
|
|
684
|
+
*
|
|
685
|
+
* Use `<Derive>` inside translated JSX when child content is computed from
|
|
686
|
+
* source code, but should still be discovered during extraction instead of
|
|
687
|
+
* treated as a runtime interpolation variable. The CLI attempts to resolve the
|
|
688
|
+
* derivable children into every possible static value and includes those values
|
|
689
|
+
* in the source content that gets translated.
|
|
690
|
+
*
|
|
691
|
+
* `<Derive>` renders its children unchanged at runtime.
|
|
692
|
+
*
|
|
693
|
+
* Run `gt validate` after adding or changing `<Derive>` usage to verify that
|
|
694
|
+
* each derivable expression can be resolved by the CLI before translating or
|
|
695
|
+
* building.
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* ```jsx
|
|
699
|
+
* function getSubject() {
|
|
700
|
+
* return (Math.random() > 0.5) ? "Alice" : "Brian";
|
|
701
|
+
* }
|
|
702
|
+
* ...
|
|
703
|
+
* <T>
|
|
704
|
+
* <Derive>
|
|
705
|
+
* {getSubject()}
|
|
706
|
+
* </Derive>
|
|
707
|
+
* is going to school today.
|
|
708
|
+
* </T>
|
|
709
|
+
* ```
|
|
710
|
+
*
|
|
711
|
+
* @param {T extends React.ReactNode} children - JSX content to derive for translation extraction.
|
|
712
|
+
* @returns {T} The same children, unchanged at runtime.
|
|
713
|
+
*/
|
|
714
|
+
declare function Derive<T extends React$1.ReactNode>({
|
|
715
|
+
children
|
|
716
|
+
}: {
|
|
717
|
+
children: T;
|
|
718
|
+
}): T;
|
|
719
|
+
declare namespace Derive {
|
|
720
|
+
var _gtt: string;
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* @deprecated Use `<Derive>` instead.
|
|
724
|
+
*
|
|
725
|
+
* Marks JSX children as derivable by the GT compiler and CLI.
|
|
726
|
+
*
|
|
727
|
+
* Use `<Derive>` instead of `<Static>` for new code. This alias is kept for
|
|
728
|
+
* backwards compatibility and renders its children unchanged at runtime.
|
|
729
|
+
*
|
|
730
|
+
* Run `gt validate` after adding or changing derived JSX content to verify that
|
|
731
|
+
* each derivable expression can be resolved by the CLI before translating or
|
|
732
|
+
* building.
|
|
733
|
+
*
|
|
734
|
+
* @example
|
|
735
|
+
* ```jsx
|
|
736
|
+
* function getSubject() {
|
|
737
|
+
* return (Math.random() > 0.5) ? "Alice" : "Brian";
|
|
738
|
+
* }
|
|
739
|
+
* ...
|
|
740
|
+
* <T>
|
|
741
|
+
* <Static>
|
|
742
|
+
* {getSubject()}
|
|
743
|
+
* </Static>
|
|
744
|
+
* is going to school today.
|
|
745
|
+
* </T>
|
|
746
|
+
* ```
|
|
747
|
+
*
|
|
748
|
+
* @param {T extends React.ReactNode} children - JSX content to derive for translation extraction.
|
|
749
|
+
* @returns {T} The same children, unchanged at runtime.
|
|
750
|
+
*/
|
|
751
|
+
declare function Static<T extends React$1.ReactNode>(props: {
|
|
752
|
+
children: T;
|
|
753
|
+
}): T;
|
|
754
|
+
declare namespace Static {
|
|
755
|
+
var _gtt: string;
|
|
756
|
+
}
|
|
757
|
+
//#endregion
|
|
758
|
+
//#region src/branches/plurals/Plural.d.ts
|
|
759
|
+
/**
|
|
760
|
+
* The `<Plural>` component dynamically renders content based on the plural form of the given number (`n`).
|
|
761
|
+
* It determines which content to display by matching the value of `n` to the appropriate pluralization branch,
|
|
762
|
+
* based on the current locale or a default locale. If no matching plural branch is found, the component renders
|
|
763
|
+
* the fallback `children` content.
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
* ```jsx
|
|
767
|
+
* <Plural
|
|
768
|
+
* n={1}
|
|
769
|
+
* one="There is 1 item"
|
|
770
|
+
* other="There are {n} items"
|
|
771
|
+
* />
|
|
772
|
+
* ```
|
|
773
|
+
* In this example, if `n` is 1, it renders `"There is 1 item"`. If `n` is a different number, it renders
|
|
774
|
+
* `"There are {n} items"`.
|
|
775
|
+
*
|
|
776
|
+
* @param {any} [children] - Fallback content to render if no matching plural branch is found.
|
|
777
|
+
* @param {number} [n] - The number used to determine the plural form. This is required for pluralization to work.
|
|
778
|
+
* @param {string} [locales] - Optional parameter, the locale to use for pluralization format. If not provided and wrapped
|
|
779
|
+
* in <GTProvider> will automatically populate this value as user's current locale. If not provided and not wrapped in
|
|
780
|
+
* <GTProvider>, will use the library default locale (en-US).
|
|
781
|
+
* @param {...{[key: string]: any}} [branches] - A spread object containing possible plural branches, typically including `one` for singular
|
|
782
|
+
* and `other` for plural forms, but it may vary depending on the locale.
|
|
783
|
+
* @returns {React.JSX.Element} The rendered content corresponding to the plural form of `n`, or the fallback content.
|
|
784
|
+
* @throws {Error} If `n` is not provided or not a valid number.
|
|
785
|
+
*/
|
|
786
|
+
declare function Plural({
|
|
787
|
+
children,
|
|
788
|
+
n,
|
|
789
|
+
locales,
|
|
790
|
+
...branches
|
|
791
|
+
}: {
|
|
792
|
+
children?: React.ReactNode;
|
|
793
|
+
n?: number;
|
|
794
|
+
locales?: string;
|
|
795
|
+
[key: string]: unknown;
|
|
796
|
+
}): React.JSX.Element;
|
|
797
|
+
declare namespace Plural {
|
|
798
|
+
var _gtt: string;
|
|
799
|
+
}
|
|
800
|
+
//#endregion
|
|
801
|
+
//#region src/branches/Branch.d.ts
|
|
802
|
+
/**
|
|
803
|
+
* The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
|
|
804
|
+
* It allows for flexible content switching based on the `branch` prop and an object of possible branches (`...branches`).
|
|
805
|
+
* If the specified `branch` is present in the `branches` object, it renders the content of that branch.
|
|
806
|
+
* If the `branch` is not found, it renders the provided `children` as fallback content.
|
|
807
|
+
*
|
|
808
|
+
* @example
|
|
809
|
+
* ```jsx
|
|
810
|
+
* <Branch
|
|
811
|
+
* branch="summary"
|
|
812
|
+
* summary={<p>This is a summary</p>}
|
|
813
|
+
* details={<p>Details here</p>}
|
|
814
|
+
* >
|
|
815
|
+
* <p>Fallback content</p>
|
|
816
|
+
* </Branch>
|
|
817
|
+
* ```
|
|
818
|
+
* If the `branch` prop is set to `"summary"`, it will render `<p>This is a summary</p>`. If the `branch` is not set or does not match any keys in the branches object, it renders the fallback content `<p>Fallback content</p>`.
|
|
819
|
+
*
|
|
820
|
+
* @param {any} [children] - Fallback content to render if no matching branch is found.
|
|
821
|
+
* @param {any} [name="branch"] - Optional name for the component, used for metadata or tracking purposes.
|
|
822
|
+
* @param {string} [branch] - The name of the branch to render. The component looks for this key in the `...branches` object.
|
|
823
|
+
* @param {...{[key: string]: any}} [branches] - A spread object containing possible branches as keys and their corresponding content as values.
|
|
824
|
+
* @returns {React.JSX.Element} The rendered branch or fallback content.
|
|
825
|
+
*/
|
|
826
|
+
declare function Branch({
|
|
827
|
+
children,
|
|
828
|
+
branch,
|
|
829
|
+
...branches
|
|
830
|
+
}: {
|
|
831
|
+
children?: unknown;
|
|
832
|
+
branch?: string | number | boolean;
|
|
833
|
+
[key: string]: unknown;
|
|
834
|
+
}): React.JSX.Element;
|
|
835
|
+
declare namespace Branch {
|
|
836
|
+
var _gtt: string;
|
|
837
|
+
}
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/hooks/useLocales.d.ts
|
|
840
|
+
/**
|
|
841
|
+
* Retrieves the user's list of supported locales from the `<GTProvider>` context.
|
|
842
|
+
*
|
|
843
|
+
* @returns {string[]} The user's locales, e.g., ['en-US', 'fr', 'jp'].
|
|
844
|
+
*
|
|
845
|
+
* @example
|
|
846
|
+
* const locales = useLocales();
|
|
847
|
+
* console.log(locale); // ['en-US', 'fr', 'jp]
|
|
848
|
+
*/
|
|
849
|
+
declare function useLocales(): string[];
|
|
850
|
+
//#endregion
|
|
851
|
+
//#region src/hooks/useSetLocale.d.ts
|
|
852
|
+
/**
|
|
853
|
+
* Sets the user's locale in the `<GTProvider>` context.
|
|
854
|
+
* If the locale passed is not supported, will fallback on current locale and then defaultLocale if necessary.
|
|
855
|
+
* @note Unless a locale has explicitly been passed to the `<GTProvider>`, this will override the user's browser preferences. The locale passed to `<GTProvider>` will always take priority.
|
|
856
|
+
*
|
|
857
|
+
* @returns {(locale: string) => void} A function that sets the user's locale.
|
|
858
|
+
*
|
|
859
|
+
* @example
|
|
860
|
+
* setLocale('en-US');
|
|
861
|
+
*/
|
|
862
|
+
declare function useSetLocale(): (locale: string) => void;
|
|
863
|
+
//#endregion
|
|
864
|
+
//#region src/ui/types.d.ts
|
|
865
|
+
type LocaleSelectorProps = {
|
|
866
|
+
locales?: string[];
|
|
867
|
+
customNames?: {
|
|
868
|
+
[key: string]: string;
|
|
869
|
+
};
|
|
870
|
+
customMapping?: CustomMapping;
|
|
871
|
+
[key: string]: unknown;
|
|
872
|
+
};
|
|
873
|
+
type RegionSelectorProps<Regions extends string[]> = {
|
|
874
|
+
regions?: Regions;
|
|
875
|
+
placeholder?: ReactNode;
|
|
876
|
+
customMapping?: CustomMapping;
|
|
877
|
+
prioritizeCurrentLocaleRegion?: boolean;
|
|
878
|
+
sortRegionsAlphabetically?: boolean;
|
|
879
|
+
};
|
|
880
|
+
//#endregion
|
|
881
|
+
//#region src/ui/LocaleSelector.d.ts
|
|
882
|
+
/**
|
|
883
|
+
* @deprecated - this function is to always be overridden by a wrapper react package
|
|
884
|
+
*/
|
|
885
|
+
declare function LocaleSelector(_props: LocaleSelectorProps): React$1.JSX.Element | null;
|
|
886
|
+
//#endregion
|
|
887
|
+
//#region src/hooks/useLocaleSelector.d.ts
|
|
888
|
+
/**
|
|
889
|
+
*
|
|
890
|
+
* Gets the list of properties for using a locale selector.
|
|
891
|
+
* Provides locale management utilities for the application.
|
|
892
|
+
* @param locales an optional list of locales to use for the drop down. These locales must be a subset of the locales provided by the `<GTProvider>` context. When not provided, the list of locales from the `<GTProvider>` context is used.
|
|
893
|
+
*
|
|
894
|
+
* @returns {Object} An object containing locale-related utilities:
|
|
895
|
+
* @returns {string} return.locale - The currently selected locale.
|
|
896
|
+
* @returns {string[]} return.locales - The list of all available locales.
|
|
897
|
+
* @returns {(locale: string) => void} return.setLocale - Function to update the current locale.
|
|
898
|
+
* @returns {(locale: string) => LocaleProperties} return.getLocaleProperties - Function to retrieve properties for a given locale.
|
|
899
|
+
*/
|
|
900
|
+
declare function useLocaleSelector(locales?: string[]): {
|
|
901
|
+
locale: string;
|
|
902
|
+
locales: string[];
|
|
903
|
+
setLocale: (locale: string) => void;
|
|
904
|
+
getLocaleProperties: (locale: string) => LocaleProperties;
|
|
905
|
+
};
|
|
906
|
+
//#endregion
|
|
907
|
+
//#region src/ui/RegionSelector.d.ts
|
|
908
|
+
/**
|
|
909
|
+
* @deprecated - this function is to always be overridden by a wrapper react package
|
|
910
|
+
*/
|
|
911
|
+
declare function RegionSelector<Regions extends string[]>(_props: RegionSelectorProps<Regions>): React$1.JSX.Element | null;
|
|
912
|
+
//#endregion
|
|
913
|
+
//#region src/hooks/useGTClass.d.ts
|
|
914
|
+
/**
|
|
915
|
+
* Returns the configured GT class instance.
|
|
916
|
+
*
|
|
917
|
+
* @returns {GT} The configured GT class instance.
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* const gt = useGTClass();
|
|
921
|
+
* console.log(gt.getLocaleProperties('en-US'));
|
|
922
|
+
*/
|
|
923
|
+
declare function useGTClass(): _$generaltranslation.GT;
|
|
924
|
+
/**
|
|
925
|
+
* Returns the locale properties for the given locale.
|
|
926
|
+
*
|
|
927
|
+
* @param {string} locale - The locale to get the properties for.
|
|
928
|
+
* @returns {LocaleProperties} The locale properties for the given locale.
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* const localeProperties = useLocaleProperties('en-US');
|
|
932
|
+
* console.log(localeProperties);
|
|
933
|
+
*/
|
|
934
|
+
declare function useLocaleProperties(locale: string): LocaleProperties;
|
|
935
|
+
//#endregion
|
|
936
|
+
//#region src/hooks/useRegionSelector.d.ts
|
|
937
|
+
type RegionData = {
|
|
938
|
+
code: string;
|
|
939
|
+
name: string;
|
|
940
|
+
emoji: string;
|
|
941
|
+
locale: string;
|
|
942
|
+
};
|
|
943
|
+
/**
|
|
944
|
+
* React hook for managing region selection logic in applications supporting multiple regions.
|
|
945
|
+
*
|
|
946
|
+
* This hook provides the necessary data and handlers to implement a region selector UI component.
|
|
947
|
+
* It returns the current region, a list of available regions, region metadata, and functions to update the region or associated locale.
|
|
948
|
+
*
|
|
949
|
+
* ### Parameters
|
|
950
|
+
* @param {Object} [options] - Optional configuration object.
|
|
951
|
+
* @param {string[]} [options.regions] - An optional array of ISO 3166 region codes to display. If not provided, regions are inferred from supported locales.
|
|
952
|
+
* @param {Object.<string, string|{name?: string, emoji?: string, locale?: string}>} [options.customMapping] - Optional mapping to override region display names, emojis, or associated locales.
|
|
953
|
+
* @param {boolean} [options.prioritizeCurrentLocaleRegion=true] - If true, the region corresponding to the current locale is prioritized in the list.
|
|
954
|
+
* @param {boolean} [options.sortRegionsAlphabetically=true] - If true, regions are sorted alphabetically by display name.
|
|
955
|
+
*
|
|
956
|
+
* ### Returns
|
|
957
|
+
* @returns {{
|
|
958
|
+
* region: string | undefined,
|
|
959
|
+
* setRegion: (region: string) => void,
|
|
960
|
+
* regions: string[],
|
|
961
|
+
* regionData: Map<string, { code: string, name: string, emoji: string, locale: string }>,
|
|
962
|
+
* locale: string,
|
|
963
|
+
* setLocale: (locale: string) => void
|
|
964
|
+
* }} An object containing:
|
|
965
|
+
* - `region`: The currently selected region code.
|
|
966
|
+
* - `setRegion`: Function to update the selected region.
|
|
967
|
+
* - `regions`: Array of available region codes.
|
|
968
|
+
* - `regionData`: Map of region codes to their display data (name, emoji, locale).
|
|
969
|
+
* - `locale`: The current locale.
|
|
970
|
+
* - `setLocale`: Function to update the locale.
|
|
971
|
+
*
|
|
972
|
+
* ### Example
|
|
973
|
+
* ```tsx
|
|
974
|
+
* const {
|
|
975
|
+
* region,
|
|
976
|
+
* setRegion,
|
|
977
|
+
* regions,
|
|
978
|
+
* regionData,
|
|
979
|
+
* locale,
|
|
980
|
+
* setLocale
|
|
981
|
+
* } = useRegionSelector({
|
|
982
|
+
* customMapping: { US: { name: "United States", emoji: "🇺🇸" } }
|
|
983
|
+
* });
|
|
984
|
+
*
|
|
985
|
+
* return (
|
|
986
|
+
* <select value={region} onChange={e => setRegion(e.target.value)}>
|
|
987
|
+
* {regions.map(r => (
|
|
988
|
+
* <option key={r} value={r}>
|
|
989
|
+
* {regionData.get(r)?.name}
|
|
990
|
+
* </option>
|
|
991
|
+
* ))}
|
|
992
|
+
* </select>
|
|
993
|
+
* );
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
declare function useRegionSelector({
|
|
997
|
+
regions: _regions,
|
|
998
|
+
customMapping,
|
|
999
|
+
prioritizeCurrentLocaleRegion,
|
|
1000
|
+
sortRegionsAlphabetically
|
|
1001
|
+
}?: {
|
|
1002
|
+
regions?: string[];
|
|
1003
|
+
customMapping?: {
|
|
1004
|
+
[region: string]: string | {
|
|
1005
|
+
name?: string;
|
|
1006
|
+
emoji?: string;
|
|
1007
|
+
locale?: string;
|
|
1008
|
+
};
|
|
1009
|
+
};
|
|
1010
|
+
prioritizeCurrentLocaleRegion?: boolean;
|
|
1011
|
+
sortRegionsAlphabetically?: boolean;
|
|
1012
|
+
}): {
|
|
1013
|
+
region: string | undefined;
|
|
1014
|
+
setRegion: (region: string | undefined) => void;
|
|
1015
|
+
regions: string[];
|
|
1016
|
+
regionData: Map<string, RegionData>;
|
|
1017
|
+
locales: string[];
|
|
1018
|
+
locale: string;
|
|
1019
|
+
localeRegion: string;
|
|
1020
|
+
setLocale: (locale: string) => void;
|
|
1021
|
+
};
|
|
1022
|
+
//#endregion
|
|
1023
|
+
//#region src/hooks/useLocaleDirection.d.ts
|
|
1024
|
+
/**
|
|
1025
|
+
* Retrieves the text direction ('ltr' or 'rtl') for the current or specified locale from the `<GTProvider>` context.
|
|
1026
|
+
*
|
|
1027
|
+
* If no locale is provided, the direction for the current user's locale is returned.
|
|
1028
|
+
*
|
|
1029
|
+
* @param {string} [locale] - Optional locale code (e.g., 'ar', 'en-US'). If omitted, uses the current locale from context.
|
|
1030
|
+
* @returns {'ltr' | 'rtl'} The text direction for the locale: 'rtl' for right-to-left languages, otherwise 'ltr'.
|
|
1031
|
+
*
|
|
1032
|
+
* @example
|
|
1033
|
+
* const dir = useLocaleDirection(); // e.g., 'ltr'
|
|
1034
|
+
* const arabicDir = useLocaleDirection('ar'); // 'rtl'
|
|
1035
|
+
*/
|
|
1036
|
+
declare function useLocaleDirection(locale?: string): 'ltr' | 'rtl';
|
|
1037
|
+
//#endregion
|
|
1038
|
+
//#region ../i18n/dist/index-BLWcN0wI.d.cts
|
|
1039
|
+
//#region src/translation-functions/fallbacks/gtFallback.d.ts
|
|
1040
|
+
/**
|
|
1041
|
+
* A fallback function for the gt() function that decodes and interpolates.
|
|
1042
|
+
* @param {string | null | undefined} message - The ICU formatted message to interpolate.
|
|
1043
|
+
* @param {InlineTranslationOptions} options - The options to interpolate.
|
|
1044
|
+
* @returns - The decoded and interpolated message.
|
|
1045
|
+
*
|
|
1046
|
+
* @note This function is useful as a placeholder when for incrementally migrating to the m() function.
|
|
1047
|
+
* @example
|
|
1048
|
+
* // A backwards compatible translation function
|
|
1049
|
+
* function getMessage(gt: GTFunctionType = gtFallback) {
|
|
1050
|
+
* return gt('Hello, world!');
|
|
1051
|
+
* }
|
|
1052
|
+
*
|
|
1053
|
+
* // Here i18n has been implemented
|
|
1054
|
+
* function WithTranslation() {
|
|
1055
|
+
* const gt = useGT();
|
|
1056
|
+
* return <>{getMessage(gt)}</>;
|
|
1057
|
+
* }
|
|
1058
|
+
*
|
|
1059
|
+
*
|
|
1060
|
+
* // i18n has not yet been implemented yet
|
|
1061
|
+
* function WithoutTranslations() {
|
|
1062
|
+
* return <>{getMessage()}</>;
|
|
1063
|
+
* }
|
|
1064
|
+
*/
|
|
1065
|
+
declare const gtFallback: GTFunctionType; //#endregion
|
|
1066
|
+
//#region src/translation-functions/fallbacks/mFallback.d.ts
|
|
1067
|
+
/**
|
|
1068
|
+
* A fallback function for the m() function that decodes and interpolates.
|
|
1069
|
+
* @param {string | null | undefined} encodedMsg - The encoded message to decode and interpolate.
|
|
1070
|
+
* @param {InlineTranslationOptions} options - The options to interpolate.
|
|
1071
|
+
* @returns - The decoded and interpolated message.
|
|
1072
|
+
*
|
|
1073
|
+
* @note This function is useful as a placeholder when for incrementally migrating to the m() function.
|
|
1074
|
+
* @example
|
|
1075
|
+
* // A backwards compatible translation function
|
|
1076
|
+
* function getMessage(m: MFunctionType = mFallback) {
|
|
1077
|
+
* return m(msg('Hello, world!'));
|
|
1078
|
+
* }
|
|
1079
|
+
*
|
|
1080
|
+
* // Here i18n has been implemented
|
|
1081
|
+
* function WithTranslation() {
|
|
1082
|
+
* const m = useMessages();
|
|
1083
|
+
* return <>{getMessage(m)}</>;
|
|
1084
|
+
* }
|
|
1085
|
+
*
|
|
1086
|
+
*
|
|
1087
|
+
* // i18n has not yet been implemented yet
|
|
1088
|
+
* function WithoutTranslations() {
|
|
1089
|
+
* return <>{getMessage()}</>;
|
|
1090
|
+
* }
|
|
1091
|
+
*/
|
|
1092
|
+
declare const mFallback: MFunctionType; //#endregion
|
|
1093
|
+
//#endregion
|
|
1094
|
+
//#region ../core/dist/internal.d.cts
|
|
1095
|
+
//#endregion
|
|
1096
|
+
//#region src/derive/decodeVars.d.ts
|
|
1097
|
+
/**
|
|
1098
|
+
* Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()
|
|
1099
|
+
* @example
|
|
1100
|
+
* const encodedIcu = "Hi" + declareVar("Brian") + ", my name is {name}"
|
|
1101
|
+
* // 'Hi {_gt_, select, other {Brian}}, my name is {name}'
|
|
1102
|
+
* decodeVars(encodedIcu)
|
|
1103
|
+
* // 'Hi Brian, my name is {name}'
|
|
1104
|
+
*/
|
|
1105
|
+
declare function decodeVars(icuString: string): string; //#endregion
|
|
1106
|
+
//#region src/derive/declareVar.d.ts
|
|
1107
|
+
/**
|
|
1108
|
+
* Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).
|
|
1109
|
+
*
|
|
1110
|
+
* @example
|
|
1111
|
+
* function nonDerivableFunction() {
|
|
1112
|
+
* return Math.random();
|
|
1113
|
+
* }
|
|
1114
|
+
*
|
|
1115
|
+
* function derivableFunction() {
|
|
1116
|
+
* if (condition) {
|
|
1117
|
+
* return declareVar(nonDerivableFunction())
|
|
1118
|
+
* }
|
|
1119
|
+
* return 'John Doe';
|
|
1120
|
+
* }
|
|
1121
|
+
*
|
|
1122
|
+
* const gt = useGT();
|
|
1123
|
+
* gt(`My name is ${derive(derivableFunction())}`);
|
|
1124
|
+
*
|
|
1125
|
+
* @param {string | number | boolean | null | undefined} variable - The variable to sanitize.
|
|
1126
|
+
* @param {Object} [options] - The options for the sanitization.
|
|
1127
|
+
* @param {string} [options.$name] - The name of the variable.
|
|
1128
|
+
* @returns {string} The sanitized value.
|
|
1129
|
+
*/
|
|
1130
|
+
declare function declareVar(variable: string | number | boolean | null | undefined, options?: {
|
|
1131
|
+
$name?: string;
|
|
1132
|
+
}): string; //#endregion
|
|
1133
|
+
//#region src/derive/derive.d.ts
|
|
1134
|
+
/**
|
|
1135
|
+
* Marks content as derivable by the GT compiler and CLI.
|
|
1136
|
+
*
|
|
1137
|
+
* Use `derive()` when a translation string or context needs content that is
|
|
1138
|
+
* computed from source code, but should still be discovered during extraction
|
|
1139
|
+
* instead of treated as a runtime interpolation variable. The CLI attempts to
|
|
1140
|
+
* resolve the derivable expression into every possible static value and
|
|
1141
|
+
* includes those values in the source content that gets translated.
|
|
1142
|
+
*
|
|
1143
|
+
* `derive()` returns its argument unchanged at runtime.
|
|
1144
|
+
*
|
|
1145
|
+
* Run `gt validate` after adding or changing `derive()` calls to verify that
|
|
1146
|
+
* each derivable expression can be resolved by the CLI before translating or
|
|
1147
|
+
* building.
|
|
1148
|
+
*
|
|
1149
|
+
* @example
|
|
1150
|
+
* ```jsx
|
|
1151
|
+
* function getSubject() {
|
|
1152
|
+
* return (Math.random() > 0.5) ? "Alice" : "Brian";
|
|
1153
|
+
* }
|
|
1154
|
+
* ...
|
|
1155
|
+
* gt(`My name is ${derive(getSubject())}`);
|
|
1156
|
+
* ```
|
|
1157
|
+
*
|
|
1158
|
+
* @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
|
|
1159
|
+
* @returns {T} The same content, unchanged at runtime.
|
|
1160
|
+
*/
|
|
1161
|
+
declare function derive<T extends string | boolean | number | null | undefined>(content: T): T;
|
|
1162
|
+
/**
|
|
1163
|
+
* @deprecated Use derive() instead.
|
|
1164
|
+
*
|
|
1165
|
+
* Marks content as derivable by the GT compiler and CLI.
|
|
1166
|
+
*
|
|
1167
|
+
* Use `derive()` instead of `declareStatic()` for new code. This alias is kept
|
|
1168
|
+
* for backwards compatibility and returns its argument unchanged at runtime.
|
|
1169
|
+
*
|
|
1170
|
+
* Run `gt validate` after adding or changing derived content to verify that
|
|
1171
|
+
* each derivable expression can be resolved by the CLI before translating or
|
|
1172
|
+
* building.
|
|
1173
|
+
*
|
|
1174
|
+
* @example
|
|
1175
|
+
* ```jsx
|
|
1176
|
+
* function getSubject() {
|
|
1177
|
+
* return (Math.random() > 0.5) ? "Alice" : "Brian";
|
|
1178
|
+
* }
|
|
1179
|
+
* ...
|
|
1180
|
+
* gt(`My name is ${declareStatic(getSubject())}`);
|
|
1181
|
+
* ```
|
|
1182
|
+
*
|
|
1183
|
+
* @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
|
|
1184
|
+
* @returns {T} The same content, unchanged at runtime.
|
|
1185
|
+
*/
|
|
1186
|
+
declare const declareStatic: typeof derive; //#endregion
|
|
1187
|
+
//#region src/derive/indexVars.d.ts
|
|
1188
|
+
/**
|
|
1189
|
+
* Given an ICU string adds identifiers to each _gt_ placeholder
|
|
1190
|
+
* indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'
|
|
1191
|
+
*/
|
|
1192
|
+
//#endregion
|
|
1193
|
+
//#region ../i18n/dist/index.d.cts
|
|
1194
|
+
//#endregion
|
|
1195
|
+
//#region src/translation-functions/msg/msg.d.ts
|
|
1196
|
+
/**
|
|
1197
|
+
* Registers a message to be translated. Returns the message unchanged if no options are provided.
|
|
1198
|
+
* @param {string | string[]} message The message to encode.
|
|
1199
|
+
* @param {InlineTranslationOptions} [options] The options to encode.
|
|
1200
|
+
* @returns The message or array of messages.
|
|
1201
|
+
*
|
|
1202
|
+
* @note - This function registers the message before the build process. The actual translation does not
|
|
1203
|
+
* occur until the m() function is invoked.
|
|
1204
|
+
*
|
|
1205
|
+
* @note - Message format
|
|
1206
|
+
* A message is broken into two parts separated by colons:
|
|
1207
|
+
* - interpolated content - the content with interpolated variables
|
|
1208
|
+
* - hash + options - a unique identifier for the source content and options for the translation
|
|
1209
|
+
*
|
|
1210
|
+
* @example - Basic usage
|
|
1211
|
+
*
|
|
1212
|
+
* const message1 = msg('Hello, World!');
|
|
1213
|
+
* console.log(message1); // "Hello, World!"
|
|
1214
|
+
*
|
|
1215
|
+
* const message2 = msg('Hello, {name}!', { name: 'Brian' });
|
|
1216
|
+
* console.log(message2); // "Hello, Brian:eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9"
|
|
1217
|
+
*
|
|
1218
|
+
* @example - Array usage
|
|
1219
|
+
*
|
|
1220
|
+
* const messages = msg(['Hello, Alice!', 'Hello, Bob!']);
|
|
1221
|
+
* console.log(messages); // ["Hello, Alice!", "Hello, Bob!"]
|
|
1222
|
+
*
|
|
1223
|
+
* @example - When specifying an id for an array, each message will have a unique id of `${id}.${index}`
|
|
1224
|
+
* const messages = msg(['Hello, Alice!', 'Hello, Bob!'], { $id: 'greetings' });
|
|
1225
|
+
* // "Hello, Alice!" id: "greetings.0"
|
|
1226
|
+
* // "Hello, Bob!" id: "greetings.1"
|
|
1227
|
+
*
|
|
1228
|
+
* @important Internal note: until other packages are updated to use i18n-context practices, msg cannot use any functions that use i18nManager at all!
|
|
1229
|
+
*/
|
|
1230
|
+
declare function msg<T extends RegisterableMessages = string>(message: T): T;
|
|
1231
|
+
declare function msg<T extends RegisterableMessages = string>(message: T, options?: InlineTranslationOptions): T extends string ? string : string[]; //#endregion
|
|
1232
|
+
//#region src/translation-functions/msg/decodeMsg.d.ts
|
|
1233
|
+
/**
|
|
1234
|
+
* Extracts the original interpolated message string.
|
|
1235
|
+
* If the message cannot be decoded (i.e., it does not contain a colon separator),
|
|
1236
|
+
* the input is returned as-is.
|
|
1237
|
+
* @param encodedMsg The message to decode.
|
|
1238
|
+
* @returns The decoded message, or the input if it cannot be decoded.
|
|
1239
|
+
*/
|
|
1240
|
+
declare function decodeMsg(encodedMsg: string): string;
|
|
1241
|
+
declare function decodeMsg<T extends null | undefined>(encodedMsg: T): T;
|
|
1242
|
+
declare function decodeMsg<T extends string | null | undefined>(encodedMsg: T): T extends string ? string : T; //#endregion
|
|
1243
|
+
//#region src/translation-functions/msg/decodeOptions.d.ts
|
|
1244
|
+
/**
|
|
1245
|
+
* Decodes the options from an encoded message.
|
|
1246
|
+
* @param encodedMsg The message to decode.
|
|
1247
|
+
* @returns The decoded options.
|
|
1248
|
+
*/
|
|
1249
|
+
declare function decodeOptions(encodedMsg: string): InlineTranslationOptions | null; //#endregion
|
|
1250
|
+
//#endregion
|
|
1251
|
+
//#region src/translation/hooks/useMessages.d.ts
|
|
1252
|
+
/**
|
|
1253
|
+
* Gets the message decoding and translation function `m` provided by `<GTProvider>`.
|
|
1254
|
+
*
|
|
1255
|
+
* @returns {Function} A translation function that accepts an encoded message, decodes it, and returns the translated value.
|
|
1256
|
+
*
|
|
1257
|
+
* @example
|
|
1258
|
+
* const encodedMessage = msg("Hello, world")
|
|
1259
|
+
* const m = useMessages();
|
|
1260
|
+
* m(encodedMessage) // returns "Hello, world" translated
|
|
1261
|
+
*
|
|
1262
|
+
* @example
|
|
1263
|
+
* const encodedMessage = msg("My name is {name}", { name: "Brian" });
|
|
1264
|
+
* const m = useMessages();
|
|
1265
|
+
* m(encodedMessage) // returns "My name is Brian" translated
|
|
1266
|
+
*/
|
|
1267
|
+
declare function useMessages(_messages?: _Messages): MFunctionType;
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/types-dir/runtime.d.ts
|
|
1270
|
+
type TranslateIcuCallback = (params: {
|
|
1271
|
+
source: string;
|
|
1272
|
+
targetLocale: string;
|
|
1273
|
+
metadata: {
|
|
1274
|
+
hash: string;
|
|
1275
|
+
context?: string;
|
|
1276
|
+
maxChars?: number;
|
|
1277
|
+
} & Record<string, unknown>;
|
|
1278
|
+
}) => Promise<TranslatedChildren>;
|
|
1279
|
+
type TranslateChildrenCallback = (params: {
|
|
1280
|
+
source: JsxChildren | undefined;
|
|
1281
|
+
targetLocale: string;
|
|
1282
|
+
metadata: {
|
|
1283
|
+
hash: string;
|
|
1284
|
+
context?: string;
|
|
1285
|
+
maxChars?: number;
|
|
1286
|
+
} & Record<string, unknown>;
|
|
1287
|
+
}) => Promise<TranslatedChildren>;
|
|
1288
|
+
//#endregion
|
|
1289
|
+
//#region src/types-dir/context.d.ts
|
|
1290
|
+
type GTContextType = {
|
|
1291
|
+
gt: GT;
|
|
1292
|
+
registerIcuForTranslation: TranslateIcuCallback;
|
|
1293
|
+
registerJsxForTranslation: TranslateChildrenCallback;
|
|
1294
|
+
_gtFunction: (message: string, options?: InlineTranslationOptions, preloadedTranslations?: Translations) => string;
|
|
1295
|
+
_mFunction: <T extends string | null | undefined>(encodedMsg: T, options?: Record<string, unknown>, preloadedTranslations?: Translations) => T extends string ? string : T;
|
|
1296
|
+
_filterMessagesForPreload: (_messages: _Messages) => _Messages;
|
|
1297
|
+
_preloadMessages: (_messages: _Messages) => Promise<Translations>;
|
|
1298
|
+
_dictionaryFunction: (id: string, options?: DictionaryTranslationOptions) => string;
|
|
1299
|
+
_dictionaryObjFunction: (id: string, idWithParent: string, options?: DictionaryTranslationOptions) => Dictionary | DictionaryEntry | string | undefined;
|
|
1300
|
+
developmentApiEnabled: boolean;
|
|
1301
|
+
locale: string;
|
|
1302
|
+
locales: string[];
|
|
1303
|
+
setLocale: (locale: string) => void;
|
|
1304
|
+
defaultLocale: string;
|
|
1305
|
+
region: string | undefined;
|
|
1306
|
+
setRegion: (region: string | undefined) => void;
|
|
1307
|
+
translations: Translations | null;
|
|
1308
|
+
translationRequired: boolean;
|
|
1309
|
+
dialectTranslationRequired: boolean;
|
|
1310
|
+
renderSettings: {
|
|
1311
|
+
method: RenderMethod;
|
|
1312
|
+
timeout?: number;
|
|
1313
|
+
};
|
|
1314
|
+
projectId?: string;
|
|
1315
|
+
_versionId?: string;
|
|
1316
|
+
};
|
|
1317
|
+
//#endregion
|
|
1318
|
+
//#region src/provider/GTContext.d.ts
|
|
1319
|
+
declare const GTContext: _$react.Context<GTContextType | undefined>;
|
|
1320
|
+
//#endregion
|
|
1321
|
+
//#region src/provider/hooks/useRuntimeTranslation.d.ts
|
|
1322
|
+
declare function useRuntimeTranslation({
|
|
1323
|
+
gt,
|
|
1324
|
+
locale,
|
|
1325
|
+
versionId: _versionId,
|
|
1326
|
+
// kept for API compatibility (not used)
|
|
1327
|
+
defaultLocale,
|
|
1328
|
+
runtimeUrl,
|
|
1329
|
+
renderSettings,
|
|
1330
|
+
setTranslations,
|
|
1331
|
+
environment,
|
|
1332
|
+
...additionalMetadata
|
|
1333
|
+
}: {
|
|
1334
|
+
gt: GT;
|
|
1335
|
+
locale: string;
|
|
1336
|
+
versionId?: string;
|
|
1337
|
+
defaultLocale?: string;
|
|
1338
|
+
runtimeUrl?: string | null;
|
|
1339
|
+
renderSettings: {
|
|
1340
|
+
method: RenderMethod;
|
|
1341
|
+
timeout?: number;
|
|
1342
|
+
};
|
|
1343
|
+
environment: 'development' | 'production' | 'test';
|
|
1344
|
+
setTranslations: _$react.Dispatch<_$react.SetStateAction<Translations | null>>;
|
|
1345
|
+
[key: string]: unknown;
|
|
1346
|
+
}): {
|
|
1347
|
+
registerIcuForTranslation: TranslateIcuCallback;
|
|
1348
|
+
registerJsxForTranslation: TranslateChildrenCallback;
|
|
1349
|
+
developmentApiEnabled: boolean;
|
|
1350
|
+
};
|
|
1351
|
+
//#endregion
|
|
1352
|
+
//#region src/provider/hooks/translation/useCreateInternalUseGTFunction.d.ts
|
|
1353
|
+
declare function useCreateInternalUseGTFunction({
|
|
1354
|
+
gt,
|
|
1355
|
+
translations,
|
|
1356
|
+
locale,
|
|
1357
|
+
defaultLocale,
|
|
1358
|
+
translationRequired,
|
|
1359
|
+
developmentApiEnabled,
|
|
1360
|
+
registerIcuForTranslation,
|
|
1361
|
+
environment
|
|
1362
|
+
}: {
|
|
1363
|
+
gt: GT;
|
|
1364
|
+
translations: Translations | null;
|
|
1365
|
+
locale: string;
|
|
1366
|
+
defaultLocale: string;
|
|
1367
|
+
translationRequired: boolean;
|
|
1368
|
+
developmentApiEnabled: boolean;
|
|
1369
|
+
registerIcuForTranslation: TranslateIcuCallback;
|
|
1370
|
+
environment: 'development' | 'production' | 'test';
|
|
1371
|
+
}): {
|
|
1372
|
+
_gtFunction: (message: string, options?: InlineTranslationOptions, preloadedTranslations?: Translations) => string;
|
|
1373
|
+
_mFunction: <T extends string | null | undefined>(message: T, options?: Record<string, unknown>, preloadedTranslations?: Translations) => T extends string ? string : T;
|
|
1374
|
+
_filterMessagesForPreload: (_messages: _Messages) => _Messages;
|
|
1375
|
+
_preloadMessages: (_messages: _Messages) => Promise<Translations>;
|
|
1376
|
+
};
|
|
1377
|
+
//#endregion
|
|
1378
|
+
//#region src/provider/hooks/translation/useCreateInternalUseTranslationsFunction.d.ts
|
|
1379
|
+
declare function useCreateInternalUseTranslationsFunction(gt: GT, dictionary: Dictionary | undefined, dictionaryTranslations: Dictionary | undefined, translations: Translations | null, locale: string, defaultLocale: string, translationRequired: boolean, dialectTranslationRequired: boolean, developmentApiEnabled: boolean, registerIcuForTranslation: TranslateIcuCallback, environment: 'development' | 'production' | 'test'): (id: string, options?: DictionaryTranslationOptions) => string;
|
|
1380
|
+
//#endregion
|
|
1381
|
+
//#region src/provider/hooks/translation/useCreateInternalUseTranslationsObjFunction.d.ts
|
|
1382
|
+
declare function useCreateInternalUseTranslationsObjFunction(dictionary: Dictionary, dictionaryTranslations: Dictionary, setDictionary: Function, setDictionaryTranslations: Function, translations: Translations | null, locale: string, defaultLocale: string, translationRequired: boolean, dialectTranslationRequired: boolean, developmentApiEnabled: boolean, registerIcuForTranslation: TranslateIcuCallback, gtFunction: (id: string, options: DictionaryTranslationOptions) => string): (id: string, idWithParent: string, options?: DictionaryTranslationOptions) => Dictionary | DictionaryEntry | undefined;
|
|
1383
|
+
//#endregion
|
|
1384
|
+
export { Branch, Currency, DateTime, Derive, type DictionaryTranslationOptions, GTContext, GTProvider, type InlineTranslationOptions, LocaleSelector, Num, Plural, RegionSelector, RelativeTime, type RuntimeTranslationOptions, Static, T, Var, declareStatic, declareVar, decodeMsg, decodeOptions, decodeVars, derive, gtFallback, mFallback, msg, useCreateInternalUseGTFunction, useCreateInternalUseTranslationsFunction, useCreateInternalUseTranslationsObjFunction, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleDirection, useLocaleProperties, useLocaleSelector, useLocales, useMessages, useRegion, useRegionSelector, useRuntimeTranslation, useSetLocale, useTranslations, useVersionId };
|
|
36
1385
|
//# sourceMappingURL=index.d.ts.map
|