From ecb0bb22edc5ba0c74c8cd3430c32da8322e06a0 Mon Sep 17 00:00:00 2001 From: rigelglen Date: Fri, 27 Dec 2019 17:03:04 +0530 Subject: [PATCH] feat(cordova-plugin-mlkit-translate): Add plugin (#3261) --- .../plugins/mlkit-translate/index.ts | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/@ionic-native/plugins/mlkit-translate/index.ts diff --git a/src/@ionic-native/plugins/mlkit-translate/index.ts b/src/@ionic-native/plugins/mlkit-translate/index.ts new file mode 100644 index 00000000..43a2152c --- /dev/null +++ b/src/@ionic-native/plugins/mlkit-translate/index.ts @@ -0,0 +1,115 @@ +import { Injectable } from '@angular/core'; +import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core'; + +/** + * This is the language object which will be returned by `downloadModel`, `deleteModel`, `getAvailableModels` and `getDownloadedModels` methods. + */ +export interface LanguageModel { + /** + * BCP-47 language code of the language. For example: en + * For full list of languages codes, see https://firebase.google.com/docs/ml-kit/translation-language-support + */ + code: string; + + /** + * Display name of the language. For example: English + */ + displayName: string; +} + +/** + * @name MLKitTranslate + * @description + * Plugin that implements MLKit Translation and Language Identification features. + * + * @usage + * ```typescript + * import { MLKitTranslate } from '@ionic-native/ml-kit-translate'; + * + * + * constructor(private mlkitTranslate: MLKitTranslate) { } + * + * ... + * + * this.mlkitTranslate.translate('Hello', 'en', 'es') + * .then((resultText: string) => console.log(res)) + * .catch((error: string) => console.error(error)); + * + * @interfaces + * LanguageModel + * ``` + */ +@Plugin({ + pluginName: 'MLKitTranslate', + plugin: 'cordova-plugin-mlkit-translate', + pluginRef: 'MLKitTranslate', + repo: 'https://github.com/rigelglen/cordova-plugin-mlkit-translate', + platforms: ['Android', 'iOS'] +}) +@Injectable() +export class MLKitTranslate extends IonicNativePlugin { + /** + * Translates text from one language to another. Requires the source and target languages need to be downloaded. + * If not the languages are downloaded in the background automatically. + * @param text {string} text to be translated + * @param targetLanguage {string} BCP-47 language code of the language to translate to + * @param sourceLanguage {string=} (optional) BCP-47 language code of the language to translate to. If not provided, source language is inferred from text + * @return {Promise} Returns a promise that resolves with the translated text + */ + @Cordova() + translate( + text: string, + targetLanguage: string, + sourceLanguage?: string + ): Promise { + return; + } + + /** + * Determines the language of a string of text. + * @param text {string} text to be translated + * @return {Promise} Returns a promise that resolves with the identified language + */ + @Cordova() + identifyLanguage(text: string): Promise { + return; + } + + /** + * List of language models that have been downloaded to the device. + * @return {Promise} Returns a promise that resolves with an array of languages that have been downloaded. + */ + @Cordova() + getDownloadedModels(): Promise { + return; + } + + /** + * List of language models that can be downloaded. + * @return {Promise} Returns a promise that resolves with an array of possible languages that can be downloaded. + */ + @Cordova() + getAvailableModels(): Promise { + return; + } + + /** + * Downloads a specified language model. + * @param code {string} BCP-47 language code of the language to download + * @return {Promise} Returns a promise that resolves with the downloaded language. + */ + @Cordova() + downloadModel(code: string): Promise { + return; + } + + /** + * Deletes a specified language model. + * @param code {string} BCP-47 language code of the language to delete + * @return {Promise} Returns a promise that resolves with the deleted language. + */ + @Cordova() + deleteModel(code: string): Promise { + return; + } +}