Reputation:
I'm trying to translate a text to a target language using firebase ML kit but it only translates in between languages whose model is downloaded. I wants to translate even if model is not downloaded
@Override
protected String doInBackground(String... params) {
try {
TranslatorOptions options = new TranslatorOptions.Builder()
.setSourceLanguage(languageCodes[sourcode])
.setTargetLanguage(languageCodes[destcode])
.build();
final Translator translator = Translation.getClient(options);
getLifecycle().addObserver(translator);
translator.translate(params[0])
.addOnSuccessListener(s -> TranslationFragment.this.requireActivity().runOnUiThread(() -> translationBinding.translatedText.setText(s))).addOnFailureListener(e -> TranslationFragment.this.requireActivity().runOnUiThread(() -> Toast.makeText(requireActivity(), "Translation Failed", Toast.LENGTH_SHORT).show()));
} catch (RuntimeException e) {
isTranslationsupported = false;
} finally {
progressDialog.dismiss();
}
return null;
}
Upvotes: 0
Views: 1156
Reputation: 534
ML Kit's Translation API is meant for doing translation on-device and it needs to download language packs to make that work. If you want to do translation using a cloud API, please check out Google Cloud Translation.
Upvotes: 1