@depup/i18next 25.8.18-depup.2
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/.nvmrc +1 -0
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/changes.json +10 -0
- package/dist/cjs/i18next.js +2245 -0
- package/dist/esm/i18next.bundled.js +2256 -0
- package/dist/esm/i18next.js +2256 -0
- package/dist/esm/package.json +1 -0
- package/dist/umd/i18next.js +2251 -0
- package/dist/umd/i18next.min.js +1 -0
- package/i18next.js +2251 -0
- package/i18next.min.js +1 -0
- package/index.d.mts +63 -0
- package/index.d.ts +587 -0
- package/index.js +5 -0
- package/jsr.json +15 -0
- package/package.json +142 -0
- package/typescript/helpers.d.ts +77 -0
- package/typescript/options.d.ts +802 -0
- package/typescript/t.d.ts +516 -0
|
@@ -0,0 +1,802 @@
|
|
|
1
|
+
import type { $MergeBy, $PreservedValue, $Dictionary } from './helpers.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This interface can be augmented by users to add types to `i18next` default TypeOptions.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* ```ts
|
|
8
|
+
* // i18next.d.ts
|
|
9
|
+
* import 'i18next';
|
|
10
|
+
* declare module 'i18next' {
|
|
11
|
+
* interface CustomTypeOptions {
|
|
12
|
+
* defaultNS: 'custom';
|
|
13
|
+
* returnNull: false;
|
|
14
|
+
* returnObjects: false;
|
|
15
|
+
* nsSeparator: ':';
|
|
16
|
+
* keySeparator: '.';
|
|
17
|
+
* compatibilityJSON: 'v4';
|
|
18
|
+
* allowObjectInHTMLChildren: false;
|
|
19
|
+
* resources: {
|
|
20
|
+
* custom: {
|
|
21
|
+
* foo: 'foo';
|
|
22
|
+
* };
|
|
23
|
+
* };
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface CustomTypeOptions {}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This interface can be augmented by users to add types to `i18next` default PluginOptions.
|
|
32
|
+
*/
|
|
33
|
+
export interface CustomPluginOptions {}
|
|
34
|
+
|
|
35
|
+
export type TypeOptions = $MergeBy<
|
|
36
|
+
{
|
|
37
|
+
/** @see {InitOptions.returnNull} */
|
|
38
|
+
returnNull: false;
|
|
39
|
+
|
|
40
|
+
/** @see {InitOptions.returnEmptyString} */
|
|
41
|
+
returnEmptyString: true;
|
|
42
|
+
|
|
43
|
+
/** @see {InitOptions.returnObjects} */
|
|
44
|
+
returnObjects: false;
|
|
45
|
+
|
|
46
|
+
/** @see {InitOptions.keySeparator} */
|
|
47
|
+
keySeparator: '.';
|
|
48
|
+
|
|
49
|
+
/** @see {InitOptions.nsSeparator} */
|
|
50
|
+
nsSeparator: ':';
|
|
51
|
+
|
|
52
|
+
/** @see {InitOptions.pluralSeparator} */
|
|
53
|
+
pluralSeparator: '_';
|
|
54
|
+
|
|
55
|
+
/** @see {InitOptions.contextSeparator} */
|
|
56
|
+
contextSeparator: '_';
|
|
57
|
+
|
|
58
|
+
/** @see {InitOptions.defaultNS} */
|
|
59
|
+
defaultNS: 'translation';
|
|
60
|
+
|
|
61
|
+
/** @see {InitOptions.fallbackNS} */
|
|
62
|
+
fallbackNS: false;
|
|
63
|
+
|
|
64
|
+
/** @see {InitOptions.compatibilityJSON} */
|
|
65
|
+
compatibilityJSON: 'v4';
|
|
66
|
+
|
|
67
|
+
/** @see {InitOptions.resources} */
|
|
68
|
+
resources: object;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Flag that allows HTML elements to receive objects. This is only useful for React applications
|
|
72
|
+
* where you pass objects to HTML elements so they can be replaced to their respective interpolation
|
|
73
|
+
* values (mostly with Trans component)
|
|
74
|
+
*/
|
|
75
|
+
allowObjectInHTMLChildren: false;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Flag that enables strict key checking even if a `defaultValue` has been provided.
|
|
79
|
+
* This ensures all calls of `t` function don't accidentally use implicitly missing keys.
|
|
80
|
+
*/
|
|
81
|
+
strictKeyChecks: false;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Prefix for interpolation
|
|
85
|
+
*/
|
|
86
|
+
interpolationPrefix: '{{';
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Suffix for interpolation
|
|
90
|
+
*/
|
|
91
|
+
interpolationSuffix: '}}';
|
|
92
|
+
|
|
93
|
+
/** @see {InterpolationOptions.unescapePrefix} */
|
|
94
|
+
unescapePrefix: '-';
|
|
95
|
+
|
|
96
|
+
/** @see {InterpolationOptions.unescapeSuffix} */
|
|
97
|
+
unescapeSuffix: '';
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Use a proxy-based selector to select a translation.
|
|
101
|
+
*
|
|
102
|
+
* Enables features like go-to definition, and better DX/faster autocompletion
|
|
103
|
+
* for TypeScript developers.
|
|
104
|
+
*
|
|
105
|
+
* If you're working with an especially large set of translations and aren't
|
|
106
|
+
* using context, you set `enableSelector` to `"optimize"` and i18next won't do
|
|
107
|
+
* any type-level processing of your translations at all.
|
|
108
|
+
*
|
|
109
|
+
* With `enableSelector` set to `"optimize"`, i18next is capable of supporting
|
|
110
|
+
* arbitrarily large/deep translation sets without causing any IDE slowdown
|
|
111
|
+
* whatsoever.
|
|
112
|
+
*
|
|
113
|
+
* @default false
|
|
114
|
+
*/
|
|
115
|
+
enableSelector: false;
|
|
116
|
+
},
|
|
117
|
+
CustomTypeOptions
|
|
118
|
+
>;
|
|
119
|
+
|
|
120
|
+
export type PluginOptions<T> = $MergeBy<
|
|
121
|
+
{
|
|
122
|
+
/**
|
|
123
|
+
* Options for language detection - check documentation of plugin
|
|
124
|
+
* @default undefined
|
|
125
|
+
*/
|
|
126
|
+
detection?: object;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Options for backend - check documentation of plugin
|
|
130
|
+
* @default undefined
|
|
131
|
+
*/
|
|
132
|
+
backend?: T;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Options for cache layer - check documentation of plugin
|
|
136
|
+
* @default undefined
|
|
137
|
+
*/
|
|
138
|
+
cache?: object;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Options for i18n message format - check documentation of plugin
|
|
142
|
+
* @default undefined
|
|
143
|
+
*/
|
|
144
|
+
i18nFormat?: object;
|
|
145
|
+
},
|
|
146
|
+
CustomPluginOptions
|
|
147
|
+
>;
|
|
148
|
+
|
|
149
|
+
export type FormatFunction = (
|
|
150
|
+
value: any,
|
|
151
|
+
format?: string,
|
|
152
|
+
lng?: string,
|
|
153
|
+
options?: InterpolationOptions & $Dictionary<any>,
|
|
154
|
+
) => string;
|
|
155
|
+
|
|
156
|
+
export interface InterpolationOptions {
|
|
157
|
+
/**
|
|
158
|
+
* Format function see formatting for details
|
|
159
|
+
* @default noop
|
|
160
|
+
*/
|
|
161
|
+
format?: FormatFunction;
|
|
162
|
+
/**
|
|
163
|
+
* Used to separate format from interpolation value
|
|
164
|
+
* @default ','
|
|
165
|
+
*/
|
|
166
|
+
formatSeparator?: string;
|
|
167
|
+
/**
|
|
168
|
+
* Escape function
|
|
169
|
+
* @default str => str
|
|
170
|
+
*/
|
|
171
|
+
escape?(str: string): string;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Always format interpolated values.
|
|
175
|
+
* @default false
|
|
176
|
+
*/
|
|
177
|
+
alwaysFormat?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Escape passed in values to avoid xss injection
|
|
180
|
+
* @default true
|
|
181
|
+
*/
|
|
182
|
+
escapeValue?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* If true, then value passed into escape function is not casted to string, use with custom escape function that does its own type check
|
|
185
|
+
* @default false
|
|
186
|
+
*/
|
|
187
|
+
useRawValueToEscape?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Prefix for interpolation
|
|
190
|
+
* @default '{{'
|
|
191
|
+
*/
|
|
192
|
+
prefix?: string;
|
|
193
|
+
/**
|
|
194
|
+
* Suffix for interpolation
|
|
195
|
+
* @default '}}'
|
|
196
|
+
*/
|
|
197
|
+
suffix?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Escaped prefix for interpolation (regexSafe)
|
|
200
|
+
* @default undefined
|
|
201
|
+
*/
|
|
202
|
+
prefixEscaped?: string;
|
|
203
|
+
/**
|
|
204
|
+
* Escaped suffix for interpolation (regexSafe)
|
|
205
|
+
* @default undefined
|
|
206
|
+
*/
|
|
207
|
+
suffixEscaped?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Suffix to unescaped mode
|
|
210
|
+
* @default undefined
|
|
211
|
+
*/
|
|
212
|
+
unescapeSuffix?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Prefix to unescaped mode
|
|
215
|
+
* @default '-'
|
|
216
|
+
*/
|
|
217
|
+
unescapePrefix?: string;
|
|
218
|
+
/**
|
|
219
|
+
* Prefix for nesting
|
|
220
|
+
* @default '$t('
|
|
221
|
+
*/
|
|
222
|
+
nestingPrefix?: string;
|
|
223
|
+
/**
|
|
224
|
+
* Suffix for nesting
|
|
225
|
+
* @default ')'
|
|
226
|
+
*/
|
|
227
|
+
nestingSuffix?: string;
|
|
228
|
+
/**
|
|
229
|
+
* Escaped prefix for nesting (regexSafe)
|
|
230
|
+
* @default undefined
|
|
231
|
+
*/
|
|
232
|
+
nestingPrefixEscaped?: string;
|
|
233
|
+
/**
|
|
234
|
+
* Escaped suffix for nesting (regexSafe)
|
|
235
|
+
* @default undefined
|
|
236
|
+
*/
|
|
237
|
+
nestingSuffixEscaped?: string;
|
|
238
|
+
/**
|
|
239
|
+
* Separates options from key
|
|
240
|
+
* @default ','
|
|
241
|
+
*/
|
|
242
|
+
nestingOptionsSeparator?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Global variables to use in interpolation replacements
|
|
245
|
+
* @default undefined
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
defaultVariables?: { [index: string]: any };
|
|
249
|
+
/**
|
|
250
|
+
* After how many interpolation runs to break out before throwing a stack overflow
|
|
251
|
+
* @default 1000
|
|
252
|
+
*/
|
|
253
|
+
maxReplaces?: number;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* If true, it will skip to interpolate the variables
|
|
257
|
+
* @default true
|
|
258
|
+
*/
|
|
259
|
+
skipOnVariables?: boolean;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface FallbackLngObjList {
|
|
263
|
+
[language: string]: readonly string[];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export type FallbackLng =
|
|
267
|
+
| string
|
|
268
|
+
| readonly string[]
|
|
269
|
+
| FallbackLngObjList
|
|
270
|
+
| ((code: string) => string | readonly string[] | FallbackLngObjList);
|
|
271
|
+
|
|
272
|
+
export interface ReactOptions {
|
|
273
|
+
/**
|
|
274
|
+
* Set it to fallback to let passed namespaces to translated hoc act as fallbacks
|
|
275
|
+
* @default 'default'
|
|
276
|
+
*/
|
|
277
|
+
nsMode?: 'default' | 'fallback';
|
|
278
|
+
/**
|
|
279
|
+
* Set it to the default parent element created by the Trans component.
|
|
280
|
+
* @default 'div'
|
|
281
|
+
*/
|
|
282
|
+
defaultTransParent?: string;
|
|
283
|
+
/**
|
|
284
|
+
* Set which events trigger a re-render, can be set to false or string of events
|
|
285
|
+
* @default 'languageChanged'
|
|
286
|
+
*/
|
|
287
|
+
bindI18n?: string | false;
|
|
288
|
+
/**
|
|
289
|
+
* Set which events on store trigger a re-render, can be set to false or string of events
|
|
290
|
+
* @default ''
|
|
291
|
+
*/
|
|
292
|
+
bindI18nStore?: string | false;
|
|
293
|
+
/**
|
|
294
|
+
* Set fallback value for Trans components without children
|
|
295
|
+
* @default undefined
|
|
296
|
+
*/
|
|
297
|
+
transEmptyNodeValue?: string;
|
|
298
|
+
/**
|
|
299
|
+
* Set it to false if you do not want to use Suspense
|
|
300
|
+
* @default true
|
|
301
|
+
*/
|
|
302
|
+
useSuspense?: boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Function to generate an i18nKey from the defaultValue (or Trans children)
|
|
305
|
+
* when no key is provided.
|
|
306
|
+
* By default, the defaultValue (Trans text) itself is used as the key.
|
|
307
|
+
* If you want to require keys for all translations, supply a function
|
|
308
|
+
* that always throws an error.
|
|
309
|
+
* @default undefined
|
|
310
|
+
*/
|
|
311
|
+
hashTransKey?(defaultValue: TOptionsBase['defaultValue']): TOptionsBase['defaultValue'];
|
|
312
|
+
/**
|
|
313
|
+
* Convert eg. <br/> found in translations to a react component of type br
|
|
314
|
+
* @default true
|
|
315
|
+
*/
|
|
316
|
+
transSupportBasicHtmlNodes?: boolean;
|
|
317
|
+
/**
|
|
318
|
+
* Which nodes not to convert in defaultValue generation in the Trans component.
|
|
319
|
+
* @default ['br', 'strong', 'i', 'p']
|
|
320
|
+
*/
|
|
321
|
+
transKeepBasicHtmlNodesFor?: readonly string[];
|
|
322
|
+
/**
|
|
323
|
+
* Wrap text nodes in a user-specified element.
|
|
324
|
+
* @default ''
|
|
325
|
+
*/
|
|
326
|
+
transWrapTextNodes?: string;
|
|
327
|
+
/**
|
|
328
|
+
* Default props to apply to all Trans components.
|
|
329
|
+
* Component-level props will override these defaults.
|
|
330
|
+
*/
|
|
331
|
+
transDefaultProps?: {
|
|
332
|
+
tOptions?: TOptions;
|
|
333
|
+
values?: object;
|
|
334
|
+
shouldUnescape?: boolean;
|
|
335
|
+
components?: readonly unknown[] | { readonly [tagName: string]: unknown }; // Use `unknown` (or `any`) to be permissive without importing React.
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Optional keyPrefix that will be automatically applied to returned t function in useTranslation for example.
|
|
339
|
+
* @default undefined
|
|
340
|
+
*/
|
|
341
|
+
keyPrefix?: string;
|
|
342
|
+
/**
|
|
343
|
+
* Unescape function
|
|
344
|
+
* by default it unescapes some basic html entities
|
|
345
|
+
*/
|
|
346
|
+
unescape?(str: string): string;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export type ResourceKey =
|
|
350
|
+
| string
|
|
351
|
+
| {
|
|
352
|
+
[key: string]: any;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
export interface ResourceLanguage {
|
|
356
|
+
[namespace: string]: ResourceKey;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export interface Resource {
|
|
360
|
+
[language: string]: ResourceLanguage;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export interface InitOptions<T = object> extends PluginOptions<T> {
|
|
364
|
+
/**
|
|
365
|
+
* Logs info level to console output. Helps finding issues with loading not working.
|
|
366
|
+
* @default false
|
|
367
|
+
*/
|
|
368
|
+
debug?: boolean;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Show support notice in console during initialization.
|
|
372
|
+
* @default true
|
|
373
|
+
*/
|
|
374
|
+
showSupportNotice?: boolean;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Resources to initialize with (if not using loading or not appending using addResourceBundle)
|
|
378
|
+
* @default undefined
|
|
379
|
+
*/
|
|
380
|
+
resources?: Resource;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Allow initializing with bundled resources while using a backend to load non bundled ones.
|
|
384
|
+
* @default false
|
|
385
|
+
*/
|
|
386
|
+
partialBundledLanguages?: boolean;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Language to use (overrides language detection)
|
|
390
|
+
* @default undefined
|
|
391
|
+
*/
|
|
392
|
+
lng?: string;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Language to use if translations in user language are not available.
|
|
396
|
+
* @default 'dev'
|
|
397
|
+
*/
|
|
398
|
+
fallbackLng?: false | FallbackLng;
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Array of allowed languages
|
|
402
|
+
* @default false
|
|
403
|
+
*/
|
|
404
|
+
supportedLngs?: false | readonly string[];
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* If true will pass eg. en-US if finding en in supportedLngs
|
|
408
|
+
* @default false
|
|
409
|
+
*/
|
|
410
|
+
nonExplicitSupportedLngs?: boolean;
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Language codes to lookup, given set language is 'en-US':
|
|
414
|
+
* 'all' --> ['en-US', 'en', 'dev'],
|
|
415
|
+
* 'currentOnly' --> 'en-US',
|
|
416
|
+
* 'languageOnly' --> 'en'
|
|
417
|
+
* @default 'all'
|
|
418
|
+
*/
|
|
419
|
+
load?: 'all' | 'currentOnly' | 'languageOnly';
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Array of languages to preload. Important on server-side to assert translations are loaded before rendering views.
|
|
423
|
+
* @default false
|
|
424
|
+
*/
|
|
425
|
+
preload?: false | readonly string[];
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Language will be lowercased eg. en-US --> en-us
|
|
429
|
+
* @default false
|
|
430
|
+
*/
|
|
431
|
+
lowerCaseLng?: boolean;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Language will be lowercased EN --> en while leaving full locales like en-US
|
|
435
|
+
* @default false
|
|
436
|
+
*/
|
|
437
|
+
cleanCode?: boolean;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* String or array of namespaces to load
|
|
441
|
+
* @default 'translation'
|
|
442
|
+
*/
|
|
443
|
+
ns?: string | readonly string[];
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Default namespace used if not passed to translation function
|
|
447
|
+
* @default 'translation'
|
|
448
|
+
*/
|
|
449
|
+
defaultNS?: string | false | readonly string[];
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* String or array of namespaces to lookup key if not found in given namespace.
|
|
453
|
+
* @default false
|
|
454
|
+
*/
|
|
455
|
+
fallbackNS?: false | string | readonly string[];
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Calls save missing key function on backend if key not found.
|
|
459
|
+
* @default false
|
|
460
|
+
*/
|
|
461
|
+
saveMissing?: boolean;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Calls save missing key function on backend if key not found also for plural forms.
|
|
465
|
+
* @default false
|
|
466
|
+
*/
|
|
467
|
+
saveMissingPlurals?: boolean;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Experimental: enable to update default values using the saveMissing
|
|
471
|
+
* (Works only if defaultValue different from translated value.
|
|
472
|
+
* Only useful on initial development or when keeping code as source of truth not changing values outside of code.
|
|
473
|
+
* Only supported if backend supports it already)
|
|
474
|
+
* @default false
|
|
475
|
+
*/
|
|
476
|
+
updateMissing?: boolean;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* @default 'fallback'
|
|
480
|
+
*/
|
|
481
|
+
saveMissingTo?: 'current' | 'all' | 'fallback';
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Used to not fallback to the key as default value, when using saveMissing functionality.
|
|
485
|
+
* i.e. when using with i18next-http-backend this will result in having a key with an empty string value.
|
|
486
|
+
* @default false
|
|
487
|
+
*/
|
|
488
|
+
missingKeyNoValueFallbackToKey?: boolean;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Used for custom missing key handling (needs saveMissing set to true!)
|
|
492
|
+
* @default false
|
|
493
|
+
*/
|
|
494
|
+
missingKeyHandler?:
|
|
495
|
+
| false
|
|
496
|
+
| ((
|
|
497
|
+
lngs: readonly string[],
|
|
498
|
+
ns: string,
|
|
499
|
+
key: string,
|
|
500
|
+
fallbackValue: string,
|
|
501
|
+
updateMissing: boolean,
|
|
502
|
+
options: any,
|
|
503
|
+
) => void);
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Receives a key that was not found in `t()` and returns a value, that will be returned by `t()`
|
|
507
|
+
* @default noop
|
|
508
|
+
*/
|
|
509
|
+
parseMissingKeyHandler?(key: string, defaultValue?: string, options?: any): any;
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Appends namespace to missing key
|
|
513
|
+
* @default false
|
|
514
|
+
*/
|
|
515
|
+
appendNamespaceToMissingKey?: boolean;
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Gets called in case a interpolation value is undefined. This method will not be called if the value is empty string or null
|
|
519
|
+
* @default noop
|
|
520
|
+
*/
|
|
521
|
+
missingInterpolationHandler?: (text: string, value: any, options: InitOptions) => any;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Will use 'plural' as suffix for languages only having 1 plural form, setting it to false will suffix all with numbers
|
|
525
|
+
* @default true
|
|
526
|
+
*/
|
|
527
|
+
simplifyPluralSuffix?: boolean;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* String or array of postProcessors to apply per default
|
|
531
|
+
* @default false
|
|
532
|
+
*/
|
|
533
|
+
postProcess?: false | string | readonly string[];
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* passthrough the resolved object including 'usedNS', 'usedLang' etc into options object of postprocessors as 'i18nResolved' property
|
|
537
|
+
* @default false
|
|
538
|
+
*/
|
|
539
|
+
postProcessPassResolved?: boolean;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Allows null values as valid translation
|
|
543
|
+
* @default false
|
|
544
|
+
*/
|
|
545
|
+
returnNull?: boolean;
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Allows empty string as valid translation
|
|
549
|
+
* @default true
|
|
550
|
+
*/
|
|
551
|
+
returnEmptyString?: boolean;
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Allows objects as valid translation result
|
|
555
|
+
* @default false
|
|
556
|
+
*/
|
|
557
|
+
returnObjects?: boolean;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Returns an object that includes information about the used language, namespace, key and value
|
|
561
|
+
* @default false
|
|
562
|
+
*/
|
|
563
|
+
returnDetails?: boolean;
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Gets called if object was passed in as key but returnObjects was set to false
|
|
567
|
+
* @default noop
|
|
568
|
+
*/
|
|
569
|
+
returnedObjectHandler?(key: string, value: string, options: any): void;
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Char, eg. '\n' that arrays will be joined by
|
|
573
|
+
* @default false
|
|
574
|
+
*/
|
|
575
|
+
joinArrays?: false | string;
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Sets defaultValue
|
|
579
|
+
* @default args => ({ defaultValue: args[1] })
|
|
580
|
+
*/
|
|
581
|
+
overloadTranslationOptionHandler?(args: string[]): TOptions;
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* @see https://www.i18next.com/translation-function/interpolation
|
|
585
|
+
*/
|
|
586
|
+
interpolation?: InterpolationOptions;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Options for react - check documentation of plugin
|
|
590
|
+
* @default undefined
|
|
591
|
+
*/
|
|
592
|
+
react?: ReactOptions;
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Triggers resource loading in init function inside a setTimeout (default async behaviour).
|
|
596
|
+
* Set it to false if your backend loads resources sync - that way calling i18next.t after
|
|
597
|
+
* init is possible without relaying on the init callback.
|
|
598
|
+
* @default true
|
|
599
|
+
*/
|
|
600
|
+
initAsync?: boolean;
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* @deprecated Use initAsync instead.
|
|
604
|
+
*/
|
|
605
|
+
initImmediate?: boolean;
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Char to separate keys
|
|
609
|
+
* @default '.'
|
|
610
|
+
*/
|
|
611
|
+
keySeparator?: false | string;
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Char to split namespace from key
|
|
615
|
+
* @default ':'
|
|
616
|
+
*/
|
|
617
|
+
nsSeparator?: false | string;
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Char to split plural from key
|
|
621
|
+
* @default '_'
|
|
622
|
+
*/
|
|
623
|
+
pluralSeparator?: string;
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Char to split context from key
|
|
627
|
+
* @default '_'
|
|
628
|
+
*/
|
|
629
|
+
contextSeparator?: string;
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Prefixes the namespace to the returned key when using `cimode`
|
|
633
|
+
* @default false
|
|
634
|
+
*/
|
|
635
|
+
appendNamespaceToCIMode?: boolean;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Compatibility JSON version
|
|
639
|
+
* @warning only `v4` is available and supported by typescript
|
|
640
|
+
* @default 'v4'
|
|
641
|
+
*/
|
|
642
|
+
compatibilityJSON?: 'v4';
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Options for https://github.com/locize/locize-lastused
|
|
646
|
+
* @default undefined
|
|
647
|
+
*/
|
|
648
|
+
locizeLastUsed?: {
|
|
649
|
+
/**
|
|
650
|
+
* The id of your locize project
|
|
651
|
+
*/
|
|
652
|
+
projectId: string;
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* An api key if you want to send missing keys
|
|
656
|
+
*/
|
|
657
|
+
apiKey?: string;
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* The reference language of your project
|
|
661
|
+
* @default 'en'
|
|
662
|
+
*/
|
|
663
|
+
referenceLng?: string;
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Version
|
|
667
|
+
* @default 'latest'
|
|
668
|
+
*/
|
|
669
|
+
version?: string;
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Debounce interval to send data in milliseconds
|
|
673
|
+
* @default 90000
|
|
674
|
+
*/
|
|
675
|
+
debounceSubmit?: number;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Hostnames that are allowed to send last used data.
|
|
679
|
+
* Please keep those to your local system, staging, test servers (not production)
|
|
680
|
+
* @default ['localhost']
|
|
681
|
+
*/
|
|
682
|
+
allowedHosts?: readonly string[];
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Automatically lookup for a flat key if a nested key is not found an vice-versa
|
|
687
|
+
* @default true
|
|
688
|
+
*/
|
|
689
|
+
ignoreJSONStructure?: boolean;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Limit parallelism of calls to backend
|
|
693
|
+
* This is needed to prevent trying to open thousands of
|
|
694
|
+
* sockets or file descriptors, which can cause failures
|
|
695
|
+
* and actually make the entire process take longer.
|
|
696
|
+
* @default 10
|
|
697
|
+
*/
|
|
698
|
+
maxParallelReads?: number;
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* The maximum number of retries to perform.
|
|
702
|
+
* Note that retries are only performed when a request has no response
|
|
703
|
+
* and throws an error.
|
|
704
|
+
* The default value is used if value is set below 0.
|
|
705
|
+
* @default 5
|
|
706
|
+
*/
|
|
707
|
+
maxRetries?: number;
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Set how long to wait, in milliseconds, between retries of failed requests.
|
|
711
|
+
* This number is compounded by a factor of 2 for subsequent retry.
|
|
712
|
+
* The default value is used if value is set below 1ms.
|
|
713
|
+
* @default 350
|
|
714
|
+
*/
|
|
715
|
+
retryTimeout?: number;
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Initializes the internal formatter for the in-built formats as cached version.
|
|
719
|
+
* Can be set to false for this type of issues: https://github.com/i18next/i18next/issues/2227
|
|
720
|
+
* @default true
|
|
721
|
+
*/
|
|
722
|
+
cacheInBuiltFormats?: boolean;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
export interface TOptionsBase {
|
|
726
|
+
/**
|
|
727
|
+
* Default value to return if a translation was not found
|
|
728
|
+
*/
|
|
729
|
+
defaultValue?: unknown;
|
|
730
|
+
/**
|
|
731
|
+
* Count value used for plurals
|
|
732
|
+
*/
|
|
733
|
+
count?: number;
|
|
734
|
+
/**
|
|
735
|
+
* Ordinal flag for ordinal plurals
|
|
736
|
+
*/
|
|
737
|
+
ordinal?: boolean;
|
|
738
|
+
/**
|
|
739
|
+
* Used for contexts (eg. male\female)
|
|
740
|
+
*/
|
|
741
|
+
context?: unknown;
|
|
742
|
+
/**
|
|
743
|
+
* Object with vars for interpolation - or put them directly in options
|
|
744
|
+
*/
|
|
745
|
+
replace?: any;
|
|
746
|
+
/**
|
|
747
|
+
* Override language to use
|
|
748
|
+
*/
|
|
749
|
+
lng?: string;
|
|
750
|
+
/**
|
|
751
|
+
* Override languages to use
|
|
752
|
+
*/
|
|
753
|
+
lngs?: readonly string[];
|
|
754
|
+
/**
|
|
755
|
+
* Override language to lookup key if not found see fallbacks for details
|
|
756
|
+
*/
|
|
757
|
+
fallbackLng?: false | FallbackLng;
|
|
758
|
+
/**
|
|
759
|
+
* Override namespaces (string or array)
|
|
760
|
+
*/
|
|
761
|
+
ns?: Namespace;
|
|
762
|
+
/**
|
|
763
|
+
* Override char to separate keys
|
|
764
|
+
*/
|
|
765
|
+
keySeparator?: false | string;
|
|
766
|
+
/**
|
|
767
|
+
* Override char to split namespace from key
|
|
768
|
+
*/
|
|
769
|
+
nsSeparator?: false | string;
|
|
770
|
+
/**
|
|
771
|
+
* Accessing an object not a translation string (can be set globally too)
|
|
772
|
+
*/
|
|
773
|
+
returnObjects?: boolean;
|
|
774
|
+
/**
|
|
775
|
+
* Returns an object that includes information about the used language, namespace, key and value
|
|
776
|
+
*/
|
|
777
|
+
returnDetails?: boolean;
|
|
778
|
+
/**
|
|
779
|
+
* Char, eg. '\n' that arrays will be joined by (can be set globally too)
|
|
780
|
+
*/
|
|
781
|
+
joinArrays?: string;
|
|
782
|
+
/**
|
|
783
|
+
* String or array of postProcessors to apply see interval plurals as a sample
|
|
784
|
+
*/
|
|
785
|
+
postProcess?: string | readonly string[];
|
|
786
|
+
/**
|
|
787
|
+
* Override interpolation options
|
|
788
|
+
*/
|
|
789
|
+
interpolation?: InterpolationOptions;
|
|
790
|
+
/**
|
|
791
|
+
* Optional keyPrefix that will be applied to the key before resolving.
|
|
792
|
+
* Only supported on the TFunction returned by getFixedT().
|
|
793
|
+
*/
|
|
794
|
+
keyPrefix?: string;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
export type TOptions<TInterpolationMap extends object = $Dictionary> = TOptionsBase &
|
|
798
|
+
TInterpolationMap;
|
|
799
|
+
|
|
800
|
+
export type FlatNamespace = $PreservedValue<keyof TypeOptions['resources'], string>;
|
|
801
|
+
export type Namespace<T = FlatNamespace> = T | readonly T[];
|
|
802
|
+
export type DefaultNamespace = TypeOptions['defaultNS'];
|