-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathi18n.ts
More file actions
52 lines (47 loc) · 1.25 KB
/
i18n.ts
File metadata and controls
52 lines (47 loc) · 1.25 KB
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
import type { I18n } from '../../../../types/api';
import I18nInternal from '../../i18n';
import { logLabeled } from '../../utils';
import Module from '../../__module';
/**
* Provides methods for working with i18n
*/
export default class I18nAPI extends Module {
/**
* Return namespace section for tool or block tune
*
* @param toolName - tool name
* @param isTune - is tool a block tune
*/
private static getNamespace(toolName, isTune): string {
if (isTune) {
return `blockTunes.${toolName}`;
}
return `tools.${toolName}`;
}
/**
* Return I18n API methods with global dictionary access
*/
public get methods(): I18n {
return {
t: (): string | undefined => {
logLabeled('I18n.t() method can be accessed only from Tools', 'warn');
return undefined;
},
};
}
/**
* Return I18n API methods with tool namespaced dictionary
*
* @param toolName - tool name
* @param isTune - is tool a block tune
*/
public getMethodsForTool(toolName: string, isTune: boolean): I18n {
return Object.assign(
this.methods,
{
t: (dictKey: string): string => {
return I18nInternal.t(I18nAPI.getNamespace(toolName, isTune), dictKey);
},
});
}
}