Skip to content

Commit c6862c4

Browse files
committed
Add MarkEdit.translationService for translation
1 parent 7674ad3 commit c6862c4

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Add `markedit-api` to your (TypeScript) project's devDependencies:
1919
```json
2020
{
2121
"devDependencies": {
22-
"markedit-api": "https://github.com/MarkEdit-app/MarkEdit-api#v0.16.0"
22+
"markedit-api": "https://github.com/MarkEdit-app/MarkEdit-api#v0.17.0"
2323
}
2424
}
2525
```
@@ -44,6 +44,8 @@ interface MarkEdit {
4444
editorAPI: TextEditable;
4545
// Retrieves a generative language model by name.
4646
languageModel(name: LanguageModelName): LanguageModel;
47+
// Retrieves the system translation service.
48+
translationService: TranslationService;
4749
// CodeMirror modules used by MarkEdit.
4850
codemirror: { view, state, language, langMarkdown, commands, search, autocomplete };
4951
// Lezer modules used by MarkEdit.

index.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export interface MarkEdit {
5555
*/
5656
languageModel(name: LanguageModelName): LanguageModel;
5757

58+
/**
59+
* Retrieves the system translation service.
60+
*/
61+
translationService: TranslationService;
62+
5863
/**
5964
* CodeMirror modules used by MarkEdit.
6065
*/
@@ -380,6 +385,22 @@ export type LanguageModelSampling =
380385
| { mode: 'greedy' }
381386
| { mode: 'top-k' | 'top-p'; value: number; seed?: number };
382387

388+
/**
389+
* The system translation service.
390+
*/
391+
export interface TranslationService {
392+
/**
393+
* Translate the text with language pair.
394+
*
395+
* Use BCP-47 language tags, such as `en-US`, `zh-CN`.
396+
*/
397+
translate(text: string, languages?: { from?: string; to?: string }): Promise<TranslationResponse>;
398+
}
399+
400+
export type TranslationResponse =
401+
| { succeeded: true; text: string }
402+
| { succeeded: false; error: string };
403+
383404
/**
384405
* Information of a file in the file system.
385406
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "markedit-api",
3-
"version": "0.16.0",
3+
"version": "0.17.0",
44
"description": "Type definitions for the latest MakrEdit API.",
55
"main": "./index.cjs",
66
"module": "./index.js",

0 commit comments

Comments
 (0)