-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathreact-localization.tsx
72 lines (60 loc) · 2.35 KB
/
react-localization.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
declare module 'react-localization' {
import react from "react";
type Formatted = number | string | react.JSX.Element;
type FormatObject<U extends Formatted> = { [key: string]: U };
export interface GlobalStrings<T> {
[language: string]: T;
}
export interface LocalizedStringsMethods {
/**
* Can be used from ouside the class to force a particular language
* independently from the interface one
* @param language
*/
setLanguage(language: string): void;
/**
* The current language displayed (could differ from the interface language
* if it has been forced manually and a matching translation has been found)
*/
getLanguage(): string;
/**
* The current interface language (could differ from the language displayed)
*/
getInterfaceLanguage(): string;
/**
* Format the passed string replacing the numbered placeholders
* i.e. I'd like some {0} and {1}, or just {0}
* Use example:
* strings.formatString(strings.question, strings.bread, strings.butter)
*/
formatString<T extends Formatted>(str: string, ...values: Array<T | FormatObject<T>>): Array<string | T> | string;
/**
* Return an array containing the available languages passed as props in the constructor
*/
getAvailableLanguages(): string[];
/**
* Return a string with the passed key in a different language
* @param key
* @param language
*/
getString(key: string, language?: string, omitWarning?: boolean): string;
/**
* Replace the NamedLocalization object without reinstantiating the object
* @param props
*/
setContent(props: any): void;
}
export type LocalizedStrings<T> = LocalizedStringsMethods & T;
type GetInterfaceLanguageCallback = () => string;
interface Options {
customLanguageInterface?: GetInterfaceLanguageCallback;
logsEnabled?: boolean;
pseudo?: boolean;
pseudoMultipleLanguages?: boolean;
}
interface LocalizedStringsFactory {
new <T>(props: GlobalStrings<T>, options?: Options): LocalizedStrings<T>;
}
var LocalizedStrings: LocalizedStringsFactory;
export default LocalizedStrings;
}