如何在不下载模型的情况下使用 Firebase ML 套件在线翻译文本?

How to Translate a text online Using Firebase ML kit without Downloading its Model?

我正在尝试使用 firebase ML 套件将文本翻译成目标语言,但它只能在已下载模型的语言之间进行翻译。即使没有下载模型我也想翻译

@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;
        }

ML Kit 的翻译 API 用于在设备上进行翻译,它需要下载语言包才能进行翻译。如果您想使用云 API 进行翻译,请查看 Google Cloud Translation