首页 > 解决方案 > 在 android studio 中将所有文本视图翻译成其他语言

问题描述

我想通过从菜单中选择一种语言将我的 android 应用程序的所有文本视图翻译成其他语言。有什么翻译的方法吗?我听说我们可以使用微软文本翻译器进行翻译。但是不知道怎么用。请帮我。

标签: androidazuretextviewtranslation

解决方案


是的 !您可以使用 Azure 翻译器来实现您的目标。

高层工作如下:

在此处输入图像描述

Azure 翻译器支持 90 种语言和方言。你可以参考这个来访问语言列表。

https://docs.microsoft.com/en-us/azure/cognitive-services/translator/language-support

如何使用 :

第一步是获得订阅 - 如果您想先尝试,请使用以下链接:

https://azure.microsoft.com/en-in/free/cognitive-services/

第 1 步: 创建翻译资源:https ://ms.portal.azure.com/#create/Microsoft.CognitiveServicesTextTranslation 在此处输入图像描述

步骤 2 转到资源并获取 API 密钥。

第 3 步: 您必须使用以下指定的正文、标题来击中端点:

https://api.cognitive.microsofttranslator.com

网址参数:

/translate?api-version=3.0&from=<SourceLang>&to=<TranslationLang>

示例端点: 如果您要从英语翻译成德语:

https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=de&to=it

标题:

Ocp-Apim-Subscription-Key : <The Subscription Key you obtained>
Ocp-Apim-Subscription-Region : The Translator resource region which you would have provided while creating the resource.

身体 :

要翻译的文本应采用以下格式:

[{
    'text': 'Hello World!'
}]

回复 :

成功的响应如下所示:

[
    {
        "translations": [
            {
                "text": "Hallo Welt!",
                "to": "de"
            },
            {
                "text": "Salve, mondo!",
                "to": "it"
            }
        ]
    }
]

有关详细信息,请参阅此快速入门


推荐阅读