UNPKG

3.16 kBTypeScriptView Raw
1/** @module data */
2/**
3 * An object that contains string translations for multiple languages.
4 * Language keys use two-letter codes like: 'en', 'sp', 'de', 'ru', 'fr', 'pr'.
5 * When translation for specified language does not exists it defaults to English ('en').
6 * When English does not exists it falls back to the first defined language.
7 *
8 * ### Example ###
9 *
10 * let values = MultiString.fromTuples(
11 * "en", "Hello World!",
12 * "ru", "Привет мир!"
13 * );
14 *
15 * let value1 = values.get('ru'); // Result: "Привет мир!"
16 * let value2 = values.get('pt'); // Result: "Hello World!"
17 */
18export declare class MultiString {
19 /**
20 * Creates a new MultiString object and initializes it with values.
21 *
22 * @param map a map with language-text pairs.
23 */
24 constructor(map?: any);
25 /**
26 * Gets a string translation by specified language.
27 * When language is not found it defaults to English ('en').
28 * When English is not found it takes the first value.
29 *
30 * @param language a language two-symbol code.
31 * @returns a translation for the specified language or default translation.
32 */
33 get(language: string): string;
34 /**
35 * Gets all languages stored in this MultiString object,
36 *
37 * @returns a list with language codes.
38 */
39 getLanguages(): string[];
40 /**
41 * Puts a new translation for the specified language.
42 *
43 * @param language a language two-symbol code.
44 * @param value a new translation for the specified language.
45 */
46 put(language: string, value: any): any;
47 /**
48 * Removes translation for the specified language.
49 *
50 * @param language a language two-symbol code.
51 */
52 remove(language: string): void;
53 /**
54 * Appends a map with language-translation pairs.
55 *
56 * @param map the map with language-translation pairs.
57 */
58 append(map: any): void;
59 /**
60 * Clears all translations from this MultiString object.
61 */
62 clear(): any;
63 /**
64 * Returns the number of translations stored in this MultiString object.
65 *
66 * @returns the number of translations.
67 */
68 length(): number;
69 /**
70 * Creates a new MultiString object from a value that contains language-translation pairs.
71 *
72 * @param value the value to initialize MultiString.
73 * @returns a MultiString object.
74 *
75 * @see [[StringValueMap]]
76 */
77 static fromValue(value: any): MultiString;
78 /**
79 * Creates a new MultiString object from language-translation pairs (tuples).
80 *
81 * @param tuples an array that contains language-translation tuples.
82 * @returns a MultiString Object.
83 *
84 * @see [[fromTuplesArray]]
85 */
86 static fromTuples(...tuples: any[]): MultiString;
87 /**
88 * Creates a new MultiString object from language-translation pairs (tuples) specified as array.
89 *
90 * @param tuples an array that contains language-translation tuples.
91 * @returns a MultiString Object.
92 */
93 static fromTuplesArray(tuples: any[]): MultiString;
94}