android开发 多语言和国际化(转)
我们建好一个android 的项目后,默认的res下面 有layout、values、drawable等目录
这些都是程序默认的资源文件目录,如果要实现多语言版本的话,我们就要添加要实现语言的对应的资源文件。
首先我们点击添加Android Xml File按钮,会出现下面的界面:
输入文件名:string.xml,选中Values单选框,并把下面左列表中的Region添加到左边的列表里面,并在Region输入框里输入cn,如下图
这时,上面的消息提示:如果用Region的话,需要使用语言项,和Region一样,我们把Language也添加到右面的列表里面,填入zh,如下图
点击Finish按钮,资源文件就会建好了,目录:res\values-zh-rCN(其实上面一大堆操作,就是为生成这个目录)
默认生成的string.xml的代码:
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"><?</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">xml</span> <span class="attr" style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);">version</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">="1.0"</span> <span class="attr" style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);">encoding</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">="utf-8"</span>?<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"><</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">resources</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"><</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">string</span> <span class="attr" style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);">name</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">="hello"</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>Hello World, Test!<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"></</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">string</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"><</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">string</span> <span class="attr" style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);">name</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">="app_name"</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>Test-Multilingual<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"></</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">string</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"></</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">resources</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
修改刚刚生成的res\values-zh-rCN目录下的string.xml:
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"><?</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">xml</span> <span class="attr" style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);">version</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">="1.0"</span> <span class="attr" style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);">encoding</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">="utf-8"</span>?<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"><</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">resources</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"><</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">string</span> <span class="attr" style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);">name</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">="app_name"</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>测试多语言<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"></</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">string</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"><</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">string</span> <span class="attr" style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);">name</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">="hello"</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>你好 多语言测试<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"></</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">string</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
<span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);"></</span><span class="html" style="margin: 0px; padding: 0px; color: rgb(128, 0, 0);">resources</span><span class="kwrd" style="margin: 0px; padding: 0px; color: rgb(0, 0, 255);">></span>
运行结果:
en-us:英文
zh-cn:中国大陆
zh-tw:台湾
因为设置了region为CN,所以zh-tw的时候,没有找到res\values-zh-rTW的目录,加载了默认的res\values目录下的string.xml
这里只用了Values做例子,其余的Resource都可以,图片了,布局了等等
(出处和作者:www.cnblogs.com/wuyunan Ready Wu)
附1:
在代码中切换语言:
- Resources resources = getResources();//获得res资源对象
- Configuration config = resources.getConfiguration();//获得设置对象
- DisplayMetrics dm = resources .getDisplayMetrics();//获得屏幕参数:主要是分辨率,像素等。
- config.locale = Locale.SIMPLIFIED_CHINESE; //简体中文
- resources.updateConfiguration(config, dm);
附2:
国家代号与区号
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
附3:
各国语言缩写
en_US 英文 (美国)
ar 阿拉伯文
ar_AE 阿拉伯文 (阿拉伯联合酋长国)
ar_BH 阿拉伯文 (巴林)
ar_DZ 阿拉伯文 (阿尔及利亚)
ar_EG 阿拉伯文 (埃及)
ar_IQ 阿拉伯文 (伊拉克)
ar_JO 阿拉伯文 (约旦)
ar_KW 阿拉伯文 (科威特)
ar_LB 阿拉伯文 (黎巴嫩)
ar_LY 阿拉伯文 (利比亚)
ar_MA 阿拉伯文 (摩洛哥)
ar_OM 阿拉伯文 (阿曼)
ar_QA 阿拉伯文 (卡塔尔)
ar_SA 阿拉伯文 (沙特阿拉伯)
ar_SD 阿拉伯文 (苏丹)
ar_SY 阿拉伯文 (叙利亚)
ar_TN 阿拉伯文 (突尼斯)
ar_YE 阿拉伯文 (也门)
be 白俄罗斯文
be_BY 白俄罗斯文 (白俄罗斯)
bg 保加利亚文
bg_BG 保加利亚文 (保加利亚)
ca 加泰罗尼亚文
ca_ES 加泰罗尼亚文 (西班牙)
ca_ES_EURO 加泰罗尼亚文 (西班牙,Euro)
cs 捷克文
cs_CZ 捷克文 (捷克共和国)
da 丹麦文
da_DK 丹麦文 (丹麦)
de 德文
de_AT 德文 (奥地利)
de_AT_EURO 德文 (奥地利,Euro)
de_CH 德文 (瑞士)
de_DE 德文 (德国)
de_DE_EURO 德文 (德国,Euro)
de_LU 德文 (卢森堡)
de_LU_EURO 德文 (卢森堡,Euro)
el 希腊文
el_GR 希腊文 (希腊)
en_AU 英文 (澳大利亚)
en_CA 英文 (加拿大)
en_GB 英文 (英国)
en_IE 英文 (爱尔兰)
en_IE_EURO 英文 (爱尔兰,Euro)
en_NZ 英文 (新西兰)
en_ZA 英文 (南非)
es 西班牙文
es_BO 西班牙文 (玻利维亚)
es_AR 西班牙文 (阿根廷)
es_CL 西班牙文 (智利)
es_CO 西班牙文 (哥伦比亚)
es_CR 西班牙文 (哥斯达黎加)
es_DO 西班牙文 (多米尼加共和国)
es_EC 西班牙文 (厄瓜多尔)
es_ES 西班牙文 (西班牙)
es_ES_EURO 西班牙文 (西班牙,Euro)
es_GT 西班牙文 (危地马拉)
es_HN 西班牙文 (洪都拉斯)
es_MX 西班牙文 (墨西哥)
es_NI 西班牙文 (尼加拉瓜)
et 爱沙尼亚文
es_PA 西班牙文 (巴拿马)
es_PE 西班牙文 (秘鲁)
es_PR 西班牙文 (波多黎哥)
es_PY 西班牙文 (巴拉圭)
es_SV 西班牙文 (萨尔瓦多)
es_UY 西班牙文 (乌拉圭)
es_VE 西班牙文 (委内瑞拉)
et_EE 爱沙尼亚文 (爱沙尼亚)
fi 芬兰文
fi_FI 芬兰文 (芬兰)
fi_FI_EURO 芬兰文 (芬兰,Euro)
fr 法文
fr_BE 法文 (比利时)
fr_BE_EURO 法文 (比利时,Euro)
fr_CA 法文 (加拿大)
fr_CH 法文 (瑞士)
fr_FR 法文 (法国)
fr_FR_EURO 法文 (法国,Euro)
fr_LU 法文 (卢森堡)
fr_LU_EURO 法文 (卢森堡,Euro)
hr 克罗地亚文
hr_HR 克罗地亚文 (克罗地亚)
hu 匈牙利文
hu_HU 匈牙利文 (匈牙利)
is 冰岛文
is_IS 冰岛文 (冰岛)
it 意大利文
it_CH 意大利文 (瑞士)
it_IT 意大利文 (意大利)
it_IT_EURO 意大利文 (意大利,Euro)
iw 希伯来文
iw_IL 希伯来文 (以色列)
ja 日文
ja_JP 日文 (日本)
ko 朝鲜文
ko_KR 朝鲜文 (南朝鲜)
lt 立陶宛文
lt_LT 立陶宛文 (立陶宛)
lv 拉托维亚文(列托)
lv_LV 拉托维亚文(列托) (拉脱维亚)
mk 马其顿文
mk_MK 马其顿文 (马其顿王国)
nl 荷兰文
nl_BE 荷兰文 (比利时)
nl_BE_EURO 荷兰文 (比利时,Euro)
nl_NL 荷兰文 (荷兰)
nl_NL_EURO 荷兰文 (荷兰,Euro)
no 挪威文
no_NO 挪威文 (挪威)
no_NO_NY 挪威文 (挪威,Nynorsk)
pl 波兰文
pl_PL 波兰文 (波兰)
pt 葡萄牙文
pt_BR 葡萄牙文 (巴西)
pt_PT 葡萄牙文 (葡萄牙)
pt_PT_EURO 葡萄牙文 (葡萄牙,Euro)
ro 罗马尼亚文
ro_RO 罗马尼亚文 (罗马尼亚)
ru 俄文
ru_RU 俄文 (俄罗斯)
sh 塞波尼斯-克罗地亚文
sh_YU 塞波尼斯-克罗地亚文 (南斯拉夫)
sk 斯洛伐克文
sk_SK 斯洛伐克文 (斯洛伐克)
sl 斯洛文尼亚文
sl_SI 斯洛文尼亚文 (斯洛文尼亚)
sq 阿尔巴尼亚文
sq_AL 阿尔巴尼亚文 (阿尔巴尼亚)
sr 塞尔维亚文
sr_YU 塞尔维亚文 (南斯拉夫)
sv 瑞典文
sv_SE 瑞典文 (瑞典)
th 泰文
th_TH 泰文 (泰国)
tr 土耳其文
tr_TR 土耳其文 (土耳其)
uk 乌克兰文
uk_UA 乌克兰文 (乌克兰)
zh 中文
zh_CN 中文 (中国)
zh_HK 中文 (香港)
zh_TW 中文 (台湾)
android开发 多语言和国际化(转)相关推荐
- Android开发——Kotlin语言
语法 变量 类型转换 "不安全的"转换操作符 "安全的"转换操作符 函数 一行代码的情况 运算符 位运算符 程序控制语句 选择结构 循环结构 类和对象 继承与构 ...
- Kotlin成为Android开发首选语言——你绝对不能错过的
继Java 和 C++ 之后,Google 在 I/O 2017 上宣布 Android 加入了对 Kotlin 编程语言的支持. 将Kotlin语言作为安卓开发的一级编程语言.Kotlin由JetB ...
- go语言ios android开发,Go 语言编写移动端 Android 和 iOS SDK
这篇文章不涉及 Go 编译原生 Android 和 iOS 应用,只讲述如何使用 Go 语言编译生成 Android 和 iOS SDK 库文件,并使用 Java (Android) 和 Object ...
- vue中开发多语言(国际化),vue+i18n(详细教程)
目录 第一步: 第二步: 第三步: 第四步: 最后: 前言:我们有时候会遇到一个项目需要支持多语言,而用直接翻译的插件时常会导致翻译的结果跟自己预想的有所偏差或者结果太长造成页面结构紊乱而这个时候就需 ...
- 安卓航班Android开发经典教程大总结1----基础编程及源码推送
上篇主要讲述了社区的总体规划以及总结此次教程的目的,接下来开始正式总结android开发相关知识,从最简单的环境搭建到正式项目的制作,当然教程是总结来的,同时再次声明资料很多来自互联网,如有侵权请联系 ...
- Android开发从入门到精通教程大总结(源码,教程,面试题,书籍,视频)
老罗: http://blog.csdn.net/column/details/androidluo.html http://xiaozu.renren.com/xiaozu/100692/3569 ...
- Android多国语言翻译 字符串目录详解
Android多国语言翻译 国际化 命名规则 values-[ 语言简称]-r[地区] 常用语言 values #默认语言 找不到对应语言就会使用这里 values-ar # 拉伯语 Arabic v ...
- Android逆向 学习Android安全和逆向开发的路线总结,android开发平台的发展
学习Android逆向之前,必备条件.[必备,出去面试正经公司的安全岗位都会问的基础问题] 从事3-5年真实的Android开发工作,熟练使用C/C++,Java,kotlin,dart等Androi ...
- 学android开发,入门语言JAVA知识点
Android是一种以Linux为基础的开源码操作系统,主要使用于便携设备,而linux是用c语言和少量汇编语言写成的,如果你想研究Android,就去学java语言吧. Android开发入门教程 ...
- Android开发笔记(八十三)多语言支持
汉字转拼音 app中有许多场景要对汉字排序,例如通讯录姓名.商品名称.城市名称等等,这些汉字词汇通常是按照拼音排序,所以产生了把汉字转换为拼音的需求. Android自带库 Android自带的联系人 ...
最新文章
- 前端一HTML:十四: important
- linux 可执行文件与写操作的同步问题
- mysql分片建表语句_Mysql元数据如何生成Hive建表语句注释脚本详解
- LeetCode 785. 判断二分图(染色法)
- 界面发布2019中国最富1000人榜:凛冬望春,马云问鼎中国首富
- Mybatis01(结果集封装)
- python读取xml文件内容显示不全_python读取xml文件时的问题
- ADT版本不同导致的一个问题
- WINCE 中常见的问题收集
- PhoenixFramework自动化测试平台部署初始化说明
- 复合隐写/图片混合/图片格式头修改-西伯利亚大尾巴狼
- 怎么关闭win10虚拟机服务器,大神为你win10系统彻底关闭退出vmware虚拟机的方案...
- 看板的作用是什么?任务看板如何跟进
- 利用poi 1.6 通过模板导出复杂 Word表格,包含合单元格后垂直居中、循环生成行等
- greenplum(gp)的常用命令
- cin.tie(0)和ios::sync_with_stdio(false)
- 假如泰坦尼克号是艘中国游轮
- zzuliloj 1037: 四则运算
- 计算机启动时运行ccleaner,CCleaner中设置表详解
- HTML5 拖放(Drag 和 Drop)简介
热门文章
- 推荐 7 个 Python 入门视频教程
- 如何将十进制转化为二进制和十六进制
- java怎么实现事务_java实现简单的事务
- 小程序后台PHP版本部署运行 LNMP+WNMP
- CSS特效(一):制作盒子荧光特效
- vue项目的停止_Terminal怎么停止VUE项目
- BSD许可协议具体限制了什么?
- 游戏测试和软件测试有什么区别?
- 椭圆曲线的加密算法解析和程序设计—基于python语言
- java.exe 0xc000012d_应用程序无法正常启动0xc000012d,此情况要怎么解决,望大神交一交...