react-localization 2.0.4 → 2.0.6

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,62 @@
1
+ declare module 'react-localization' {
2
+ import react from "react";
3
+ type Formatted = number | string | react.JSX.Element;
4
+ type FormatObject<U extends Formatted> = {
5
+ [key: string]: U;
6
+ };
7
+ export interface GlobalStrings<T> {
8
+ [language: string]: T;
9
+ }
10
+ export interface LocalizedStringsMethods {
11
+ /**
12
+ * Can be used from ouside the class to force a particular language
13
+ * independently from the interface one
14
+ * @param language
15
+ */
16
+ setLanguage(language: string): void;
17
+ /**
18
+ * The current language displayed (could differ from the interface language
19
+ * if it has been forced manually and a matching translation has been found)
20
+ */
21
+ getLanguage(): string;
22
+ /**
23
+ * The current interface language (could differ from the language displayed)
24
+ */
25
+ getInterfaceLanguage(): string;
26
+ /**
27
+ * Format the passed string replacing the numbered placeholders
28
+ * i.e. I'd like some {0} and {1}, or just {0}
29
+ * Use example:
30
+ * strings.formatString(strings.question, strings.bread, strings.butter)
31
+ */
32
+ formatString<T extends Formatted>(str: string, ...values: Array<T | FormatObject<T>>): Array<string | T> | string;
33
+ /**
34
+ * Return an array containing the available languages passed as props in the constructor
35
+ */
36
+ getAvailableLanguages(): string[];
37
+ /**
38
+ * Return a string with the passed key in a different language
39
+ * @param key
40
+ * @param language
41
+ */
42
+ getString(key: string, language?: string, omitWarning?: boolean): string;
43
+ /**
44
+ * Replace the NamedLocalization object without reinstantiating the object
45
+ * @param props
46
+ */
47
+ setContent(props: any): void;
48
+ }
49
+ export type LocalizedStrings<T> = LocalizedStringsMethods & T;
50
+ type GetInterfaceLanguageCallback = () => string;
51
+ interface Options {
52
+ customLanguageInterface?: GetInterfaceLanguageCallback;
53
+ logsEnabled?: boolean;
54
+ pseudo?: boolean;
55
+ pseudoMultipleLanguages?: boolean;
56
+ }
57
+ interface LocalizedStringsFactory {
58
+ new <T>(props: GlobalStrings<T>, options?: Options): LocalizedStrings<T>;
59
+ }
60
+ var LocalizedStrings: LocalizedStringsFactory;
61
+ export default LocalizedStrings;
62
+ }
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "react-localization",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Simple module to localize the React interface using the same syntax used in the ReactNativeLocalization module",
5
5
  "type": "module",
6
6
  "main": "./lib/react-localization.umd.js",
7
7
  "module": "./lib/react-localization.es.js",
8
- "types": "./lib/LocalizedStrings.d.ts",
8
+ "types": "./lib/react-localization.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
+ "require": "./lib/react-localization.es.js",
12
+ "types": "./lib/react-localization.d.ts",
11
13
  "import": "./lib/react-localization.es.js"
12
14
  }
13
15
  },