多语言支持
2016-01-20 00:05
337 查看
Supporting Different Languages
上一课下一课This class teaches you to
Create Locale Directories and String FilesUse the String Resources
You should also read
Localization ChecklistLocalization with Resources
It’s always a good practice to extract UI strings from your app code and keep them in an external file. Android makes this easy with a resources directory in each Android project.
If you created your project using the Android SDK Tools (readCreating an Android Project), the tools create a
res/directory in the top level of the project. Within this
res/directory are subdirectories for various resource types. There are also a few default files such as
res/values/strings.xml, which holds your string values.
Create Locale Directories and String Files
To add support for more languages, create additionalvaluesdirectories inside
res/that include a hyphen and the ISO language code at the end of the directory name. For example,
values-es/is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time. For more information, see Providing Alternative Resources.
Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:
MyProject/ res/ values/ strings.xml values-es/ strings.xml values-fr/ strings.xml
Add the string values for each locale into the appropriate file.
At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user's device.
For example, the following are some different string resource files for different languages.
English (default locale),
/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="title">My Application</string> <string name="hello_world">Hello World!</string> </resources>
Spanish,
/values-es/strings.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="title">Mi Aplicación</string> <string name="hello_world">Hola Mundo!</string> </resources>
French,
/values-fr/strings.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="title">Mon Application</string> <string name="hello_world">Bonjour le monde !</string> </resources>
Note: You can use the locale qualifier (or any configuration qualifer) on any resource type, such as if you want to provide localized versions of your bitmap drawable. For more information, see Localization.
相关文章推荐
- AMD加载器实现笔记(二)
- Linux 上最好的五款音乐播放器
- 解决Jquery下拉框数据动态获取的问题
- shell循环
- 八大排序算法的Python实现
- 使用python实现省市三级菜单效果
- 以视频爬取实例讲解Python爬虫神器Beautiful Soup用法
- 编写Python爬虫抓取豆瓣电影TOP100及用户头像的方法
- Python使用Beautiful Soup包编写爬虫时的一些关键点
- Python的爬虫包Beautiful Soup中用正则表达式来搜索
- 实践Python的爬虫框架Scrapy来抓取豆瓣电影TOP250
- 深入剖析Python的爬虫框架Scrapy的结构与运作流程
- Python中urllib+urllib2+cookielib模块编写爬虫实战
- 使用Python编写爬虫的基本模块及框架使用指南
- Python的Scrapy爬虫框架简单学习笔记
- Python模拟百度登录实例详解
- Python中使用urllib2模块编写爬虫的简单上手示例
- CodeIgniter读写分离实现方法详解
- CodeIgniter视图使用注意事项
- CodeIgniter扩展核心类实例详解