-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "LiberTranslate" provider (#140)
- Add "LiberTranslate" provider - Bump dependencies to the latest version
- Loading branch information
Showing
6 changed files
with
143 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ProviderBase from './ProviderBase' | ||
|
||
/* eslint-disable camelcase */ | ||
type LibreTranslateResponse = { translatedText: string } | ||
|
||
export default class LibreTranslateProvider extends ProviderBase { | ||
private apiKey: string | ||
|
||
constructor(apiKey: string) { | ||
super('https://libretranslate.com/translate') | ||
this.apiKey = apiKey | ||
} | ||
|
||
translate(text: string, lang: string): Promise<string[]> { | ||
const [source, target] = lang.split('-', 2) | ||
const data = { | ||
q: text, | ||
source, | ||
target, | ||
format: 'text', | ||
api_key: this.apiKey | ||
} | ||
return this.api<LibreTranslateResponse>({ data, url: '/', method: 'POST' }) | ||
.then(({ translatedText }) => [translatedText]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters