-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathi18n.ts
37 lines (34 loc) · 819 Bytes
/
i18n.ts
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
import browser from 'webextension-polyfill';
import i18nEnMessages from '../public/_locales/en/messages.json';
type Keys<T> = {
[K in keyof T]: (...rest: string[]) => string;
};
/**
* @example
* ```ts
* const extensionName = i18n.extensionName()
* ```
*/
export const i18n = Object.keys(i18nEnMessages).reduce(
(p, c: keyof typeof i18nEnMessages) => {
p[c] = (...rest) => browser.i18n.getMessage(c, ...rest);
return p;
},
{} as Keys<typeof i18nEnMessages>,
);
type KeysMap<T> = {
[K in keyof T]: string;
};
/**
* @example
* ```ts
* const extensionName = i18nMap.extensionName
* ```
*/
export const i18nMap = Object.keys(i18nEnMessages).reduce(
(p, c: keyof typeof i18nEnMessages) => {
p[c] = browser.i18n.getMessage(c);
return p;
},
{} as KeysMap<typeof i18nEnMessages>,
);