com.google.mlkit.nl.translate.Translation.getClient Image Screenshot
在上图中,我已经导入了getClient(),但它仍然显示我要导入
答案 0 :(得分:0)
我也遇到了这个问题,暂时可以使用Firebase Natural Language库。 Document Here,
首先在您的grandle文件中插入--
implementation 'com.google.firebase:firebase-ml-natural-language:22.0.0'
implementation 'com.google.firebase:firebase-ml-natural-language-translate-model:20.0.8'
对于翻译模型-
val options = FirebaseTranslatorOptions.Builder()
.setSourceLanguage(FirebaseTranslateLanguage.DE)
.setTargetLanguage(FirebaseTranslateLanguage.TR)
.build()
val englishGermanTranslator = FirebaseNaturalLanguage.getInstance().getTranslator(options)
englishGermanTranslator.downloadModelIfNeeded()
.addOnSuccessListener {
// Model downloaded successfully. Okay to start translating.
// (Set a flag, unhide the translation UI, etc.)
}
.addOnFailureListener { exception ->
// Model couldn’t be downloaded or other internal error.
// ...
}
englishGermanTranslator.translate(text)
.addOnSuccessListener { translatedText ->
Log.d("translate","done \t $translatedText")
}
.addOnFailureListener { exception ->
// Error.
// ...
}
希望对您有帮助