@magicdoor/magic-localization 0.1.0 → 0.2.0
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/README.md +3 -2
- package/dist/index.d.ts +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
createDictionary,
|
|
23
23
|
type DictionaryKey,
|
|
24
24
|
type DictionaryLanguage,
|
|
25
|
-
type
|
|
25
|
+
type TranslatableTextOf,
|
|
26
26
|
type Translator,
|
|
27
27
|
} from '@magicdoor/magic-localization';
|
|
28
28
|
|
|
@@ -50,6 +50,7 @@ export const dictionary = createDictionary({
|
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
export type Key = DictionaryKey<typeof dictionary>; // 'WELCOME' | 'LEASE_STATUS' | 'ACTIVE'
|
|
53
|
+
export type TranslatableText = TranslatableTextOf<Key>; // the one line that names your texts; declare with TranslatableText from here on
|
|
53
54
|
```
|
|
54
55
|
|
|
55
56
|
The library has no languages of its own. A dictionary's languages are exactly the keys of `translations`, coded
|
|
@@ -80,7 +81,7 @@ Code that decides what to say — a presenter, a view model — returns a `Trans
|
|
|
80
81
|
and only the UI translates it. A placeholder can be a text of its own, translated in the same language:
|
|
81
82
|
|
|
82
83
|
```ts
|
|
83
|
-
const label: TranslatableText
|
|
84
|
+
const label: TranslatableText = {
|
|
84
85
|
key: dictionary.keys.LEASE_STATUS,
|
|
85
86
|
params: { status: { key: dictionary.keys.ACTIVE } },
|
|
86
87
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* A key with the values its placeholders take, a value being a text of its own where it is a word too —
|
|
3
3
|
* or, with no key, a text shown as it is.
|
|
4
4
|
*/
|
|
5
|
-
type
|
|
5
|
+
type TranslatableTextOf<Key extends string> = {
|
|
6
6
|
readonly key: Key;
|
|
7
|
-
readonly params?: Readonly<Record<string, string | number |
|
|
7
|
+
readonly params?: Readonly<Record<string, string | number | TranslatableTextOf<Key>>>;
|
|
8
8
|
} | {
|
|
9
9
|
readonly params: {
|
|
10
10
|
readonly text: string;
|
|
@@ -40,7 +40,7 @@ type KeyOf<T extends Record<string, object>, Base extends keyof T> = Extract<key
|
|
|
40
40
|
type LanguageOf<T extends Record<string, object>> = Extract<keyof T, string>;
|
|
41
41
|
interface Translator<Key extends string> {
|
|
42
42
|
(key: Key, params?: Record<string, unknown>): string;
|
|
43
|
-
(text:
|
|
43
|
+
(text: TranslatableTextOf<Key>, params?: undefined): string;
|
|
44
44
|
}
|
|
45
45
|
/** The keys of a dictionary `createDictionary` made, named from its type: `DictionaryKey<typeof dictionary>`. */
|
|
46
46
|
type DictionaryKey<D extends {
|
|
@@ -58,9 +58,9 @@ declare function createDictionary<T extends Record<string, object>, Base extends
|
|
|
58
58
|
isLanguage: (code?: string) => code is LanguageOf<T>;
|
|
59
59
|
translate: {
|
|
60
60
|
(language: LanguageOf<T>, key: KeyOf<T, Base>, params?: Record<string, unknown>): string;
|
|
61
|
-
(language: LanguageOf<T>, text:
|
|
62
|
-
(language: LanguageOf<T>, keyOrText: KeyOf<T, Base> |
|
|
61
|
+
(language: LanguageOf<T>, text: TranslatableTextOf<KeyOf<T, Base>>): string;
|
|
62
|
+
(language: LanguageOf<T>, keyOrText: KeyOf<T, Base> | TranslatableTextOf<KeyOf<T, Base>>, params?: Record<string, unknown>): string;
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
export { type Dictionaries, type DictionaryKey, type DictionaryLanguage, type KeyOf, type LanguageOf, type LocalizationConfig, type
|
|
66
|
+
export { type Dictionaries, type DictionaryKey, type DictionaryLanguage, type KeyOf, type LanguageOf, type LocalizationConfig, type TranslatableTextOf, type Translator, createDictionary };
|