Use of the <xliff: g> label in Android, androidxliff
When I read the source code today, some <string> tags in the resource file/res/values/strings. xml contain the <xliff: g> tag, for example:
<string name="running_process_item_user_label">User: <xliff:g id="user_name">%1$s</xliff:g></string>
This label has never been used before, so I checked it online. The full name of XLIFF is XML Localization Interchange File Format, and the Chinese name is XML localized data exchange Format.
<Xliff: g> label introduction:
The property id can be named at will.
Attribute example indicates an example, which can be omitted
% N $ ms: The output is a string, and n represents the first few parameters. The m value can be set with spaces before the output.
% N $ md: the output value is an integer. n indicates the number of parameters. You can set m to a space before the output, or set it to 0 m, put m 0 before output
% N $ mf: the output is a floating point number, and n represents the number of parameters. The value of m can control the number of decimal places. For example, when m = 2.2, the output format is 00.00.
Example:
<Resources xmlns: xliff = "urn: oasis: names: tc: xliff: document: 1.2"> <string name = "welcome"> welcome <xliff: g id = "name"> % 1 $ s </xliff: g>, ranking <xliff: g id = "num"> % 2 $ d </xliff: g> </string> </resources>
To use the <xliff: g> label, you must add a namespace to resources and then use
Public final String getString (int resId, Object... formatArgs)
String s = getString(R.string.welcome, "abc", 123);
Output result: Welcome to abc, ranking 123