gt-react 10.7.0-alpha.1 β 10.7.0-alpha.3
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 +97 -0
- package/dist/client.cjs.min.cjs +17 -16
- package/dist/client.cjs.min.cjs.map +1 -0
- package/dist/client.d.ts +7 -740
- package/dist/client.d.ts.map +1 -1
- package/dist/client.esm.min.mjs +17 -16
- package/dist/client.esm.min.mjs.map +1 -0
- package/dist/errors-dir/constants.d.ts +2 -0
- package/dist/errors-dir/constants.d.ts.map +1 -0
- package/dist/index.cjs.min.cjs +21 -3
- package/dist/index.cjs.min.cjs.map +1 -0
- package/dist/index.d.ts +4 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.min.mjs +21 -3
- package/dist/index.esm.min.mjs.map +1 -0
- package/dist/internal.cjs.min.cjs +17 -16
- package/dist/internal.cjs.min.cjs.map +1 -0
- package/dist/internal.d.ts +5 -31
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.esm.min.mjs +17 -16
- package/dist/internal.esm.min.mjs.map +1 -0
- package/dist/provider/ClientProvider.d.ts +1 -1
- package/dist/provider/ClientProvider.d.ts.map +1 -1
- package/dist/provider/GTProvider.d.ts +3 -23
- package/dist/provider/GTProvider.d.ts.map +1 -1
- package/dist/provider/helpers/isSSREnabled.d.ts.map +1 -1
- package/dist/provider/hooks/locales/useDetermineLocale.d.ts +2 -9
- package/dist/provider/hooks/locales/useDetermineLocale.d.ts.map +1 -1
- package/dist/types/config.d.ts +23 -41
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/utils.d.ts +2 -6
- package/dist/utils/utils.d.ts.map +1 -1
- package/package.json +4 -16
- 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/config.cjs.min.cjs +0 -30
- package/dist/config.d.ts +0 -4
- package/dist/config.d.ts.map +0 -1
- package/dist/config.esm.min.mjs +0 -30
- package/dist/dictionaries/collectUntranslatedEntries.d.ts +0 -17
- 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 -17
- 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 -20
- 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/createErrors.d.ts +0 -33
- package/dist/errors/createErrors.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 -42
- 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/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/writeChildrenAsObjects.d.ts +0 -10
- package/dist/internal/writeChildrenAsObjects.d.ts.map +0 -1
- package/dist/messages/messages.d.ts +0 -43
- 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/config/defaultProps.d.ts +0 -4
- package/dist/provider/config/defaultProps.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/useLocaleState.d.ts +0 -16
- package/dist/provider/hooks/locales/useLocaleState.d.ts.map +0 -1
- package/dist/provider/hooks/translation/useCreateInternalUseGTFunction.d.ts +0 -18
- package/dist/provider/hooks/translation/useCreateInternalUseGTFunction.d.ts.map +0 -1
- package/dist/provider/hooks/translation/useCreateInternalUseTranslationsFunction.d.ts +0 -4
- 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/useErrorChecks.d.ts +0 -9
- 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/useRuntimeTranslation.d.ts +0 -23
- package/dist/provider/hooks/useRuntimeTranslation.d.ts.map +0 -1
- package/dist/rendering/defaultRenderSettings.d.ts +0 -6
- package/dist/rendering/defaultRenderSettings.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/hooks/useGT.d.ts +0 -20
- 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/translation/inline/T.d.ts +0 -42
- package/dist/translation/inline/T.d.ts.map +0 -1
- package/dist/types/context.d.ts +0 -30
- package/dist/types/context.d.ts.map +0 -1
- package/dist/types/runtime.d.ts +0 -20
- package/dist/types/runtime.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -90
- package/dist/types/types.d.ts.map +0 -1
- package/dist/utils/cookies.d.ts +0 -9
- 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/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/Num.d.ts +0 -31
- package/dist/variables/Num.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 -10
- package/dist/variables/getVariableName.d.ts.map +0 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,216 +1,9 @@
|
|
|
1
|
-
import * as React
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import React__default, { ReactNode } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import { Dictionary, Translations, RenderMethod } from '@generaltranslation/react-core/types';
|
|
4
|
+
import { CustomMapping } from 'generaltranslation/types';
|
|
5
|
+
export { Branch, Currency, DateTime, GTProvider, Num, Plural, Static, T, Var, decodeMsg, decodeOptions, msg, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleDirection, useLocaleProperties, useLocaleSelector, useLocales, useMessages, useRegion, useRegionSelector, useSetLocale, useTranslations } from '@generaltranslation/react-core';
|
|
7
6
|
|
|
8
|
-
/**
|
|
9
|
-
* For dictionaries, we have Entry and MetaEntry
|
|
10
|
-
*/
|
|
11
|
-
type Entry = string;
|
|
12
|
-
type MetaEntry = {
|
|
13
|
-
$context?: string;
|
|
14
|
-
$_hash?: string;
|
|
15
|
-
[key: string]: unknown;
|
|
16
|
-
};
|
|
17
|
-
type DictionaryEntry = Entry | [Entry] | [Entry, MetaEntry];
|
|
18
|
-
type Dictionary = {
|
|
19
|
-
[key: string]: Dictionary | DictionaryEntry;
|
|
20
|
-
} | (Dictionary | DictionaryEntry)[];
|
|
21
|
-
/**
|
|
22
|
-
* Translated content types
|
|
23
|
-
*/
|
|
24
|
-
type TranslatedElement = {
|
|
25
|
-
i?: number;
|
|
26
|
-
d?: GTProp;
|
|
27
|
-
c?: TranslatedChildren;
|
|
28
|
-
};
|
|
29
|
-
type TranslatedChild = TranslatedElement | string | Variable;
|
|
30
|
-
type TranslatedChildren = TranslatedChild | TranslatedChild[];
|
|
31
|
-
type Translations = {
|
|
32
|
-
[hash: string]: TranslatedChildren | null;
|
|
33
|
-
};
|
|
34
|
-
type CustomLoader = (locale: string) => Promise<any>;
|
|
35
|
-
type RenderMethod = 'skeleton' | 'replace' | 'default';
|
|
36
|
-
type DictionaryTranslationOptions = Record<string, any>;
|
|
37
|
-
type InlineTranslationOptions = DictionaryTranslationOptions & {
|
|
38
|
-
$context?: string;
|
|
39
|
-
$id?: string;
|
|
40
|
-
$_hash?: string;
|
|
41
|
-
$_source?: string;
|
|
42
|
-
};
|
|
43
|
-
type VariableProps = {
|
|
44
|
-
variableType: VariableType;
|
|
45
|
-
variableValue: any;
|
|
46
|
-
variableOptions: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions;
|
|
47
|
-
variableName: string;
|
|
48
|
-
};
|
|
49
|
-
type RenderVariable = ({ variableType, variableValue, variableOptions, locales, }: Omit<VariableProps, 'variableName'> & {
|
|
50
|
-
locales: string[];
|
|
51
|
-
}) => React__default.JSX.Element;
|
|
52
|
-
type _Message = {
|
|
53
|
-
message: string;
|
|
54
|
-
$id?: string;
|
|
55
|
-
$context?: string;
|
|
56
|
-
$_hash?: string;
|
|
57
|
-
};
|
|
58
|
-
type _Messages = _Message[];
|
|
59
|
-
type MFunctionType = <T extends string | null | undefined>(encodedMsg: T, options?: Record<string, any>) => T extends string ? string : T;
|
|
60
|
-
|
|
61
|
-
type TranslateIcuCallback = (params: {
|
|
62
|
-
source: string;
|
|
63
|
-
targetLocale: string;
|
|
64
|
-
metadata: {
|
|
65
|
-
hash: string;
|
|
66
|
-
context?: string;
|
|
67
|
-
} & Record<string, any>;
|
|
68
|
-
}) => Promise<TranslatedChildren>;
|
|
69
|
-
type TranslateChildrenCallback = (params: {
|
|
70
|
-
source: JsxChildren | undefined;
|
|
71
|
-
targetLocale: string;
|
|
72
|
-
metadata: {
|
|
73
|
-
hash: string;
|
|
74
|
-
context?: string;
|
|
75
|
-
} & Record<string, any>;
|
|
76
|
-
}) => Promise<TranslatedChildren>;
|
|
77
|
-
|
|
78
|
-
type GTContextType = {
|
|
79
|
-
gt: GT;
|
|
80
|
-
registerIcuForTranslation: TranslateIcuCallback;
|
|
81
|
-
registerJsxForTranslation: TranslateChildrenCallback;
|
|
82
|
-
_tFunction: (message: string, options?: InlineTranslationOptions, preloadedTranslations?: Translations) => string;
|
|
83
|
-
_mFunction: <T extends string | null | undefined>(encodedMsg: T, options?: Record<string, any>, preloadedTranslations?: Translations) => T extends string ? string : T;
|
|
84
|
-
_filterMessagesForPreload: (_messages: _Messages) => _Messages;
|
|
85
|
-
_preloadMessages: (_messages: _Messages) => Promise<Translations>;
|
|
86
|
-
_dictionaryFunction: (id: string, options?: DictionaryTranslationOptions) => string;
|
|
87
|
-
_dictionaryObjFunction: (id: string, idWithParent: string, options?: DictionaryTranslationOptions) => Dictionary | DictionaryEntry | string | undefined;
|
|
88
|
-
developmentApiEnabled: boolean;
|
|
89
|
-
locale: string;
|
|
90
|
-
locales: string[];
|
|
91
|
-
setLocale: (locale: string) => void;
|
|
92
|
-
defaultLocale: string;
|
|
93
|
-
region: string | undefined;
|
|
94
|
-
setRegion: (region: string | undefined) => void;
|
|
95
|
-
translations: Translations | null;
|
|
96
|
-
translationRequired: boolean;
|
|
97
|
-
dialectTranslationRequired: boolean;
|
|
98
|
-
renderSettings: {
|
|
99
|
-
method: RenderMethod;
|
|
100
|
-
timeout?: number;
|
|
101
|
-
};
|
|
102
|
-
projectId?: string;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
declare const GTContext: React$1.Context<GTContextType | undefined>;
|
|
106
|
-
|
|
107
|
-
declare function useRuntimeTranslation({ gt, locale, versionId, // kept for API compatibility (not used)
|
|
108
|
-
defaultLocale, runtimeUrl, renderSettings, setTranslations, ...additionalMetadata }: {
|
|
109
|
-
gt: GT;
|
|
110
|
-
locale: string;
|
|
111
|
-
versionId?: string;
|
|
112
|
-
defaultLocale?: string;
|
|
113
|
-
runtimeUrl?: string | null;
|
|
114
|
-
renderSettings: {
|
|
115
|
-
method: RenderMethod;
|
|
116
|
-
timeout?: number;
|
|
117
|
-
};
|
|
118
|
-
setTranslations: React$1.Dispatch<React$1.SetStateAction<Translations | null>>;
|
|
119
|
-
[key: string]: any;
|
|
120
|
-
}): {
|
|
121
|
-
registerIcuForTranslation: TranslateIcuCallback;
|
|
122
|
-
registerJsxForTranslation: TranslateChildrenCallback;
|
|
123
|
-
developmentApiEnabled: boolean;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
declare const renderVariable: RenderVariable;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Encodes content into a message that contains important translation metadata
|
|
130
|
-
* @param message The message to encode.
|
|
131
|
-
* @param options The options to encode.
|
|
132
|
-
* @returns The encoded message.
|
|
133
|
-
*
|
|
134
|
-
* @note - Message format
|
|
135
|
-
* A message is broken into two parts separated by colons:
|
|
136
|
-
* - interpolated content - the content with interpolated variables
|
|
137
|
-
* - hash + options - a unique identifier for the source content and options for the translation
|
|
138
|
-
*
|
|
139
|
-
* @example - Basic usage
|
|
140
|
-
*
|
|
141
|
-
* ```jsx
|
|
142
|
-
* import { msg } from 'gt-react';
|
|
143
|
-
* const message = msg('Hello, {name}!', { name: 'Brian' });
|
|
144
|
-
* console.log(message); // "Hello, Brian:eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9"
|
|
145
|
-
* ```
|
|
146
|
-
* eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9
|
|
147
|
-
* encodes to {"$_hash": "0x123", "$_source": "Hello, {name}!", "name": "Brian"}
|
|
148
|
-
*
|
|
149
|
-
*/
|
|
150
|
-
declare function msg(message: string, options?: InlineTranslationOptions): string;
|
|
151
|
-
/**
|
|
152
|
-
* Extracts the original interpolated message string.
|
|
153
|
-
* If the message cannot be decoded (i.e., it does not contain a colon separator),
|
|
154
|
-
* the input is returned as-is.
|
|
155
|
-
* @param encodedMsg The message to decode.
|
|
156
|
-
* @returns The decoded message, or the input if it cannot be decoded.
|
|
157
|
-
*/
|
|
158
|
-
declare function decodeMsg<T extends string | null | undefined>(encodedMsg: T): T;
|
|
159
|
-
/**
|
|
160
|
-
* Decodes the options from an encoded message.
|
|
161
|
-
* @param encodedMsg The message to decode.
|
|
162
|
-
* @returns The decoded options.
|
|
163
|
-
*/
|
|
164
|
-
declare function decodeOptions(encodedMsg: string): ({
|
|
165
|
-
$_source: string;
|
|
166
|
-
$_hash: string;
|
|
167
|
-
} & InlineTranslationOptions) | null;
|
|
168
|
-
|
|
169
|
-
type GTConfig = {
|
|
170
|
-
projectId?: string;
|
|
171
|
-
devApiKey?: string;
|
|
172
|
-
locales?: string[];
|
|
173
|
-
defaultLocale?: string;
|
|
174
|
-
dictionary?: string;
|
|
175
|
-
runtimeUrl?: string;
|
|
176
|
-
cacheUrl?: string;
|
|
177
|
-
renderSettings?: {
|
|
178
|
-
method: RenderMethod;
|
|
179
|
-
timeout?: number;
|
|
180
|
-
};
|
|
181
|
-
_versionId?: string;
|
|
182
|
-
ssr?: boolean;
|
|
183
|
-
localeCookieName?: string;
|
|
184
|
-
customMapping?: CustomMapping;
|
|
185
|
-
modelProvider?: string;
|
|
186
|
-
};
|
|
187
|
-
type GTProviderProps = {
|
|
188
|
-
children?: React.ReactNode;
|
|
189
|
-
projectId?: string;
|
|
190
|
-
devApiKey?: string;
|
|
191
|
-
dictionary?: any;
|
|
192
|
-
locales?: string[];
|
|
193
|
-
defaultLocale?: string;
|
|
194
|
-
locale?: string;
|
|
195
|
-
region?: string;
|
|
196
|
-
cacheUrl?: string;
|
|
197
|
-
runtimeUrl?: string;
|
|
198
|
-
renderSettings?: {
|
|
199
|
-
method: RenderMethod;
|
|
200
|
-
timeout?: number;
|
|
201
|
-
};
|
|
202
|
-
_versionId?: string;
|
|
203
|
-
ssr?: boolean;
|
|
204
|
-
localeCookieName?: string;
|
|
205
|
-
translations?: Translations | null;
|
|
206
|
-
loadDictionary?: CustomLoader;
|
|
207
|
-
loadTranslations?: CustomLoader;
|
|
208
|
-
config?: GTConfig;
|
|
209
|
-
fallback?: React.ReactNode;
|
|
210
|
-
customMapping?: CustomMapping;
|
|
211
|
-
modelProvider?: string;
|
|
212
|
-
[key: string]: any;
|
|
213
|
-
};
|
|
214
7
|
type ClientProviderProps = {
|
|
215
8
|
children: any;
|
|
216
9
|
dictionary: Dictionary;
|
|
@@ -237,293 +30,10 @@ type ClientProviderProps = {
|
|
|
237
30
|
resetLocaleCookieName: string;
|
|
238
31
|
regionCookieName?: string;
|
|
239
32
|
customMapping?: CustomMapping;
|
|
33
|
+
environment: 'development' | 'production' | 'test';
|
|
240
34
|
};
|
|
241
35
|
|
|
242
|
-
declare function ClientProvider({ children, dictionary: _dictionary, dictionaryTranslations: _dictionaryTranslations, translations: _translations, locale: _locale, region: _region, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, developmentApiEnabled, resetLocaleCookieName, localeCookieName, regionCookieName, customMapping, }: ClientProviderProps): React
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
|
|
246
|
-
* It allows for flexible content switching based on the `branch` prop and an object of possible branches (`...branches`).
|
|
247
|
-
* If the specified `branch` is present in the `branches` object, it renders the content of that branch.
|
|
248
|
-
* If the `branch` is not found, it renders the provided `children` as fallback content.
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* ```jsx
|
|
252
|
-
* <Branch
|
|
253
|
-
* branch="summary"
|
|
254
|
-
* summary={<p>This is a summary</p>}
|
|
255
|
-
* details={<p>Details here</p>}
|
|
256
|
-
* >
|
|
257
|
-
* <p>Fallback content</p>
|
|
258
|
-
* </Branch>
|
|
259
|
-
* ```
|
|
260
|
-
* 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>`.
|
|
261
|
-
*
|
|
262
|
-
* @param {any} [children] - Fallback content to render if no matching branch is found.
|
|
263
|
-
* @param {any} [name="branch"] - Optional name for the component, used for metadata or tracking purposes.
|
|
264
|
-
* @param {string} [branch] - The name of the branch to render. The component looks for this key in the `...branches` object.
|
|
265
|
-
* @param {...{[key: string]: any}} [branches] - A spread object containing possible branches as keys and their corresponding content as values.
|
|
266
|
-
* @returns {React.JSX.Element} The rendered branch or fallback content.
|
|
267
|
-
*/
|
|
268
|
-
declare function Branch({ children, branch, ...branches }: {
|
|
269
|
-
children?: any;
|
|
270
|
-
branch?: string | number | boolean;
|
|
271
|
-
[key: string]: any;
|
|
272
|
-
}): React.JSX.Element;
|
|
273
|
-
declare namespace Branch {
|
|
274
|
-
var _gtt: string;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* The `<Plural>` component dynamically renders content based on the plural form of the given number (`n`).
|
|
279
|
-
* It determines which content to display by matching the value of `n` to the appropriate pluralization branch,
|
|
280
|
-
* based on the current locale or a default locale. If no matching plural branch is found, the component renders
|
|
281
|
-
* the fallback `children` content.
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```jsx
|
|
285
|
-
* <Plural
|
|
286
|
-
* n={1}
|
|
287
|
-
* one="There is 1 item"
|
|
288
|
-
* other="There are {n} items"
|
|
289
|
-
* />
|
|
290
|
-
* ```
|
|
291
|
-
* In this example, if `n` is 1, it renders `"There is 1 item"`. If `n` is a different number, it renders
|
|
292
|
-
* `"There are {n} items"`.
|
|
293
|
-
*
|
|
294
|
-
* @param {any} [children] - Fallback content to render if no matching plural branch is found.
|
|
295
|
-
* @param {number} [n] - The number used to determine the plural form. This is required for pluralization to work.
|
|
296
|
-
* @param {string} [locales] - Optional parameter, the locale to use for pluralization format. If not provided and wrapped
|
|
297
|
-
* in <GTProvider> will automatically populate this value as user's current locale. If not provided and not wrapped in
|
|
298
|
-
* <GTProvider>, will use the library default locale (en-US).
|
|
299
|
-
* @param {...{[key: string]: any}} [branches] - A spread object containing possible plural branches, typically including `one` for singular
|
|
300
|
-
* and `other` for plural forms, but it may vary depending on the locale.
|
|
301
|
-
* @returns {React.JSX.Element} The rendered content corresponding to the plural form of `n`, or the fallback content.
|
|
302
|
-
* @throws {Error} If `n` is not provided or not a valid number.
|
|
303
|
-
*/
|
|
304
|
-
declare function Plural({ children, n, locales, ...branches }: {
|
|
305
|
-
children?: React.ReactNode;
|
|
306
|
-
n?: number;
|
|
307
|
-
locales?: string;
|
|
308
|
-
[key: string]: any;
|
|
309
|
-
}): React.JSX.Element;
|
|
310
|
-
declare namespace Plural {
|
|
311
|
-
var _gtt: string;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Gets the translation function `gt` provided by `<GTProvider>`.
|
|
316
|
-
*
|
|
317
|
-
* @returns {Function} A translation function that accepts an ICU message format string and returns the translation of that string.
|
|
318
|
-
*
|
|
319
|
-
* @example
|
|
320
|
-
* const gt = useGT();
|
|
321
|
-
* console.log(gt('To be or not to be...'));
|
|
322
|
-
*
|
|
323
|
-
* @example
|
|
324
|
-
* const gt = useGT();
|
|
325
|
-
* gt('My name is {customName}', { customName: "Brian", id: 'my-name', context: 'a proper noun' } )
|
|
326
|
-
*/
|
|
327
|
-
declare function useGT(_messages?: _Messages): (string: string, options?: Record<string, any> & {
|
|
328
|
-
$id?: string;
|
|
329
|
-
$context?: string;
|
|
330
|
-
$_hash?: string;
|
|
331
|
-
}) => string;
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Retrieves the application's default locale from the `<GTProvider>` context.
|
|
335
|
-
*
|
|
336
|
-
* If no default locale is passed to the `<GTProvider>`, it defaults to providing 'en'.
|
|
337
|
-
*
|
|
338
|
-
* @returns {string} The application's default locale, e.g., 'en-US'.
|
|
339
|
-
*
|
|
340
|
-
* @example
|
|
341
|
-
* const locale = useDefaultLocale();
|
|
342
|
-
* console.log(locale); // 'en-US'
|
|
343
|
-
*/
|
|
344
|
-
declare function useDefaultLocale(): string;
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Gets the dictionary access function `t` provided by `<GTProvider>`.
|
|
348
|
-
*
|
|
349
|
-
* @param {string} [id] - Optional prefix to prepend to the translation keys.
|
|
350
|
-
* @returns {Function} A translation function that accepts a key string and returns the translated value.
|
|
351
|
-
*
|
|
352
|
-
* @example
|
|
353
|
-
* const t = useTranslations('user');
|
|
354
|
-
* console.log(t('name')); // Translates item 'user.name'
|
|
355
|
-
*
|
|
356
|
-
* const t = useTranslations();
|
|
357
|
-
* console.log(t('hello')); // Translates item 'hello'
|
|
358
|
-
*/
|
|
359
|
-
declare function useTranslations(id?: string): ((id: string, options?: Record<string, any>) => string) & {
|
|
360
|
-
obj: (id: string, options?: Record<string, any>) => any | undefined;
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Retrieves the user's locale from the `<GTProvider>` context.
|
|
365
|
-
*
|
|
366
|
-
* @returns {string} The user's locale, e.g., 'en-US'.
|
|
367
|
-
*
|
|
368
|
-
* @example
|
|
369
|
-
* const locale = useLocale();
|
|
370
|
-
* console.log(locale); // 'en-US'
|
|
371
|
-
*/
|
|
372
|
-
declare function useLocale(): string;
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Build-time translation component that renders its children in the user's given locale.
|
|
376
|
-
*
|
|
377
|
-
* @example
|
|
378
|
-
* ```jsx
|
|
379
|
-
* // Basic usage:
|
|
380
|
-
* <T id="welcome_message">
|
|
381
|
-
* Hello, <Var>{name}</Var>!
|
|
382
|
-
* </T>
|
|
383
|
-
* ```
|
|
384
|
-
*
|
|
385
|
-
* @example
|
|
386
|
-
* ```jsx
|
|
387
|
-
* // Translating a plural
|
|
388
|
-
* <T id="item_count">
|
|
389
|
-
* <Plural n={3} singular={<>You have <Num children={n}/> item.</>}>
|
|
390
|
-
* You have <Num children={n}/> items.
|
|
391
|
-
* </Plural>
|
|
392
|
-
* </T>
|
|
393
|
-
* ```
|
|
394
|
-
*
|
|
395
|
-
* @param {React.ReactNode} children - The content to be translated or displayed.
|
|
396
|
-
* @param {string} [id] - Optional identifier for the translation string. If not provided, a hash will be generated from the content.
|
|
397
|
-
* @param {any} [context] - Additional context for translation key generation.
|
|
398
|
-
*
|
|
399
|
-
* @returns {JSX.Element} The rendered translation or fallback content based on the provided configuration.
|
|
400
|
-
*
|
|
401
|
-
* @throws {Error} If a plural translation is requested but the `n` option is not provided.
|
|
402
|
-
*/
|
|
403
|
-
declare function T({ children, id, context, _hash, ...options }: {
|
|
404
|
-
children: any;
|
|
405
|
-
id?: string;
|
|
406
|
-
context?: string;
|
|
407
|
-
_hash?: string;
|
|
408
|
-
[key: string]: any;
|
|
409
|
-
}): React__default.JSX.Element | undefined;
|
|
410
|
-
declare namespace T {
|
|
411
|
-
var _gtt: string;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* The `<Currency>` component renders a formatted currency string, allowing customization of name, default value, currency type, and formatting options.
|
|
416
|
-
* Must be used inside a `<GTProvider>`.
|
|
417
|
-
*
|
|
418
|
-
* @example
|
|
419
|
-
* ```jsx
|
|
420
|
-
* <Currency currency="USD">
|
|
421
|
-
* 1000
|
|
422
|
-
* </Currency>
|
|
423
|
-
* ```
|
|
424
|
-
*
|
|
425
|
-
* @param {number | string | null | undefined} children - Content to render inside the currency component.
|
|
426
|
-
* @param {string} [currency="USD"] - The currency type (e.g., USD, EUR, etc.).
|
|
427
|
-
* @param {string[]} [locales] - Optional locales to use for currency formatting. If wrapped in a `<GTProvider>`, the user's locale is used.
|
|
428
|
-
* @param {Intl.NumberFormatOptions} [options={}] - Optional formatting options to customize how the currency is displayed.
|
|
429
|
-
* @returns {JSX.Element} The formatted currency component.
|
|
430
|
-
*/
|
|
431
|
-
declare function Currency({ children, currency, locales, options, }: {
|
|
432
|
-
children: number | string | null | undefined;
|
|
433
|
-
currency?: string;
|
|
434
|
-
name?: string;
|
|
435
|
-
locales?: string[];
|
|
436
|
-
options?: Intl.NumberFormatOptions;
|
|
437
|
-
}): React__default.JSX.Element | null;
|
|
438
|
-
declare namespace Currency {
|
|
439
|
-
var _gtt: string;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* The `<DateTime>` component renders a formatted date or time string, allowing customization of the name, default value, and formatting options.
|
|
444
|
-
* It utilizes the current locale and optional format settings to display the date.
|
|
445
|
-
* Must be used inside a `<GTProvider>`.
|
|
446
|
-
*
|
|
447
|
-
* @example
|
|
448
|
-
* ```jsx
|
|
449
|
-
* <DateTime>
|
|
450
|
-
* {new Date()}
|
|
451
|
-
* </DateTime>
|
|
452
|
-
* ```
|
|
453
|
-
*
|
|
454
|
-
* @param {Date} children - Content to render inside the date component.
|
|
455
|
-
* @param {string[]} [locales] - Optional locales to use for date formatting. If wrapped in a `<GTProvider>`, the user's locale is used.
|
|
456
|
-
* @param {Intl.DateTimeFormatOptions} [options={}] - Optional formatting options for the date, following `Intl.DateTimeFormatOptions` specifications.
|
|
457
|
-
* @returns {JSX.Element} The formatted date or time component.
|
|
458
|
-
*/
|
|
459
|
-
declare function DateTime({ children, locales, options, }: {
|
|
460
|
-
children: Date | null | undefined;
|
|
461
|
-
name?: string;
|
|
462
|
-
locales?: string[];
|
|
463
|
-
options?: Intl.DateTimeFormatOptions;
|
|
464
|
-
}): React__default.JSX.Element | null;
|
|
465
|
-
declare namespace DateTime {
|
|
466
|
-
var _gtt: string;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* The `<Num>` component renders a formatted number string, allowing customization of the name, default value, and formatting options.
|
|
471
|
-
* It formats the number according to the current locale and optionally passed formatting options.
|
|
472
|
-
* Must be used inside a `<GTProvider>`.
|
|
473
|
-
*
|
|
474
|
-
* @example
|
|
475
|
-
* ```jsx
|
|
476
|
-
* <Num
|
|
477
|
-
* options={{ style: "decimal", maximumFractionDigits: 2 }}
|
|
478
|
-
* >
|
|
479
|
-
* 1000
|
|
480
|
-
* </Num>
|
|
481
|
-
* ```
|
|
482
|
-
*
|
|
483
|
-
* @param {number | string | null | undefined} children - Content to render inside the number component.
|
|
484
|
-
* @param {string[]} [locales] - Optional locales to use for number formatting. If wrapped in a `<GTProvider>`, the user's locale is used.
|
|
485
|
-
* @param {Intl.NumberFormatOptions} [options={}] - Optional formatting options for the number, following `Intl.NumberFormatOptions` specifications.
|
|
486
|
-
* @returns {React.JSX.Element} The formatted number component.
|
|
487
|
-
*/
|
|
488
|
-
declare function Num({ children, locales, options, }: {
|
|
489
|
-
children: number | string | null | undefined;
|
|
490
|
-
name?: string;
|
|
491
|
-
locales?: string[];
|
|
492
|
-
options?: Intl.NumberFormatOptions;
|
|
493
|
-
}): React__default.JSX.Element | null;
|
|
494
|
-
declare namespace Num {
|
|
495
|
-
var _gtt: string;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* The `<Var>` component renders a variable value, which can either be passed as `children` or a `value`.
|
|
500
|
-
* If `children` is provided, it will be used; otherwise, the `value` is rendered.
|
|
501
|
-
*
|
|
502
|
-
* @example Inline usage:
|
|
503
|
-
* ```jsx
|
|
504
|
-
* function MyComponent() {
|
|
505
|
-
* const name = 'Archie';
|
|
506
|
-
* return (
|
|
507
|
-
* <T>
|
|
508
|
-
* <p>
|
|
509
|
-
* Hello, <Var> {name} </Var>!
|
|
510
|
-
* </p>
|
|
511
|
-
* </T>
|
|
512
|
-
* );
|
|
513
|
-
* }
|
|
514
|
-
* ```
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
* @param {any} [children] - The content to render inside the component. If provided, it will take precedence over `value`.
|
|
518
|
-
* @returns {JSX.Element} The rendered variable component with either `children` or `value`.
|
|
519
|
-
*/
|
|
520
|
-
declare function Var({ children, }: {
|
|
521
|
-
children?: any;
|
|
522
|
-
name?: string;
|
|
523
|
-
}): React__default.JSX.Element | null;
|
|
524
|
-
declare namespace Var {
|
|
525
|
-
var _gtt: string;
|
|
526
|
-
}
|
|
36
|
+
declare function ClientProvider({ children, dictionary: _dictionary, dictionaryTranslations: _dictionaryTranslations, translations: _translations, locale: _locale, region: _region, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, developmentApiEnabled, resetLocaleCookieName, localeCookieName, regionCookieName, customMapping, environment, }: ClientProviderProps): React.JSX.Element;
|
|
527
37
|
|
|
528
38
|
/**
|
|
529
39
|
* A dropdown component that allows users to select a locale.
|
|
@@ -578,247 +88,4 @@ declare function RegionSelector<Regions extends string[]>({ regions: _regions, p
|
|
|
578
88
|
[key: string]: any;
|
|
579
89
|
}): React__default.JSX.Element | null;
|
|
580
90
|
|
|
581
|
-
|
|
582
|
-
* Provides General Translation context to its children, which can then access `useGT`, `useLocale`, and `useDefaultLocale`.
|
|
583
|
-
*
|
|
584
|
-
* @param {React.ReactNode} children - The children components that will use the translation context.
|
|
585
|
-
* @param {string} [projectId] - The project ID required for General Translation cloud services.
|
|
586
|
-
* @param {Dictionary} [dictionary=defaultDictionary] - The translation dictionary for the project.
|
|
587
|
-
* @param {string[]} [locales] - The list of approved locales for the project.
|
|
588
|
-
* @param {string} [defaultLocale=libraryDefaultLocale] - The default locale to use if no other locale is found.
|
|
589
|
-
* @param {string} [locale] - The current locale, if already set.
|
|
590
|
-
* @param {string} [cacheUrl='https://cdn.gtx.dev'] - The URL of the cache service for fetching translations.
|
|
591
|
-
* @param {string} [runtimeUrl='https://runtime.gtx.dev'] - The URL of the runtime service for fetching translations.
|
|
592
|
-
* @param {RenderSettings} [renderSettings=defaultRenderSettings] - The settings for rendering translations.
|
|
593
|
-
* @param {string} [_versionId] - The version ID for fetching translations.
|
|
594
|
-
* @param {string} [devApiKey] - The API key for development environments.
|
|
595
|
-
* @param {object} [metadata] - Additional metadata to pass to the context.
|
|
596
|
-
* @param {boolean} [ssr=isSSREnabled()] - Whether to enable server-side rendering.
|
|
597
|
-
* @param {string} [localeCookieName=defaultLocaleCookieName] - The name of the cookie to store the locale.
|
|
598
|
-
* @param {Translations | null} [translations=null] - The translations to use for the context.
|
|
599
|
-
* @param {React.ReactNode} [fallback = undefined] - Custom fallback to display while loading
|
|
600
|
-
*
|
|
601
|
-
* @returns {JSX.Element} The provider component for General Translation context.
|
|
602
|
-
*/
|
|
603
|
-
declare function GTProvider({ children, config, projectId: _projectId, devApiKey: _devApiKey, dictionary: _dictionary, locales, defaultLocale, cacheUrl, runtimeUrl, renderSettings, ssr, localeCookieName, locale: _locale, region: _region, loadDictionary, loadTranslations, fallback, translations: _translations, _versionId, customMapping, ...metadata }: GTProviderProps): react_jsx_runtime.JSX.Element;
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* Sets the user's locale in the `<GTProvider>` context.
|
|
607
|
-
* If the locale passed is not supported, will fallback on current locale and then defaultLocale if necessary.
|
|
608
|
-
* @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.
|
|
609
|
-
*
|
|
610
|
-
* @returns {(locale: string) => void} A function that sets the user's locale.
|
|
611
|
-
*
|
|
612
|
-
* @example
|
|
613
|
-
* setLocale('en-US');
|
|
614
|
-
*/
|
|
615
|
-
declare function useSetLocale(): (locale: string) => void;
|
|
616
|
-
|
|
617
|
-
/**
|
|
618
|
-
* Retrieves the user's list of supported locales from the `<GTProvider>` context.
|
|
619
|
-
*
|
|
620
|
-
* @returns {string[]} The user's locales, e.g., ['en-US', 'fr', 'jp'].
|
|
621
|
-
*
|
|
622
|
-
* @example
|
|
623
|
-
* const locales = useLocales();
|
|
624
|
-
* console.log(locale); // ['en-US', 'fr', 'jp]
|
|
625
|
-
*/
|
|
626
|
-
declare function useLocales(): string[];
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
*
|
|
630
|
-
* Gets the list of properties for using a locale selector.
|
|
631
|
-
* Provides locale management utilities for the application.
|
|
632
|
-
* @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.
|
|
633
|
-
* Provides locale management utilities for the application.
|
|
634
|
-
*
|
|
635
|
-
* @returns {Object} An object containing locale-related utilities:
|
|
636
|
-
* @returns {string} return.locale - The currently selected locale.
|
|
637
|
-
* @returns {string[]} return.locales - The list of all available locales.
|
|
638
|
-
* @returns {(locale: string) => void} return.setLocale - Function to update the current locale.
|
|
639
|
-
* @returns {(locale: string) => LocaleProperties} return.getLocaleProperties - Function to retrieve properties for a given locale.
|
|
640
|
-
*/
|
|
641
|
-
declare function useLocaleSelector(locales?: string[]): {
|
|
642
|
-
locale: string;
|
|
643
|
-
locales: string[];
|
|
644
|
-
setLocale: (locale: string) => void;
|
|
645
|
-
getLocaleProperties: (locale: string) => {
|
|
646
|
-
code: string;
|
|
647
|
-
name: string;
|
|
648
|
-
nativeName: string;
|
|
649
|
-
languageCode: string;
|
|
650
|
-
languageName: string;
|
|
651
|
-
nativeLanguageName: string;
|
|
652
|
-
nameWithRegionCode: string;
|
|
653
|
-
nativeNameWithRegionCode: string;
|
|
654
|
-
regionCode: string;
|
|
655
|
-
regionName: string;
|
|
656
|
-
nativeRegionName: string;
|
|
657
|
-
scriptCode: string;
|
|
658
|
-
scriptName: string;
|
|
659
|
-
nativeScriptName: string;
|
|
660
|
-
maximizedCode: string;
|
|
661
|
-
maximizedName: string;
|
|
662
|
-
nativeMaximizedName: string;
|
|
663
|
-
minimizedCode: string;
|
|
664
|
-
minimizedName: string;
|
|
665
|
-
nativeMinimizedName: string;
|
|
666
|
-
emoji: string;
|
|
667
|
-
};
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* Returns the configured GT class instance.
|
|
672
|
-
*
|
|
673
|
-
* @returns {GT} The configured GT class instance.
|
|
674
|
-
*
|
|
675
|
-
* @example
|
|
676
|
-
* const gt = useGTClass();
|
|
677
|
-
* console.log(gt.getLocaleProperties('en-US'));
|
|
678
|
-
*/
|
|
679
|
-
declare function useGTClass(): generaltranslation.GT;
|
|
680
|
-
/**
|
|
681
|
-
* Returns the locale properties for the given locale.
|
|
682
|
-
*
|
|
683
|
-
* @param {string} locale - The locale to get the properties for.
|
|
684
|
-
* @returns {LocaleProperties} The locale properties for the given locale.
|
|
685
|
-
*
|
|
686
|
-
* @example
|
|
687
|
-
* const localeProperties = useLocaleProperties('en-US');
|
|
688
|
-
* console.log(localeProperties);
|
|
689
|
-
*/
|
|
690
|
-
declare function useLocaleProperties(locale: string): LocaleProperties;
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* A React hook that retrieves the user's currently selected region from the `<GTProvider>` context.
|
|
694
|
-
*
|
|
695
|
-
* Returns the `region` value as a string (e.g., `"US"`, `"CA"`) or `undefined` if no region has been set.
|
|
696
|
-
*
|
|
697
|
-
* @returns {string | undefined} The currently active region code, or `undefined` if not set.
|
|
698
|
-
*
|
|
699
|
-
* @example
|
|
700
|
-
* ```tsx
|
|
701
|
-
* const region = useRegion();
|
|
702
|
-
*
|
|
703
|
-
* if (!region) {
|
|
704
|
-
* console.log("No region set yet");
|
|
705
|
-
* } else {
|
|
706
|
-
* console.log(`Current region: ${region}`);
|
|
707
|
-
* }
|
|
708
|
-
* ```
|
|
709
|
-
*/
|
|
710
|
-
declare function useRegion(): string | undefined;
|
|
711
|
-
|
|
712
|
-
type RegionData = {
|
|
713
|
-
code: string;
|
|
714
|
-
name: string;
|
|
715
|
-
emoji: string;
|
|
716
|
-
locale: string;
|
|
717
|
-
};
|
|
718
|
-
/**
|
|
719
|
-
* React hook for managing region selection logic in applications supporting multiple regions.
|
|
720
|
-
*
|
|
721
|
-
* This hook provides the necessary data and handlers to implement a region selector UI component.
|
|
722
|
-
* It returns the current region, a list of available regions, region metadata, and functions to update the region or associated locale.
|
|
723
|
-
*
|
|
724
|
-
* ### Parameters
|
|
725
|
-
* @param {Object} [options] - Optional configuration object.
|
|
726
|
-
* @param {string[]} [options.regions] - An optional array of ISO 3166 region codes to display. If not provided, regions are inferred from supported locales.
|
|
727
|
-
* @param {Object.<string, string|{name?: string, emoji?: string, locale?: string}>} [options.customMapping] - Optional mapping to override region display names, emojis, or associated locales.
|
|
728
|
-
* @param {boolean} [options.prioritizeCurrentLocaleRegion=true] - If true, the region corresponding to the current locale is prioritized in the list.
|
|
729
|
-
* @param {boolean} [options.sortRegionsAlphabetically=true] - If true, regions are sorted alphabetically by display name.
|
|
730
|
-
*
|
|
731
|
-
* ### Returns
|
|
732
|
-
* @returns {{
|
|
733
|
-
* region: string | undefined,
|
|
734
|
-
* setRegion: (region: string) => void,
|
|
735
|
-
* regions: string[],
|
|
736
|
-
* regionData: Map<string, { code: string, name: string, emoji: string, locale: string }>,
|
|
737
|
-
* locale: string,
|
|
738
|
-
* setLocale: (locale: string) => void
|
|
739
|
-
* }} An object containing:
|
|
740
|
-
* - `region`: The currently selected region code.
|
|
741
|
-
* - `setRegion`: Function to update the selected region.
|
|
742
|
-
* - `regions`: Array of available region codes.
|
|
743
|
-
* - `regionData`: Map of region codes to their display data (name, emoji, locale).
|
|
744
|
-
* - `locale`: The current locale.
|
|
745
|
-
* - `setLocale`: Function to update the locale.
|
|
746
|
-
*
|
|
747
|
-
* ### Example
|
|
748
|
-
* ```tsx
|
|
749
|
-
* const {
|
|
750
|
-
* region,
|
|
751
|
-
* setRegion,
|
|
752
|
-
* regions,
|
|
753
|
-
* regionData,
|
|
754
|
-
* locale,
|
|
755
|
-
* setLocale
|
|
756
|
-
* } = useRegionSelector({
|
|
757
|
-
* customMapping: { US: { name: "United States", emoji: "πΊπΈ" } }
|
|
758
|
-
* });
|
|
759
|
-
*
|
|
760
|
-
* return (
|
|
761
|
-
* <select value={region} onChange={e => setRegion(e.target.value)}>
|
|
762
|
-
* {regions.map(r => (
|
|
763
|
-
* <option key={r} value={r}>
|
|
764
|
-
* {regionData.get(r)?.name}
|
|
765
|
-
* </option>
|
|
766
|
-
* ))}
|
|
767
|
-
* </select>
|
|
768
|
-
* );
|
|
769
|
-
* ```
|
|
770
|
-
*/
|
|
771
|
-
declare function useRegionSelector({ regions: _regions, customMapping, prioritizeCurrentLocaleRegion, sortRegionsAlphabetically, }?: {
|
|
772
|
-
regions?: string[];
|
|
773
|
-
customMapping?: {
|
|
774
|
-
[region: string]: string | {
|
|
775
|
-
name?: string;
|
|
776
|
-
emoji?: string;
|
|
777
|
-
locale?: string;
|
|
778
|
-
};
|
|
779
|
-
};
|
|
780
|
-
prioritizeCurrentLocaleRegion?: boolean;
|
|
781
|
-
sortRegionsAlphabetically?: boolean;
|
|
782
|
-
}): {
|
|
783
|
-
region: string | undefined;
|
|
784
|
-
setRegion: (region: string | undefined) => void;
|
|
785
|
-
regions: string[];
|
|
786
|
-
regionData: Map<string, RegionData>;
|
|
787
|
-
locales: string[];
|
|
788
|
-
locale: string;
|
|
789
|
-
localeRegion: string;
|
|
790
|
-
setLocale: (locale: string) => void;
|
|
791
|
-
};
|
|
792
|
-
|
|
793
|
-
/**
|
|
794
|
-
* Retrieves the text direction ('ltr' or 'rtl') for the current or specified locale from the `<GTProvider>` context.
|
|
795
|
-
*
|
|
796
|
-
* If no locale is provided, the direction for the current user's locale is returned.
|
|
797
|
-
*
|
|
798
|
-
* @param {string} [locale] - Optional locale code (e.g., 'ar', 'en-US'). If omitted, uses the current locale from context.
|
|
799
|
-
* @returns {'ltr' | 'rtl'} The text direction for the locale: 'rtl' for right-to-left languages, otherwise 'ltr'.
|
|
800
|
-
*
|
|
801
|
-
* @example
|
|
802
|
-
* const dir = useLocaleDirection(); // e.g., 'ltr'
|
|
803
|
-
* const arabicDir = useLocaleDirection('ar'); // 'rtl'
|
|
804
|
-
*/
|
|
805
|
-
declare function useLocaleDirection(locale?: string): 'ltr' | 'rtl';
|
|
806
|
-
|
|
807
|
-
/**
|
|
808
|
-
* Gets the message decoding and translation function `m` provided by `<GTProvider>`.
|
|
809
|
-
*
|
|
810
|
-
* @returns {Function} A translation function that accepts an encoded message, decodes it, and returns the translated value.
|
|
811
|
-
*
|
|
812
|
-
* @example
|
|
813
|
-
* const encodedMessage = msg("Hello, world")
|
|
814
|
-
* const m = useMessages();
|
|
815
|
-
* m(encodedMessage) // returns "Hello, world" translated
|
|
816
|
-
*
|
|
817
|
-
* @example
|
|
818
|
-
* const encodedMessage = msg("My name is {name}", { name: "Brian" });
|
|
819
|
-
* const m = useMessages();
|
|
820
|
-
* m(encodedMessage) // returns "My name is Brian" translated
|
|
821
|
-
*/
|
|
822
|
-
declare function useMessages(_messages?: _Messages): MFunctionType;
|
|
823
|
-
|
|
824
|
-
export { Branch, ClientProvider, Currency, DateTime, GTContext, GTProvider, LocaleSelector, Num, Plural, RegionSelector, T, Var, decodeMsg, decodeOptions, msg, renderVariable, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleDirection, useLocaleProperties, useLocaleSelector, useLocales, useMessages, useRegion, useRegionSelector, useRuntimeTranslation, useSetLocale, useTranslations };
|
|
91
|
+
export { ClientProvider, LocaleSelector, RegionSelector };
|