0.0.5 • Published 10 months ago

comment-translate-manager v0.0.5

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

Used for translate source management. Multiple I translate objects are registered together, and the proxy API realizes the switching of different translation sources.

Installation

Koa requires higher for ES2020 and async function support.

$ npm install translate-manager

How to use it

let translateManager = new TranslateManager(context.workspaceState);
translateManager.onTranslate(e => {
    console.log(e);
});

Registry translate

Register translate source to manager.

export interface ITranslate {
    translate(content: string, options: ITranslateOptions): Promise<string>;
    link(content: string, options: ITranslateOptions): string;
    isSupported?: (src: string) => boolean;
    maxLen: number;
}

/**
 * @param key Registered key
 * @param translate Constructor of ITranslate
 */
translateManager.registry(key, translate);

Switch translate

Switch active translate source

if (translateManager.hasSource(key)) {
    return translateManager.setSource(key);
}

Use

Consistent with ITranslate

translateManager.translate(...);
translateManager.link(...);
translateManager.isSupport(...);
translateManager.maxLen;
0.0.5

10 months ago

0.0.4

12 months ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago