@fisharmy100/react-auto-i18n 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,637 @@
1
+ import React$1 from 'react';
2
+
3
+ /**
4
+ * The type of all language codes (i.e. the prefix of the {@link LangScriptCode})
5
+ */
6
+ type LangCode = LangScriptCode extends `${infer L}_${string}` ? L : never;
7
+ /**
8
+ * Gets the LangCode from the {@link LangScriptCode}. \
9
+ * **Example:**
10
+ * ```ts
11
+ * let langScript: LangScriptCode = "eng_Latn";
12
+ * console.log(getLangCode(langScript)); // prints out 'eng'
13
+ * ```
14
+ * @param code The {@link LangScriptCode}
15
+ * @returns the {@link LangCode} of the {@link LangScriptCode}
16
+ */
17
+ declare function getLangCode(code: LangScriptCode): LangCode;
18
+ /**
19
+ * Converts a raw string into a {@link LangCode}, with error checking
20
+ * @param str The string to be passed
21
+ * @returns A {@link LangCode} if the string is a valid {@link LangCode} or `null` if it is not
22
+ */
23
+ declare function stringToLangCode(str: string): LangCode | null;
24
+ /**
25
+ * Gets the english name of a {@link LangCode}
26
+ * @param code A {@link LangCode}
27
+ * @returns The english name of the passed {@link LangCode}
28
+ */
29
+ declare function getEnglishLangName(code: LangCode): string | null;
30
+ /**
31
+ * Gets the local name of a {@link LangCode}
32
+ * @param code A {@link LangCode}
33
+ * @returns The local name of the passed {@link LangCode}
34
+ */
35
+ declare function getLocaleLangName(code: LangCode): string | null;
36
+
37
+ /**
38
+ * The type of all script codes (i.e. the suffix of the {@link LangScriptCode})
39
+ */
40
+ type ScriptCode = LangScriptCode extends `${string}_${infer S}` ? S : never;
41
+ /**
42
+ * The direction that a given script is read, and should be rendered
43
+ * - `ltr`: Left-to-Right
44
+ * - `rtl`: Right-to-Left
45
+ */
46
+ type ScriptDirection = "ltr" | "rtl";
47
+ /**
48
+ * Gets the Script from the LangScriptCode. \
49
+ * **Example:**
50
+ * ```ts
51
+ * let langScript: LangScriptCode = "eng_Latn";
52
+ * console.log(getScriptCode(langScript)); // prints out 'Latn'
53
+ * ```
54
+ * @param code The {@link LangScriptCode}
55
+ * @returns the `Script` of the {@link LangScriptCode}
56
+ */
57
+ declare function getScriptCode(code: LangScriptCode): ScriptCode;
58
+ /**
59
+ * Converts a raw string into a {@link LangScriptCode}, with error checking
60
+ * @param str The string to be passed
61
+ * @returns A {@link LangScriptCode} if the string is a valid {@link LangScriptCode} or `null` if it is not
62
+ */
63
+ declare function stringToLangScriptCode(str: string): LangScriptCode | null;
64
+ /**
65
+ * Converts a raw string into a {@link ScriptCode}, with error checking
66
+ * @param str The string to be passed
67
+ * @returns A {@link ScriptCode} if the string is a valid {@link ScriptCode} or `null` if it is not
68
+ */
69
+ declare function stringToScriptCode(str: string): ScriptCode | null;
70
+ /**
71
+ * Gets the {@link ScriptDirection} from a {@link ScriptCode}
72
+ * @param script a {@link ScriptCode}
73
+ * @returns the {@link ScriptDirection} from the {@link ScriptCode}
74
+ */
75
+ declare function getScriptDirection(script: ScriptCode): ScriptDirection;
76
+ /**
77
+ * Gets the {@link ScriptDirection} from the {@link ScriptCode} of a {@link LangScriptCode}
78
+ * @param script a {@link LangScriptCode}
79
+ * @returns the {@link ScriptDirection} from the {@link ScriptCode} of a {@link LangScriptCode}
80
+ */
81
+ declare function getLangScriptDirection(langScript: LangScriptCode): ScriptDirection;
82
+
83
+ /**
84
+ * A country code
85
+ */
86
+ type CountryCode = 'AE' | 'AF' | 'AL' | 'AM' | 'AO' | 'AR' | 'AT' | 'AW' | 'AU' | 'AZ' | 'BA' | 'BD' | 'BE' | 'BF' | 'BG' | 'BI' | 'BJ' | 'BN' | 'BO' | 'BR' | 'BT' | 'BW' | 'BY' | 'CA' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CL' | 'CN' | 'CM' | 'CO' | 'CR' | 'CV' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DZ' | 'EC' | 'EE' | 'EG' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FO' | 'FR' | 'GB' | 'GE' | 'GH' | 'GM' | 'GN' | 'GQ' | 'GR' | 'GT' | 'GW' | 'HK' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IN' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KR' | 'KZ' | 'LA' | 'LB' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'MA' | 'MD' | 'MG' | 'MK' | 'ML' | 'MM' | 'MN' | 'MR' | 'MT' | 'MU' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NE' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PG' | 'PH' | 'PK' | 'PL' | 'PT' | 'PY' | 'QA' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SI' | 'SK' | 'SL' | 'SN' | 'SO' | 'SR' | 'SS' | 'SY' | 'SZ' | 'TD' | 'TG' | 'TH' | 'TJ' | 'TL' | 'TM' | 'TN' | 'TR' | 'TW' | 'TZ' | 'UA' | 'UG' | 'US' | 'UY' | 'UZ' | 'VE' | 'VN' | 'WS' | 'YE' | 'ZA' | 'ZM' | 'ZW';
87
+ /**
88
+ * Gets the {@link CountryCode} for the given {@link LangCode}. Essentially, what country most primarily speaks this language.
89
+ * For example, this will return `US` even though Britain, Australia, etc. also speak the language.
90
+ * @param code The {@link LangCode}
91
+ * @returns A {@link CountryCode} which represents the country ***most commonly*** associated with that language. It will return null if there is no country typically associated with this language.
92
+ */
93
+ declare function getCountryCode(code: LangCode): CountryCode | null;
94
+
95
+ /**
96
+ * A helper wrapper object for the {@link LangScriptCode}, providing basic functions in an OOP style.
97
+ */
98
+ declare class LangScriptObj {
99
+ /**
100
+ * The inner wrapped {@link LangScriptCode}
101
+ */
102
+ readonly code: LangScriptCode;
103
+ constructor(code: LangScriptCode);
104
+ /**
105
+ * A helper function for getting the {@link LangCode} for the wrapped {@link LangScriptCode}
106
+ * @returns The {@link LangCode} for the wrapped {@link LangScriptCode}
107
+ */
108
+ getLangCode(): LangCode;
109
+ /**
110
+ * A helper function for getting the {@link ScriptCode} for the wrapped {@link LangScriptCode}
111
+ * @returns The {@link ScriptCode} for the wrapped {@link LangScriptCode}
112
+ */
113
+ getScriptCode(): ScriptCode;
114
+ /**
115
+ * A helper function for getting the locale name for the wrapped {@link LangScriptCode}
116
+ * @returns The {@link LangCode} for the wrapped {@link LangScriptCode}
117
+ */
118
+ getName(): string | null;
119
+ /**
120
+ * A helper function for getting the english name for the wrapped {@link LangScriptCode}
121
+ * @returns The {@link LangCode} for the wrapped {@link LangScriptCode}
122
+ */
123
+ getEnglishName(): string | null;
124
+ /**
125
+ * A helper function for getting the {@link CountryCode} most associated with this {@link LangScriptCode}, or `null` if there is none
126
+ * @returns the {@link CountryCode} most associated with this `LangScriptCode, or `null` if there is none
127
+ */
128
+ getCountry(): CountryCode | null;
129
+ /**
130
+ * A helper function that invokes the {@link CountryFlag} component, with the country code most associated with this {@link LangScriptCode}, or null if there is none
131
+ * @returns the {@link CountryFlag} component, with the country code most associated with this {@link LangScriptCode}, or null if there is none
132
+ */
133
+ getCountryFlag(): React.ReactElement | null;
134
+ /**
135
+ * A helper function for getting the {@link ScriptDirection} for wrapped {@link LangScriptCode}
136
+ * @returns the {@link ScriptDirection} for wrapped {@link LangScriptCode}
137
+ */
138
+ getScriptDirection(): ScriptDirection;
139
+ }
140
+
141
+ /**
142
+ * Essentially represents all translations loaded for this application. It can be represented in JSON as:
143
+ * ```json
144
+ * {
145
+ * "eng_Latn": {
146
+ * "main.first": "...",
147
+ * "main.second": "...",
148
+ * ...
149
+ * },
150
+ * "fra_Latn": {
151
+ * "main.first": "...",
152
+ * "main.second": "...",
153
+ * ...
154
+ * },
155
+ * "spa_Latn": {
156
+ * "main.first": "...",
157
+ * "main.second": "...",
158
+ * ...
159
+ * },
160
+ * ...
161
+ * }
162
+ * ```
163
+ */
164
+ type I18nDatabaseType = Partial<Readonly<Record<LangScriptCode, LanguageTranslations>>>;
165
+ /**
166
+ * A map that contains translations for all keys for a given language.
167
+ */
168
+ type LanguageTranslations = Partial<Readonly<Record<string, string | string[]>>>;
169
+ /**
170
+ * The interface for a translation database
171
+ */
172
+ interface I18nDatabase {
173
+ /**
174
+ * Gets the translation for a given language and key
175
+ * @param lang A {@link LangScriptCode}
176
+ * @param key A key for the given translation in the specified language
177
+ * @returns Either a single translation (for {@link __t}), multiple translations (for {@link __tv}), or `undefined` if there is no translations
178
+ */
179
+ get(lang: LangScriptCode, key: string): string[] | string | undefined;
180
+ /**
181
+ * @returns All the {@link LangScriptCode}'s that the database contains
182
+ */
183
+ langs(): LangScriptCode[];
184
+ /**
185
+ * Allows the user to add a listener to see if the internal state of the database has changed. This can be used for things like caching
186
+ * @param listener
187
+ */
188
+ addOnChangeListener(listener: () => void): void;
189
+ /**
190
+ * Allows the user to remove a listener that would fire if the internal state of the database has changed. This can be used for things like caching
191
+ * @param listener
192
+ */
193
+ removeOnChangeListener(listener: () => void): boolean;
194
+ }
195
+ /**
196
+ * A basic wrapper around the {@link I18nDatabaseType} which implements {@link I18nDatabase}. It also gives some helper functions for loading it from a file.
197
+ */
198
+ declare class SimpleI18nDb implements I18nDatabase {
199
+ private readonly db;
200
+ constructor(db: I18nDatabaseType);
201
+ addOnChangeListener(): void;
202
+ removeOnChangeListener(): boolean;
203
+ /**
204
+ * Creates a {@link SimpleI18nDb} from a file. The file the path points to must be in the format of {@link I18nDatabaseType}
205
+ * @param path The path of the database file.
206
+ * @returns
207
+ */
208
+ static load(path: string): Promise<SimpleI18nDb>;
209
+ get(lang: LangScriptCode, key: string): string[] | string | undefined;
210
+ langs(): LangScriptCode[];
211
+ }
212
+ declare const FOLDER_LANGUAGE_MANIFEST_NAME: string;
213
+ type FolderLanguageManifestType = {
214
+ langs: LangScriptCode[];
215
+ };
216
+ /**
217
+ * A cached database, which will only load languages if necessary.
218
+ */
219
+ declare class CachedMultiFileI18nDb implements I18nDatabase {
220
+ private readonly supportedLangs;
221
+ private readonly db;
222
+ private readonly path;
223
+ private onChangedListeners;
224
+ /**
225
+ * @param path The folder path which contains all multiple files of type {@link LanguageTranslations} and each must be named using {@link LangScriptCode} followed by a `.json`
226
+ * @param langs Represents all of the languages that the translation folder contains. Essentially, if the folder has a file for a given language, add that language here.
227
+ */
228
+ constructor(path: string, langs: LangScriptCode[]);
229
+ /**
230
+ * Creates a {@link CachedMultiFileI18nDb} from a folder path.
231
+ * The folder path which contains all multiple files of type {@link LanguageTranslations}, and each must be named using {@link LangScriptCode} followed by a `.json`.
232
+ * It needs to point to a folder inside of the `public` folder, and the folder must contain a `manifest.json` file of the format {@link FolderLanguageManifestType}
233
+ */
234
+ static load(folder: string): Promise<CachedMultiFileI18nDb>;
235
+ get(lang: LangScriptCode, key: string): string[] | string | undefined;
236
+ langs(): LangScriptCode[];
237
+ addOnChangeListener(listener: () => void): void;
238
+ removeOnChangeListener(listener: () => void): boolean;
239
+ private invokeOnChangeListeners;
240
+ }
241
+ /**
242
+ * The default (empty) {@link I18nDatabase}.
243
+ */
244
+ declare const I18nDatabaseDefault: I18nDatabase;
245
+
246
+ /**
247
+ * A list of all LangScriptCodes supported by the translation engine
248
+ */
249
+ declare const LANG_SCRIPT_CODES: readonly ["ace_Arab", "ace_Latn", "acm_Arab", "acq_Arab", "aeb_Arab", "afr_Latn", "als_Latn", "amh_Ethi", "apc_Arab", "arb_Arab", "arb_Latn", "arg_Latn", "ars_Arab", "ary_Arab", "arz_Arab", "asm_Beng", "ast_Latn", "awa_Deva", "ayr_Latn", "azb_Arab", "azj_Latn", "bak_Cyrl", "bam_Latn", "ban_Latn", "bel_Cyrl", "bem_Latn", "ben_Beng", "bho_Deva", "bjn_Arab", "bjn_Latn", "bod_Tibt", "bos_Latn", "brx_Deva", "bug_Latn", "bul_Cyrl", "cat_Latn", "ceb_Latn", "ces_Latn", "chv_Cyrl", "cjk_Latn", "ckb_Arab", "cmn_Hans", "cmn_Hant", "crh_Latn", "cym_Latn", "dan_Latn", "dar_Cyrl", "deu_Latn", "dgo_Deva", "dik_Latn", "dyu_Latn", "dzo_Tibt", "ekk_Latn", "ell_Grek", "eng_Latn", "epo_Latn", "eus_Latn", "ewe_Latn", "fao_Latn", "fij_Latn", "fil_Latn", "fin_Latn", "fon_Latn", "fra_Latn", "fur_Latn", "fuv_Latn", "gaz_Latn", "gla_Latn", "gle_Latn", "glg_Latn", "gom_Deva", "gug_Latn", "guj_Gujr", "hat_Latn", "hau_Latn", "heb_Hebr", "hin_Deva", "hne_Deva", "hrv_Latn", "hun_Latn", "hye_Armn", "ibo_Latn", "ilo_Latn", "ind_Latn", "isl_Latn", "ita_Latn", "jav_Latn", "jpn_Jpan", "kaa_Latn", "kab_Latn", "kac_Latn", "kam_Latn", "kan_Knda", "kas_Arab", "kas_Deva", "kat_Geor", "kaz_Cyrl", "kbp_Latn", "kea_Latn", "khk_Cyrl", "khm_Khmr", "kik_Latn", "kin_Latn", "kir_Cyrl", "kmb_Latn", "kmr_Latn", "knc_Arab", "knc_Latn", "kor_Hang", "ktu_Latn", "lao_Laoo", "lij_Latn", "lim_Latn", "lin_Latn", "lit_Latn", "lld_Latn", "lmo_Latn", "ltg_Latn", "ltz_Latn", "lua_Latn", "lug_Latn", "luo_Latn", "lus_Latn", "lvs_Latn", "mag_Deva", "mai_Deva", "mal_Mlym", "mar_Deva", "mfe_Latn", "mhr_Cyrl", "min_Arab", "min_Latn", "mkd_Cyrl", "mlt_Latn", "mni_Beng", "mni_Mtei", "mos_Latn", "mri_Latn", "mya_Mymr", "myv_Cyrl", "nld_Latn", "nno_Latn", "nob_Latn", "npi_Deva", "nqo_Nkoo", "nso_Latn", "nus_Latn", "nya_Latn", "oci_Latn", "ory_Orya", "pag_Latn", "pan_Guru", "pap_Latn", "pbt_Arab", "pes_Arab", "plt_Latn", "pol_Latn", "por_Latn", "prs_Arab", "quy_Latn", "ron_Latn", "run_Latn", "rus_Cyrl", "sag_Latn", "san_Deva", "sat_Olck", "scn_Latn", "shn_Mymr", "sin_Sinh", "slk_Latn", "slv_Latn", "smo_Latn", "sna_Latn", "snd_Arab", "snd_Deva", "som_Latn", "sot_Latn", "spa_Latn", "srd_Latn", "srp_Cyrl", "ssw_Latn", "sun_Latn", "swe_Latn", "swh_Latn", "szl_Latn", "tam_Taml", "taq_Latn", "taq_Tfng", "tat_Cyrl", "tel_Telu", "tgk_Cyrl", "tha_Thai", "tir_Ethi", "tpi_Latn", "tsn_Latn", "tso_Latn", "tuk_Latn", "tum_Latn", "tur_Latn", "twi_Latn", "tyv_Cyrl", "uig_Arab", "ukr_Cyrl", "umb_Latn", "urd_Arab", "uzn_Latn", "uzs_Arab", "vec_Latn", "vie_Latn", "vmw_Latn", "war_Latn", "wol_Latn", "wuu_Hans", "xho_Latn", "ydd_Hebr", "yor_Latn", "yue_Hant", "zgh_Tfng", "zsm_Latn", "zul_Latn"];
250
+ /**
251
+ * The type of all supported {@link LangScriptCode}'s
252
+ */
253
+ type LangScriptCode = typeof LANG_SCRIPT_CODES[number];
254
+ /**
255
+ * A list of all {@link LangCode}'s
256
+ */
257
+ declare const LANG_CODES: LangCode[];
258
+ /**
259
+ * A list of all {@link ScriptCode}'s
260
+ */
261
+ declare const SCRIPT_CODES: ScriptCode[];
262
+ /**
263
+ * A utility function for converting a {@link LangCode} and a {@link LangCode} into a {@link LangScriptCode}
264
+ * @param lang The {@link LangCode} for the {@link LangScriptCode}
265
+ * @param script The {@link LangCode} for the {@link LangScriptCode}
266
+ * @returns The formatted {@link LangScriptCode}
267
+ */
268
+ declare function formatLangScriptCode(lang: LangCode, script: ScriptCode): LangScriptCode;
269
+
270
+ /**
271
+ * The properties for {@link CountryFlag}
272
+ */
273
+ type CountryFlagProps = React$1.HtmlHTMLAttributes<HTMLSpanElement> & {
274
+ /**
275
+ * The {@link CountryCode} for {@link CountryFlag}
276
+ */
277
+ country: CountryCode;
278
+ };
279
+ /**
280
+ * Renders a country flag icon based on the provided country code.
281
+ * @param props - The component props
282
+ * @param props.country - The country code (e.g., 'US', 'FR', 'DE'), see all values in {@link CountryCode}
283
+ * @param props.className - Optional additional CSS class names to apply to the flag element
284
+ * @param props.rest - Additional HTML span element attributes
285
+ * @returns A React element displaying the country flag icon
286
+ */
287
+ declare function CountryFlag({ country, className, ...rest }: CountryFlagProps): React$1.ReactElement;
288
+
289
+ /**
290
+ * The properties for the {@link I18nFileProvider}
291
+ */
292
+ type I18nFileProviderProps = {
293
+ /**
294
+ * The file path to the json database. It needs to point to a file inside of the `public` folder and the json must be in the format of {@link I18nDatabaseType}.
295
+ */
296
+ path: string;
297
+ /**
298
+ * The children of this component
299
+ */
300
+ children: React$1.ReactNode;
301
+ /**
302
+ * The default language for the provider. Defaults to `"eng_Latn"`
303
+ */
304
+ defaultLang: LangScriptCode;
305
+ };
306
+ /**
307
+ * A wrapper around the {@link I18nProvider} and {@link SimpleI18nDb}, which loads in a static translation json database file from the `public` folder.
308
+ * @param props The {@link I18nFileProviderProps} for this provider.
309
+ *
310
+ * ### **Example**
311
+ * ```tsx
312
+ * import { StrictMode } from 'react'
313
+ * import { createRoot } from 'react-dom/client'
314
+ * import App from './App.tsx'
315
+ * import { I18nProvider, RawI18nDb } from "react-auto-i18n";
316
+ *
317
+ * createRoot(document.getElementById('root')!).render(
318
+ * <I18nFileProvider
319
+ * defaultLang="eng_Latn"
320
+ * path="./translations.json"
321
+ * >
322
+ * <App />
323
+ * </I18nFileProvider>
324
+ * )
325
+ * ```
326
+ */
327
+ declare function I18nFileProvider({ path, children, defaultLang, }: I18nFileProviderProps): React$1.ReactElement;
328
+
329
+ /**
330
+ * The context type for the {@link I18nProvider}
331
+ */
332
+ interface I18nContextType {
333
+ /**
334
+ * The currently set {@link LangScriptCode}
335
+ */
336
+ readonly locale: LangScriptCode;
337
+ /**
338
+ * Gets a wrapper {@link LangScriptObj} around this locale
339
+ * @returns a wrapper {@link LangScriptObj} around this locale
340
+ */
341
+ readonly getLocaleObj: () => LangScriptObj;
342
+ /**
343
+ * The currently set {@link I18nDatabase}
344
+ */
345
+ readonly database: I18nDatabase;
346
+ /**
347
+ * Sets the current {@link LangScriptCode}
348
+ * @param locale The current local to set
349
+ */
350
+ readonly setLocale: (locale: LangScriptCode) => void;
351
+ /**
352
+ * Sets the current {@link I18nDatabase}
353
+ * @param locale The current local to set
354
+ */
355
+ readonly setDatabase: (database: I18nDatabase) => void;
356
+ /**
357
+ * This is essentially a helper function for doing `.database.langs()`
358
+ * @returns Returns all the loaded {@link LangScriptCode}'s in the current I18nDatabase.
359
+ */
360
+ readonly getLocales: () => LangScriptCode[];
361
+ }
362
+ /**
363
+ * The properties for the {@link I18nProvider}
364
+ */
365
+ type I18nProviderProps = {
366
+ /**
367
+ * The providers children
368
+ */
369
+ children: React$1.ReactNode;
370
+ /**
371
+ * The default language code. When passed to the {@link I18nProvider}, defaults to `"eng_Latn"`
372
+ */
373
+ defaultLang: LangScriptCode;
374
+ /**
375
+ * The {@link I18nDatabase} for this provider
376
+ */
377
+ db: I18nDatabase;
378
+ };
379
+ /**
380
+ * The provider for the {@link I18nDatabase} and current local.
381
+ *
382
+ * Allows for getting and setting the global state used by {@link __t} in a more React like way.
383
+ *
384
+ * ### **Example:**
385
+ * ```tsx
386
+ * import { StrictMode } from 'react'
387
+ * import { createRoot } from 'react-dom/client'
388
+ * import App from './App.tsx'
389
+ * import { I18nProvider, RawI18nDb } from "react-auto-i18n";
390
+ * import translations from "./assets/translations.json";
391
+ *
392
+ * const db = new RawI18nDb(translations);
393
+ *
394
+ * createRoot(document.getElementById('root')!).render(
395
+ * <I18nProvider
396
+ * defaultLang="eng_Latn"
397
+ * db={db}
398
+ * >
399
+ * <App />
400
+ * </I18nProvider>
401
+ * )
402
+ * ```
403
+ *
404
+ * @param props The {@link I18nProviderProps} for this provider
405
+ */
406
+ declare function I18nProvider({ children, defaultLang, db: dbInit, }: I18nProviderProps): React$1.ReactElement;
407
+ /**
408
+ * Allows for the modification and usage of the global database and locale states. Must be used on the context of a {@link I18nProvider}.
409
+ *
410
+ * ### **Example:**
411
+ * ```ts
412
+ * const i18n = useI18n();
413
+ * i18n.setLocale("spa_Latn");
414
+ *
415
+ * let msg = __t("message", "Hello!");
416
+ * console.log(msg); // Hola!
417
+ * ```
418
+ * @returns The instance of the current {@link I18nProvider}
419
+ */
420
+ declare function useI18n(): I18nContextType;
421
+
422
+ /**
423
+ * The properties for the {@link I18nMultiFileProvider}
424
+ */
425
+ type I18nMultiFileProviderProps = {
426
+ /**
427
+ * The folder path which contains all multiple files of type {@link LanguageTranslations}, and each must be named using {@link LangScriptCode} followed by a `.json`.
428
+ * It needs to point to a folder inside of the `public` folder, and the folder must contain a `manifest.json` file of the format {@link FolderLanguageManifestType}
429
+ */
430
+ path: string;
431
+ /**
432
+ * The children of this component
433
+ */
434
+ children: React$1.ReactNode;
435
+ /**
436
+ * The default language for the provider. Defaults to `"eng_Latn"`
437
+ */
438
+ defaultLang: LangScriptCode;
439
+ };
440
+ /**
441
+ * A wrapper around the {@link I18nProvider} and {@link CachedMultiFileI18nDb}, which loads in a static translation json database folder from the `public` folder.
442
+ * @param props The {@link I18nMultiFileProviderProps} for this provider.
443
+ *
444
+ * ### **Example**
445
+ * ```tsx
446
+ * import { StrictMode } from 'react'
447
+ * import { createRoot } from 'react-dom/client'
448
+ * import App from './App.tsx'
449
+ * import { I18nProvider, RawI18nDb } from "react-auto-i18n";
450
+ *
451
+ * createRoot(document.getElementById('root')!).render(
452
+ * <I18nMultiFileProvider
453
+ * defaultLang="eng_Latn"
454
+ * path="./translations"
455
+ * >
456
+ * <App />
457
+ * </I18nMultiFileProvider>
458
+ * )
459
+ * ```
460
+ *
461
+ */
462
+ declare function I18nMultiFileProvider({ path, children, defaultLang, }: I18nMultiFileProviderProps): React$1.ReactElement;
463
+
464
+ /**
465
+ * Sets the raw database used for translation. This is used by the {@link __t} and {@link __tv} functions. \
466
+ * **NOTE:** Prefer to use `useI18n().setDatabase(...)`, as this updates the current state.
467
+ * @param db
468
+ */
469
+ declare function setI18nDatabaseRaw(db: I18nDatabase): void;
470
+ /**
471
+ * Gets the raw database used for translation, which used by the {@link __t} and {@link __tv} functions. \
472
+ * **NOTE:** Prefer to use `useI18n().database` hook
473
+ * @returns the raw `I18nDatabase` database
474
+ */
475
+ declare function getI18nDatabaseRaw(): I18nDatabase;
476
+ /**
477
+ * Sets the raw locale used for translation. This is used by the {@link __t} and {@link __tv} functions. \
478
+ * **NOTE:** Prefer to use `useI18n().setLocale(...)`, as this updates the current state.
479
+ * @param locale
480
+ */
481
+ declare function setCurrentLocalRaw(locale: LangScriptCode): void;
482
+ /**
483
+ * Gets the raw current locale used for translation, which used by the {@link __t} and {@link __tv} functions. \
484
+ * **NOTE:** Prefer to use `useI18n().locale` hook
485
+ * @returns The current raw `LangScriptCode` locale
486
+ */
487
+ declare function getCurrentLocalRaw(): LangScriptCode;
488
+ /**
489
+ * The primary translation function for this API.
490
+ * When using {@link https://github.com/FishArmy100/react-auto-i18n/tree/main/packages/auto-i18n-cli auto-i18n-cli} to parse the program and generate the database automatically, both arguments must be raw string literals.
491
+ * The {@link https://github.com/FishArmy100/react-auto-i18n/tree/main/packages/auto-i18n-cli auto-i18n-cli} looks for all invocations of this function and generates a `I18nDatabase` compatible json file, with the proper translations.
492
+ *
493
+ * ### **Translation (using auto-i18n-cli):**
494
+ * ```ts
495
+ * // file.ts
496
+ * let msg = __t("message", "Hello!");
497
+ * ```
498
+ * Translation command:
499
+ * `npx auto-i18n-cli -i "./file.ts" -o "./translations.json" -l spa_Latn -s eng_Latn -b azure --azureKey "..."`
500
+ *
501
+ * Outputs:
502
+ * ```json
503
+ * {
504
+ * "eng_Latn": {
505
+ * "message": "Hello!"
506
+ * },
507
+ * "spa_Latn": {
508
+ * "message": "Hola!"
509
+ * }
510
+ * }
511
+ * ```
512
+ *
513
+ * ### **Usage**
514
+ * ```ts
515
+ * import db from "./translations.json";
516
+ * setI18nDatabaseRaw(db);
517
+ * setCurrentLocalRaw("spa_Latn");
518
+ * let msg = __t("message", "Hello!");
519
+ *
520
+ * console.log(msg); // Hola!
521
+ * ```
522
+ *
523
+ * ### **Escape Code**
524
+ * You can use double curly braces `{{...}}` to stop the translation engine from translating any text inside. The curly braces are removed after translation.
525
+ * If a `$` is placed before the text inside of the escape code, it is treated as a variable which values can be passed,
526
+ * and incorporated into the text.
527
+ *
528
+ * **NOTE:** the passed arguments are **NOT** translated
529
+ * ```ts
530
+ * import db from "./translations.json";
531
+ * setI18nDatabaseRaw(db);
532
+ * setCurrentLocalRaw("spa_Latn");
533
+ *
534
+ * let msg = __t("message", "Hello there! this is a test message for the {{'react-auto-i18n'}} program.");
535
+ *
536
+ * assert(msg === "Hola, este es un mensaje de prueba para el programa 'react-auto-i18n'.")
537
+ * ```
538
+ *
539
+ * @param key The key for the translation
540
+ * @param message The message to be translated
541
+ * @param arg A object that is passed as the argument to the selection functions and used for variable substitution
542
+ * @returns The translation of the message for the currently set locale.
543
+ */
544
+ declare function __t<T extends {
545
+ [k: string]: any | undefined;
546
+ }>(key: string, message: string, arg?: T): string;
547
+ type TVArgs<T> = [...[string, (t: T) => boolean][], string];
548
+ /**
549
+ * The secondary translation function for this API.
550
+ * When using {@link https://github.com/FishArmy100/react-auto-i18n/tree/main/packages/auto-i18n-cli auto-i18n-cli} to parse the program and generate the database automatically, `key` must be a string literal and `messages`
551
+ * must be an array literal, with the last argument being a string literal and all previous elements being an array literal with
552
+ * a string literal as the first element.
553
+ *
554
+ * The {@link https://github.com/FishArmy100/react-auto-i18n/tree/main/packages/auto-i18n-cli auto-i18n-cli} looks for all invocations of this function and generates a `I18nDatabase` compatible json file, with the proper translations.
555
+ *
556
+ * ### **Translation (using auto-i18n-cli):**
557
+ * ```ts
558
+ * // file.ts
559
+ * const msg = __tv("test.message.v", [
560
+ * ["You have one apple", ({count}) => count == 1],
561
+ * ["You have {{$count}} apples", ({count}) => count > 1],
562
+ * "You have no apples"
563
+ * ], { count: appleCount })
564
+ * ```
565
+ * Translation command:
566
+ * `npx auto-i18n-cli -i "./file.ts" -o "./translations.json" -l spa_Latn -s eng_Latn -b azure --azureKey "..."`
567
+ *
568
+ * Outputs:
569
+ * ```json
570
+ * {
571
+ * "eng_Latn": {
572
+ * "test.message.v": [
573
+ * "You have one apple",
574
+ * "You have {{$count}} apples",
575
+ * "You have no apples"
576
+ * ]
577
+ * },
578
+ * "spa_Latn": {
579
+ * "test.message.v": [
580
+ * "Tienes una manzana",
581
+ * "Tienes {{$count}} manzanas",
582
+ * "No tienes manzanas"
583
+ * ]
584
+ * }
585
+ * }
586
+ * ```
587
+ *
588
+ * ### **Usage**
589
+ * ```ts
590
+ * import db from "./translations.json";
591
+ * setI18nDatabaseRaw(db);
592
+ * setCurrentLocalRaw("spa_Latn");
593
+ *
594
+ * const appleCount = 5;
595
+ *
596
+ * const msg = __tv("test.message.v", [
597
+ * ["You have one apple", ({count}) => count == 1],
598
+ * ["You have {{$count}} apples", ({count}) => count > 1],
599
+ * "You have no apples"
600
+ * ], { count: appleCount })
601
+ *
602
+ * console.log(msg); // Tienes 5 manzanas!
603
+ * ```
604
+ *
605
+ * ### **Escape Code**
606
+ * You can use double curly braces `{{...}}` to stop the translation engine from translating any text inside.
607
+ * The curly braces are removed after translation.
608
+ * If a `$` is placed before the text inside of the escape code, it is treated as a variable which values can be passed,
609
+ * and incorporated into the text.
610
+ *
611
+ * **NOTE:** the passed arguments are **NOT** translated
612
+ * ```ts
613
+ * import db from "./translations.json";
614
+ * setI18nDatabaseRaw(db);
615
+ * setCurrentLocalRaw("spa_Latn");
616
+ *
617
+ * const appleCount = 5;
618
+ *
619
+ * const msg = __tv("test.message.v", [
620
+ * ["You have one apple", ({count}) => count == 1],
621
+ * ["You have {{$count}} apples", ({count}) => count > 1],
622
+ * "You have no apples"
623
+ * ], { count: appleCount })
624
+ *
625
+ * console.log(msg); // Tienes 5 manzanas!
626
+ * ```
627
+ *
628
+ * @param key The key for the translation
629
+ * @param messages An array of message variants
630
+ * @param arg A object that is passed as the argument to the selection functions and used for variable substitution
631
+ * @returns The translation of the message for the currently set locale.
632
+ */
633
+ declare function __tv<T extends {
634
+ [k: string]: any | undefined;
635
+ }>(key: string, messages: TVArgs<T>, arg: T): string;
636
+
637
+ export { CachedMultiFileI18nDb, type CountryCode, CountryFlag, type CountryFlagProps, FOLDER_LANGUAGE_MANIFEST_NAME, type FolderLanguageManifestType, type I18nContextType, type I18nDatabase, I18nDatabaseDefault, type I18nDatabaseType, I18nFileProvider, type I18nFileProviderProps, I18nMultiFileProvider, type I18nMultiFileProviderProps, I18nProvider, type I18nProviderProps, LANG_CODES, LANG_SCRIPT_CODES, type LangCode, type LangScriptCode, LangScriptObj, type LanguageTranslations, SCRIPT_CODES, type ScriptCode, type ScriptDirection, SimpleI18nDb, type TVArgs, __t, __tv, __t as default, formatLangScriptCode, getCountryCode, getCurrentLocalRaw, getEnglishLangName, getI18nDatabaseRaw, getLangCode, getLangScriptDirection, getLocaleLangName, getScriptCode, getScriptDirection, setCurrentLocalRaw, setI18nDatabaseRaw, stringToLangCode, stringToLangScriptCode, stringToScriptCode, useI18n };