Use of the & lt; xliff: g & gt; tag in Android, androidxliff

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.