Appery Translation
Translate text
Translator.translate
Parameters
- {string} text - text to be translated
- {string} targetLanguage - language code of the language to translate to
- {string} sourceLanguage - language code of the language to translate from
- {function} success - callback function which takes a parameter data which will be invoked on success
- {function} error - callback function which takes a parameter err which will be invoked on failure
Important notice:
Target Language and Source Language translate models should be downloaded before calling translate.
Check it with Translator.getDownloadedModels and then call Translator.downloadModel if desired model is missing (see below)
Supported languages and their codes can be retrieved via Translator.getSupportedLanguages
Example
window.ApperyioMLCordovaPlugin.Translator.translate("Translate this string from Spanish to English", "es", "en", successCallback, errorCallback)
Sample JSON callback: translation.json
Get downloaded offline translate models
Translator.getDownloadedModels
List of language models that have been downloaded to the device.
Parameters
- {function} success - callback function which takes a parameter data which will be invoked on success
- {function} error - callback function which takes a parameter err which will be invoked on failure
Example
window.ApperyioMLCordovaPlugin.Translator.getDownloadedModels(successCallback, errorCallback)
Sample JSON callback: downloaded_translate_models.json
Download / Delete offline translate models
Translator.downloadModel
Translator.deleteModel
List of language models that have been downloaded to the device.
Important notice:
Make sure that network is available first.
Language models are around 30MB, so don't download them unnecessarily, and only download them using WiFi, unless the user has specified otherwise.
Parameters
- {string} code - language code of the language model
- {function} success - callback function which takes a parameter data which will be invoked on success
- {function} error - callback function which takes a parameter err which will be invoked on failure
Example
window.ApperyioMLCordovaPlugin.Translator.Translator.deleteModel("es", successCallback, errorCallback)
window.ApperyioMLCordovaPlugin.Translator.Translator.downloadModel("es", successCallback, errorCallback)
Sample JSON callback: download_delete_translate_model.json
Updated 4 months ago