https://github.com/rmraya/mtengines
TypeScript library for retrieving Machine Translation (MT) from different engines
https://github.com/rmraya/mtengines
machine-translation typescript
Last synced: over 1 year ago
JSON representation
TypeScript library for retrieving Machine Translation (MT) from different engines
- Host: GitHub
- URL: https://github.com/rmraya/mtengines
- Owner: rmraya
- License: epl-1.0
- Created: 2023-06-26T11:13:26.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-13T20:09:21.000Z (over 1 year ago)
- Last Synced: 2025-03-13T21:25:39.618Z (over 1 year ago)
- Topics: machine-translation, typescript
- Language: TypeScript
- Homepage:
- Size: 78.1 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MTEngines
TypeScript library for Machine Translation (MT) engines.
Interface `MTEngine` provides these methods:
```typescript
getName(): string;
getShortName(): string;
getSourceLanguages(): Promise;
getTargetLanguages(): Promise;
setSourceLanguage(lang: string): void;
getSourceLanguage(): string;
setTargetLanguage(lang: string): void;
getTargetLanguage(): string;
translate(source: string): Promise;
getMTMatch(source: string): Promise;
handlesTags(): boolean;
fixesMatches(): boolean;
fixMatch?(originalSource: XMLElement, matchSource: XMLElement, matchTarget: XMLElement): Promise;
```
All supported engines implement this interface. The `fixMatch()` method is optional and only implemented by `ChatGPTTranslator`.
```typescript
getSource(): string;
getTarget(): string;
getConfidence(): number;
getSourceLanguage(): string;
getTargetLanguage(): string;
getSourceXMLElement(): XMLElement;
getTargetXMLElement(): XMLElement;
```
## Supported Engines
- DeepL (Free and Pro)
- Google Cloud Translation
- Microsoft Azure Translator Text
- ModernMT
- OpenAI ChatGPT
- Yandex Translate API
## Installation
```bash
npm install mtengines
```
## Example
```typescript
import { GoogleTranslator } from "mtengines";
class TestGoogle {
constructor() {
let translator: GoogleTranslator = new GoogleTranslator('yourApiKey');
translator.setSourceLanguage("en");
translator.setTargetLanguage("ja");
translator.translate("Hello World").then((result:string) => {
console.log(result);
}, (error:any) => {
console.error(error);
});
}
}
new TestGoogle();
```