简体   繁体   English

我可以使用谷歌翻译在 Android 应用程序中启用多语言吗?

[英]Can I use Google Translator to enable multi language in Android app?

I'm working on an Android app.我正在开发一个 Android 应用程序。 I need to make it available in many languages.我需要提供多种语言版本。 Can we use Google Translate Plugin or translate API to get this work ?我们可以使用谷歌翻译插件或翻译 API 来完成这项工作吗?

Please check this link : https://www.w3schools.com/howto/tryit.asp?filename=tryhow_google_translate请检查此链接: https : //www.w3schools.com/howto/tryit.asp?filename=tryhow_google_translate

You can see there's a drop down to get all the language list.您可以看到有一个下拉菜单可以获取所有语言列表。 Can I use something like this in my Android app ?我可以在我的 Android 应用程序中使用这样的东西吗?

If I can't use a this method, what's the best way to enable multi-language feature in an Android app ?如果我不能使用这种方法,那么在 Android 应用程序中启用多语言功能的最佳方法是什么?

Every android app has a resource value "strings" (a list of values for string variables) to provide different languages.每个 android 应用程序都有一个资源值“字符串”(字符串变量的值列表)来提供不同的语言。

<resources>
<string name="home_act_bottom_bar_home_item">Shop</string>
<string name="home_act_bottom_bar_cont_item">Contacts</string>
<string name="home_act_bottom_bar_cart_item">Cart</string>
</resources>

The application must have a new string res file for each language.对于每种语言,应用程序都必须有一个新的字符串 res 文件。 When the application is launched, the OS detects current system language which was chosen by user in android settings and then try to find this language in res files.当应用程序启动时,操作系统会检测用户在 android 设置中选择的当前系统语言,然后尝试在 res 文件中找到该语言。 If the file we need exists (for example Russian) it will be used, if not - the system will start application with default strings res file(often English).如果我们需要的文件存在(例如俄语),它将被使用,否则 - 系统将使用默认字符串 res 文件(通常是英语)启动应用程序。 You certainly may use different web-services to translate you "Strings" after application was launched, but it will need time, will make user experience worth (user will have to wait for translation and UI update), will make your code very complex.你当然可以在应用程序启动后使用不同的网络服务来翻译你的“字符串”,但这需要时间,会让用户体验变得有价值(用户将不得不等待翻译和 UI 更新),会让你的代码非常复杂。 I suggest you to translate your App beforehand, and put translations to according string res files, it will make your app fast and code not so complex.我建议你事先翻译你的应用程序,并把翻译成相应的字符串 res 文件,它会让你的应用程序变得更快,代码也不那么复杂。

You can read official docs here: https://developer.android.com/training/basics/supporting-devices/languages您可以在此处阅读官方文档: https : //developer.android.com/training/basics/supporting-devices/languages

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM