How to localize android system string resources?

2019-07-21 05:33发布

问题:

If I define my string resource in my strings.xml, I can localize my app by defining language specific strings.xml. But, When I use(for instance) the android system resource string "@android:string/no" for the word "Cancel",
how can I localize "Cancel" for different languages?

回答1:

Android handle localization of system keywords(cancel ok no) automatically if you refer to them using @android:string/.



回答2:

Created a strings.xml file for each language. Place them in that languages values folder see 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



回答3:

If you want you can declare a no string in string.xml and refer strings as @string/no. If you see http://developer.android.com/training/basics/supporting-devices/languages.html ,then you can define string.xml in different folders. Eg: values-fr for french and so on. So you can define the strings in different languages in these string.xml files and put them in appropriate folder. Android will pick up the work from relevant string.xml.

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