i18next 20.3.3 → 20.3.4

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/index.d.ts +38 -29
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 20.3.4
2
+
3
+ - fix(types): only use readonly array of strings in API [1629](https://github.com/i18next/i18next/pull/1629)
4
+
1
5
  ### 20.3.3
2
6
 
3
7
  - add transWrapTextNodes to types [1626](https://github.com/i18next/i18next/pull/1626)
package/index.d.ts CHANGED
@@ -2,14 +2,14 @@ type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
2
2
  type MergeBy<T, K> = Omit<T, keyof K> & K;
3
3
 
4
4
  export interface FallbackLngObjList {
5
- [language: string]: string[];
5
+ [language: string]: readonly string[];
6
6
  }
7
7
 
8
8
  export type FallbackLng =
9
9
  | string
10
- | string[]
10
+ | readonly string[]
11
11
  | FallbackLngObjList
12
- | ((code: string) => string | string[] | FallbackLngObjList);
12
+ | ((code: string) => string | readonly string[] | FallbackLngObjList);
13
13
 
14
14
  export type FormatFunction = (
15
15
  value: any,
@@ -178,7 +178,7 @@ export interface ReactOptions {
178
178
  * Which nodes not to convert in defaultValue generation in the Trans component.
179
179
  * @default ['br', 'strong', 'i', 'p']
180
180
  */
181
- transKeepBasicHtmlNodesFor?: string[];
181
+ transKeepBasicHtmlNodesFor?: readonly string[];
182
182
  /**
183
183
  * Wrap text nodes in a user-specified element.
184
184
  * @default ''
@@ -252,7 +252,7 @@ export interface InitOptions extends MergeBy<DefaultPluginOptions, PluginOptions
252
252
  * DEPRECATED use supportedLngs
253
253
  * @default false
254
254
  */
255
- whitelist?: false | string[];
255
+ whitelist?: false | readonly string[];
256
256
 
257
257
  /**
258
258
  * DEPRECTADED use nonExplicitSupportedLngs
@@ -264,7 +264,7 @@ export interface InitOptions extends MergeBy<DefaultPluginOptions, PluginOptions
264
264
  * Array of allowed languages
265
265
  * @default false
266
266
  */
267
- supportedLngs?: false | string[];
267
+ supportedLngs?: false | readonly string[];
268
268
 
269
269
  /**
270
270
  * If true will pass eg. en-US if finding en in supportedLngs
@@ -285,7 +285,7 @@ export interface InitOptions extends MergeBy<DefaultPluginOptions, PluginOptions
285
285
  * Array of languages to preload. Important on server-side to assert translations are loaded before rendering views.
286
286
  * @default false
287
287
  */
288
- preload?: false | string[];
288
+ preload?: false | readonly string[];
289
289
 
290
290
  /**
291
291
  * Language will be lowercased eg. en-US --> en-us
@@ -303,7 +303,7 @@ export interface InitOptions extends MergeBy<DefaultPluginOptions, PluginOptions
303
303
  * String or array of namespaces to load
304
304
  * @default 'translation'
305
305
  */
306
- ns?: string | string[];
306
+ ns?: string | readonly string[];
307
307
 
308
308
  /**
309
309
  * Default namespace used if not passed to translation function
@@ -315,7 +315,7 @@ export interface InitOptions extends MergeBy<DefaultPluginOptions, PluginOptions
315
315
  * String or array of namespaces to lookup key if not found in given namespace.
316
316
  * @default false
317
317
  */
318
- fallbackNS?: false | string | string[];
318
+ fallbackNS?: false | string | readonly string[];
319
319
 
320
320
  /**
321
321
  * Calls save missing key function on backend if key not found
@@ -343,7 +343,7 @@ export interface InitOptions extends MergeBy<DefaultPluginOptions, PluginOptions
343
343
  */
344
344
  missingKeyHandler?:
345
345
  | false
346
- | ((lngs: string[], ns: string, key: string, fallbackValue: string) => void);
346
+ | ((lngs: readonly string[], ns: string, key: string, fallbackValue: string) => void);
347
347
 
348
348
  /**
349
349
  * Receives a key that was not found in `t()` and returns a value, that will be returned by `t()`
@@ -373,7 +373,7 @@ export interface InitOptions extends MergeBy<DefaultPluginOptions, PluginOptions
373
373
  * String or array of postProcessors to apply per default
374
374
  * @default false
375
375
  */
376
- postProcess?: false | string | string[];
376
+ postProcess?: false | string | readonly string[];
377
377
 
378
378
  /**
379
379
  * passthrough the resolved object including 'usedNS', 'usedLang' etc into options object of postprocessors as 'i18nResolved' property
@@ -547,7 +547,7 @@ export interface InitOptions extends MergeBy<DefaultPluginOptions, PluginOptions
547
547
  * Handle when locize saved the edited translations, eg. reload website
548
548
  * @default noop
549
549
  */
550
- onEditorSaved?: (lng: null, ns: string | string[]) => void;
550
+ onEditorSaved?: (lng: null, ns: string | readonly string[]) => void;
551
551
  };
552
552
 
553
553
  /**
@@ -588,7 +588,7 @@ export interface InitOptions extends MergeBy<DefaultPluginOptions, PluginOptions
588
588
  * Please keep those to your local system, staging, test servers (not production)
589
589
  * @default ['localhost']
590
590
  */
591
- allowedHosts?: string[];
591
+ allowedHosts?: readonly string[];
592
592
  };
593
593
 
594
594
  /**
@@ -622,7 +622,7 @@ export interface TOptionsBase {
622
622
  /**
623
623
  * Override languages to use
624
624
  */
625
- lngs?: string[];
625
+ lngs?: readonly string[];
626
626
  /**
627
627
  * Override language to lookup key if not found see fallbacks for details
628
628
  */
@@ -630,7 +630,7 @@ export interface TOptionsBase {
630
630
  /**
631
631
  * Override namespaces (string or array)
632
632
  */
633
- ns?: string | string[];
633
+ ns?: string | readonly string[];
634
634
  /**
635
635
  * Override char to separate keys
636
636
  */
@@ -650,7 +650,7 @@ export interface TOptionsBase {
650
650
  /**
651
651
  * String or array of postProcessors to apply see interval plurals as a sample
652
652
  */
653
- postProcess?: string | string[];
653
+ postProcess?: string | readonly string[];
654
654
  /**
655
655
  * Override interpolation options
656
656
  */
@@ -780,9 +780,18 @@ export interface BackendModule<TOptions = object> extends Module {
780
780
  init(services: Services, backendOptions: TOptions, i18nextOptions: InitOptions): void;
781
781
  read(language: string, namespace: string, callback: ReadCallback): void;
782
782
  /** Save the missing translation */
783
- create?(languages: string[], namespace: string, key: string, fallbackValue: string): void;
783
+ create?(
784
+ languages: readonly string[],
785
+ namespace: string,
786
+ key: string,
787
+ fallbackValue: string,
788
+ ): void;
784
789
  /** Load multiple languages and namespaces. For backends supporting multiple resources loading */
785
- readMulti?(languages: string[], namespaces: string[], callback: MultiReadCallback): void;
790
+ readMulti?(
791
+ languages: readonly string[],
792
+ namespaces: readonly string[],
793
+ callback: MultiReadCallback,
794
+ ): void;
786
795
  /** Store the translation. For backends acting as cache layer */
787
796
  save?(language: string, namespace: string, data: ResourceLanguage): void;
788
797
  }
@@ -796,7 +805,7 @@ export interface LanguageDetectorModule extends Module {
796
805
  type: 'languageDetector';
797
806
  init(services: Services, detectorOptions: object, i18nextOptions: InitOptions): void;
798
807
  /** Must return detected language */
799
- detect(): string | string[] | undefined;
808
+ detect(): string | readonly string[] | undefined;
800
809
  cacheUserLanguage(lng: string): void;
801
810
  }
802
811
 
@@ -811,7 +820,7 @@ export interface LanguageDetectorAsyncModule extends Module {
811
820
  async: true;
812
821
  init(services: Services, detectorOptions: object, i18nextOptions: InitOptions): void;
813
822
  /** Must call callback passing detected language */
814
- detect(callback: (lng: string | string[] | undefined) => void): void;
823
+ detect(callback: (lng: string | readonly string[] | undefined) => void): void;
815
824
  cacheUserLanguage(lng: string): void;
816
825
  }
817
826
 
@@ -913,8 +922,8 @@ export interface i18n {
913
922
  * Both params could be arrays of languages or namespaces and will be treated as fallbacks in that case.
914
923
  * On the returned function you can like in the t function override the languages or namespaces by passing them in options or by prepending namespace.
915
924
  */
916
- getFixedT(lng: string | string[], ns?: string | string[]): TFunction;
917
- getFixedT(lng: null, ns: string | string[]): TFunction;
925
+ getFixedT(lng: string | readonly string[], ns?: string | readonly string[]): TFunction;
926
+ getFixedT(lng: null, ns: string | readonly string[]): TFunction;
918
927
 
919
928
  /**
920
929
  * Changes the language. The callback will be called as soon translations were loaded or an error occurs while loading.
@@ -931,27 +940,27 @@ export interface i18n {
931
940
  /**
932
941
  * Is set to an array of language-codes that will be used it order to lookup the translation value.
933
942
  */
934
- languages: string[];
943
+ languages: readonly string[];
935
944
 
936
945
  /**
937
946
  * Loads additional namespaces not defined in init options.
938
947
  */
939
- loadNamespaces(ns: string | string[], callback?: Callback): Promise<void>;
948
+ loadNamespaces(ns: string | readonly string[], callback?: Callback): Promise<void>;
940
949
 
941
950
  /**
942
951
  * Loads additional languages not defined in init options (preload).
943
952
  */
944
- loadLanguages(lngs: string | string[], callback?: Callback): Promise<void>;
953
+ loadLanguages(lngs: string | readonly string[], callback?: Callback): Promise<void>;
945
954
 
946
955
  /**
947
956
  * Reloads resources on given state. Optionally you can pass an array of languages and namespaces as params if you don't want to reload all.
948
957
  */
949
958
  reloadResources(
950
- lngs?: string | string[],
951
- ns?: string | string[],
959
+ lngs?: string | readonly string[],
960
+ ns?: string | readonly string[],
952
961
  callback?: () => void,
953
962
  ): Promise<void>;
954
- reloadResources(lngs: null, ns: string | string[], callback?: () => void): Promise<void>;
963
+ reloadResources(lngs: null, ns: string | readonly string[], callback?: () => void): Promise<void>;
955
964
 
956
965
  /**
957
966
  * Changes the default namespace.
@@ -1002,7 +1011,7 @@ export interface i18n {
1002
1011
  */
1003
1012
  on(
1004
1013
  event: 'missingKey',
1005
- callback: (lngs: string[], namespace: string, key: string, res: string) => void,
1014
+ callback: (lngs: readonly string[], namespace: string, key: string, res: string) => void,
1006
1015
  ): void;
1007
1016
 
1008
1017
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next",
3
- "version": "20.3.3",
3
+ "version": "20.3.4",
4
4
  "description": "i18next internationalization framework",
5
5
  "main": "./dist/cjs/i18next.js",
6
6
  "module": "./dist/esm/i18next.js",