mirror of
https://github.com/codex-team/editor.js
synced 2024-05-07 08:56:48 +02:00
2d89105670
* Add internal wrappers for tools classes * FIx lint * Change tools collections to map * Apply some more refactoring * Make tool instance private field * Add some docs * Fix eslint * Basic implementation for Block Tunes * Small fix for demo * Review changes * Fix * Add common tunes and ToolsCollection class * Fixes after review * Rename tools collections * Readonly fix * Some fixes after review * Apply suggestions from code review Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Fixes after review * Add docs and changelog * Update docs/block-tunes.md Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Apply suggestions from code review Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update src/components/block/index.ts Co-authored-by: Murod Khaydarov <murod.haydarov@gmail.com> * [Dev] Tools utils tests (#1602) * Add tests for tools utils and coverage report * Fix eslint * Adjust test * Add more tests * Update after code review * Fix test & bump version Co-authored-by: Peter Savchenko <specc.dev@gmail.com> Co-authored-by: Murod Khaydarov <murod.haydarov@gmail.com>
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { I18n } from '../../../../types/api';
|
|
import I18nInternal from '../../i18n';
|
|
import { logLabeled } from '../../utils';
|
|
import Module from '../../__module';
|
|
import { ToolClass } from '../../tools/collection';
|
|
|
|
/**
|
|
* Provides methods for working with i18n
|
|
*/
|
|
export default class I18nAPI extends Module {
|
|
/**
|
|
* Return namespace section for tool or block tune
|
|
*
|
|
* @param tool - tool object
|
|
*/
|
|
private static getNamespace(tool: ToolClass): string {
|
|
if (tool.isTune) {
|
|
return `blockTunes.${tool.name}`;
|
|
}
|
|
|
|
return `tools.${tool.name}`;
|
|
}
|
|
|
|
/**
|
|
* 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 tool - Tool object
|
|
*/
|
|
public getMethodsForTool(tool: ToolClass): I18n {
|
|
return Object.assign(
|
|
this.methods,
|
|
{
|
|
t: (dictKey: string): string => {
|
|
return I18nInternal.t(I18nAPI.getNamespace(tool), dictKey);
|
|
},
|
|
});
|
|
}
|
|
}
|