Application of Xliff in Android

Source: Internet
Author: User

"Turn" http://blog.csdn.net/xipiaoyouzi/article/details/7891153

Today I saw a Google demo, found that some of the resource string in/res/values/string.xml contains a similar xliff node, just checked, Xliff is XML Localization interchange File The abbreviation for format, the Chinese name is XML localized data Interchange format.

For the resource string in Android, there may be similar to the following <xliff:g id= "file_name" >%1$s</xliff:g> notation, here, id we can arbitrarily define, behind the%1 $ s 1% Indicates that this is the first replaceable amount, s represents a string

Detailed introduction is as follows:

Property ID can be named casually
The attribute example represents an example, which can be omitted
%n$ms: Represents the output of a string, n is the number of parameters, set the value of M can be placed before the output space
%N$MD: Represents the output is an integer, n is the number of parameters, set the value of M can be placed before the output space, can also be set to 0m, before the output of M 0
%N$MF: Represents the output is a floating-point number, n is the number of parameters, setting the value of M can control the scale, such as m=2.2, the output format is 00.00

For example, there are multiple variables in a string that need to be replaced, and you can define the following variables in the XML:

<string name= "Info" >
Your name is <xliff:g id= "name" >%1$S</XLIFF:G>, and your
<xliff:g id= "Age" >%2$s</xliff:g>
</string>

Dynamic loading in the program:

TextView TV = (TextView) Findviewbyid (R.id.textview);

String info = getresources (). getString (R.string.info, "Jnhoodlum", "22");

Tv.settext (info);

One last thing to note: In the string, you increase the xmlns of xliff:

<resources xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:xliff= "urn:oasis:names:tc:xliff:document:1.2" >

Application of Xliff in Android

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.