简体   繁体   English

如何本地化android系统字符串资源?

[英]How to localize android system string resources?

If I define my string resource in my strings.xml, I can localize my app by defining language specific strings.xml. 如果在strings.xml中定义字符串资源,则可以通过定义特定于语言的strings.xml来本地化应用程序。 But, When I use(for instance) the android system resource string "@android:string/no" for the word "Cancel", 但是,当我使用(例如)单词“ Cancel”使用android系统资源字符串“ @android:string / no”时,
how can I localize "Cancel" for different languages? 如何为不同的语言本地化“取消”?

如果您使用@android:string/引用,系统会自动处理系统关键字的本地化(取消确定)。

If you want you can declare a no string in string.xml and refer strings as @string/no . 如果需要,可以在string.xml声明一个no字符串,并将字符串引用为@string/no If you see http://developer.android.com/training/basics/supporting-devices/languages.html ,then you can define string.xml in different folders. 如果看到http://developer.android.com/training/basics/supporting-devices/languages.html ,则可以在其他文件夹中定义string.xml Eg: values-fr for french and so on. 例如: values-fr用于法语,依此类推。 So you can define the strings in different languages in these string.xml files and put them in appropriate folder. 因此,您可以在这些string.xml文件中以不同的语言定义字符串,并将它们放在适当的文件夹中。 Android will pick up the work from relevant string.xml . Android将从相关的string.xml工作。

YourProject/
    res/
       values/
           strings.xml
       values-es/
           strings.xml
       values-fr/
           strings.xml

Created a strings.xml file for each language. 为每种语言创建一个strings.xml文件。 Place them in that languages values folder see http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources 将它们放在该语言值文件夹中,请参见http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

And then within your strings.xml files make sure they all have a string with the name no 然后在您的strings.xml文件中,确保它们都有一个名称为no的字符串。

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

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