Android Studio错误消息I18n [英] Android Studio error message I18n
问题描述
我收到一条错误消息,内容为:
I got an error message that says:
[I18N]硬编码的字符串今天-晴天-78/67",应使用@string资源.
[I18N] Hardcoded string "Today - Sunny - 78/67", should use @string resource.
如何解决此错误?
代码行是: android:text =今天-Sunny-78/67"
推荐答案
i18n是国际化的缩写.Android Studio只是给您一个提示,即您设置文本的方式将不允许您轻松地翻译文本.
i18n is an abbreviation for internationalization. Android Studio is just giving you a hint that the way you are setting the text won't allow you to easily translate it.
相反,您应该将字符串放在res/values文件夹内的strings.xml文件中:
Instead you should put your string in a strings.xml file within the res/values folder:
<resources>
<string name="my_string">Today - Sunny - 78/67</string>
</resources>
然后您像这样在TextView上引用该字符串:
You then reference that string on your TextView like this:
android:text="@string/my_string"
这将使您可以为西班牙字符串(res/values-es/strings.xml)创建另一个文件,您可以在其中添加翻译:
This would allow you to make another file for spanish strings, res/values-es/strings.xml that you could add a translation to:
<resources>
<string name="my_string">Hoy - Soleado - 78/67</string>
</resources>
然后,如果用户的语言环境为西班牙语,则将自动为您的TextView选择该字符串.
And then that string will automatically get picked for your TextView if the user's locale language is Spanish.
这篇关于Android Studio错误消息I18n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!