Android资源字符串/res/values/string.xml中可以包含xliff的节点,Xliff是XML Localization Interchange File Format 的缩写,中文名为XML本地化数据交换格式。
quote from wikipedia (http://en.wikipedia.org/wiki/XLIFF) :
"XLIFF (XML Localisation Interchange File Format) is an XML-based format created to standardize localization. XLIFF was standardized by OASIS in 2002. Its current specification is v1.2[1] released on Feb-1-2008.
The specification is aimed at the localization industry. It specifies elements and attributes to aid in localization.
XLIFF forms part of the Open Architecture for XML Authoring and Localization (OAXAL) reference architecture."
<xliff:g>标签介绍:
属性id可以随便命名
属性值举例说明
%n$ms:代表输出的是字符串,n代表是第几个参数,设置m的值可以在输出之前放置空格
%n$md:代表输出的是整数,n代表是第几个参数,设置m的值可以在输出之前放置空格,也可以设为0m,在输出之前放置m个0
%n$mf:代表输出的是浮点数,n代表是第几个参数,设置m的值可以控制小数位数,如m=2.2时,输出格式为00.00
也可简单写成:
%d (表示整数)
%f (表示浮点数)
%s (表示字符串)
使用步骤举例:
1.
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
2.
<string name="test_xliff">小红今年<xliff:g id="xxx">%d</xliff:g>岁了,上<xliff:g id="yyy">%s</xliff:g>年级!</string>
3.
String test = String.format(getResources().getString(R.string.test_xliff), 7, "小学二");
输出:
小红今年7岁了,上小学二年级!