博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android develop 国际化
阅读量:4307 次
发布时间:2019-06-06

本文共 3089 字,大约阅读时间需要 10 分钟。

转自别人的一片文章,出处以找不到了,觉得写得不错,记录一下

一、概念

  1.Internationalization(I18N)

    国际化

    使得App在不改的源码、资源文件的情况下,能够适应各国、各文化、各语言

    是L10N的基础

  2.Localization(L10N)

    本地化

    为App提供本地化的语言,图片,媒体资源等

二、Strings

  1.永远不要在任何地方Hard-code字符串

    layouts, xmls, menus, codes

    使用Lint查找所有hardcoded字符串

  2.永远不要拼接字符串

    错误的做法:

      <string name=“total”>共计</string>

      <string name=“apps”>个应用</string>

      String result = getString(R.string.total) + Integer.toString(appCount) + getString(R.string.apps)

    正确的做法:

      <string name=“total_apps”>共计%1$d个应用</string>

      String result = getString(R.string.total_apps, appCount)

三、Layouts

  1.Flexible layouts

    避免hard code margin, padding, width, height

    多使用minWidth, minHeight, maxWidth, maxHeight等属性

    需要定义精确尺寸的时候,请注意: 为外语留出足够的空间(例如中文长度*2,或者英文长度*1.5)

    为特定语言提供定制的Layouts

  2.RTL

    中东语言为主

    Android 4.2+支持 layoutDirection, textDirection, textAlignment, etc

    http://android-developers.blogspot.fr/2013/03/native-rtl-support-in-android-42.html

 

四、Plurals

  1.量词

    一个应用,两个应用,三个应用

    One app, two apps, three apps

    中文非常简单,但是其他语言可能有更多变化

    至少需要定义one, other, 但是也可以定义zero, two, few, many

  2.R.plurals

    使用专用的<plurals></plurals>在资源中定义

    http://developer.android.com/guide/topics/resources/string-resource.html#Plurals

五、Date, time, numbers, currencies

  1.利用现有API

    不要重复制造轮子

    不如Android系统对语言的支持广泛

  2.需要深入理解以下类:

    DateUtils, DateFormat, DecimalFormat

六、Resource Management

  1.为不同locale定义不同的resources

    values values-es values-jp values-zh-rCN values-zh-rTW

  2.资源匹配

    MCC, MNC, configuration(landscape, portrait), language, region

    Android会尝试按照精确度寻找匹配,如果无法找到匹配,则使用默认资源

    对于国际化产品,默认资源建议为英文,中文资源请放在-zh-rCN中

    默认资源必须为全集

  3.资源命名

    Module_Name

      其中Module为缩写,全部小写,不超过3个字符

      Name为具体资源的英文名称,首字母大写

  4.删除不需要的资源

    在多语言环境下,多出一个资源会导致apk文件体积大幅增加

    避免使用 Resources.getIdentifier(可能被compressed)

  5.禁止使用反射等方式获取资源id

  6.不要使用可被本地化的资源作为索引或进行持久化

    例如hashmap的key,或者使用button.text判断是否是特定button,这些资源可能会在运行时改变,导致程序工作异常

七、Help translators

  1.提供string的上下文信息

    <!-- The action for submitting a form. This text is on a button that can fit 30 chars -->

    <string name="login_submit_button">Sign in</string>

  2.标出无法翻译的部分

    <string name="countdown"><xliff:g id="time" example="5 days>%1$s</xliff:g>until holiday</string>

  3.在翻译团队提出问题时,请尽快给出反馈

八、Testing

  1.I18N testing

    提供中文与英文版本,测试人员测试不同环境下UI语言是否正确(hardcode) 未来可制作pseudo translation版本,测试I18N

    在运行时切换系统语言设定,App需要能够正确改变语言(configuration change)

  2.L10N testing

    众测机制(用户,当地运营团队,etc)

九、References

  1.Localizing with Resources

    http://developer.android.com/guide/topics/resources/localization.html

  2.Localization Checklist

    http://developer.android.com/distribute/tools/localization-checklist.html

  3.String resources

    http://developer.android.com/guide/topics/resources/string-resource.html

  4.RTL

    http://android-developers.blogspot.fr/2013/03/native-rtl-support-in-android-42.html

  5.Support Different Languages

    http://developer.android.com/training/basics/supporting-devices/languages.html

 

转载于:https://www.cnblogs.com/wanjintun/p/5003828.html

你可能感兴趣的文章
命令备忘 ss
查看>>
使用docker安装wazuh
查看>>
linux 常用性能优化
查看>>
安装wazuh-agent
查看>>
修改windows网络参数,让上网更快
查看>>
利用nc当作备用shell管理方案.
查看>>
备用shell管理方案之butterfly+nginx+https
查看>>
使用开源软件 jumpserver 搭造自己的堡垒机
查看>>
[报错解决] "MySQL server has gone away" 解决思路
查看>>
http状态码-备查
查看>>
iptables一些练习
查看>>
常用命令备忘 xargs
查看>>
关于nginx反代jenkins报错 反向代理设置有误
查看>>
关于Ubuntu中snap安装软件太慢解决办法
查看>>
esp8266 + dht11 + 两路继电器 实现pc远程控制开关机温度监控.并配置zabbix监控
查看>>
在linux中设置优先使用ipv4,而不是ipv6
查看>>
谷歌浏览器离线安装包下载
查看>>
正则表达式
查看>>
AWK命令使用
查看>>
Redis项目实战---应用及理论(三)---Jedis使用
查看>>