Android中<xliff:g>標籤的使用

來源:互聯網
上載者:User

標籤:

今天看源碼時發現在資源檔/res/values/strings.xml中有些<string>標籤中包含<xliff:g>標籤,如:

<string name="running_process_item_user_label">User: <xliff:g id="user_name">%1$s</xliff:g></string>

這個標籤以前都沒用過,就在網上查了一下。XLIFF外文全名是XML Localization Interchange File Format,中文名是XML本地化資料交換格式。

<xliff:g>標籤介紹:

屬性id可隨意命名

屬性example表示舉例說明,可省略

%n$ms:輸出的是字串,n代表是第幾個參數,設定m的值可以在輸出之前放置空格 
%n$md:輸出的是整數,n代表是第幾個參數,設定m的值可以在輸出之前放置空格,也可以設為0m,在輸出之前放置m個0 
%n$mf:輸出的是浮點數,n代表是第幾個參數,設定m的值可以控制小數位元,如m=2.2時,輸出格式為00.00

舉例說明:

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">    <string name="welcome">            歡迎 <xliff:g id="name">%1$s</xliff:g>, 排名 <xliff:g id="num">%2$d</xliff:g>    </string></resources>

使用<xliff:g>標籤需要在resources中加入命名空間,然後在Android程式中使用

public final String getString (int resId, Object... formatArgs)
String s = getString(R.string.welcome, "abc", 123);

輸出結果:歡迎 abc, 排名 123

Android中<xliff:g>標籤的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.