mirror of
https://github.com/codex-team/editor.js
synced 2024-05-06 08:33:20 +02:00
63eeec0f3b
Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com> Co-authored-by: Georgy Berezhnoy <gohabereg@gmail.com> Co-authored-by: tasuku-s <tasuku@freemind.co.jp> Co-authored-by: Athul Anil Kumar <athul7744@outlook.com> Co-authored-by: Taly <vitalik7tv@yandex.ru> Co-authored-by: flaming-cl <51183663+flaming-cl@users.noreply.github.com> Co-authored-by: Nguyen Ngoc Son <sonnn.se@gmail.com> Co-authored-by: Sisir Das K <37764463+sis-dk@users.noreply.github.com> Co-authored-by: Sisir <sisir@hellosivi.com>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import Module from '../../__module';
|
|
import { I18n } from '../../../../types/api';
|
|
import I18nInternal from '../../i18n';
|
|
import { ToolType } from '../tools';
|
|
import { logLabeled } from '../../utils';
|
|
|
|
/**
|
|
* Provides methods for working with i18n
|
|
*/
|
|
export default class I18nAPI extends Module {
|
|
/**
|
|
* Return namespace section for tool or block tune
|
|
*
|
|
* @param toolName - name of tool. Used to provide dictionary only for this tool
|
|
* @param toolType - 'block' for Block Tool, 'inline' for Inline Tool, 'tune' for Block Tunes
|
|
*/
|
|
private static getNamespace(toolName: string, toolType: ToolType): string {
|
|
switch (toolType) {
|
|
case ToolType.Block:
|
|
case ToolType.Inline:
|
|
return `tools.${toolName}`;
|
|
case ToolType.Tune:
|
|
return `blockTunes.${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 - name of tool. Used to provide dictionary only for this tool
|
|
* @param toolType - 'block' for Block Tool, 'inline' for Inline Tool, 'tune' for Block Tunes
|
|
*/
|
|
public getMethodsForTool(toolName: string, toolType: ToolType): I18n {
|
|
return Object.assign(
|
|
this.methods,
|
|
{
|
|
t: (dictKey: string): string => {
|
|
return I18nInternal.t(I18nAPI.getNamespace(toolName, toolType), dictKey);
|
|
},
|
|
});
|
|
}
|
|
}
|