Android中XLIFF的應用

來源:互聯網
上載者:User

標籤:

【轉】http://blog.csdn.net/xipiaoyouzi/article/details/7891153

今天看了一個google的demo,發現部分資源字串在/res/values/string.xml中包含有類似xliff的節點,剛才查了一下,Xliff是XML Localization Interchange File Format 的縮寫,中文名為XML本地化資料交換格式。

對於在Android的資源字串中,可能會有類似下面的 <xliff:g id="FILE_NAME">%1$s</xliff:g> 寫法,這裡,id我們可以隨便定義,後面的%1$s的1%表示這是第一個可替換量,s表示字串

詳細的介紹如下:

屬性id可以隨便命名 
屬性example表示舉例說明,可以省略 
%n$ms:代表輸出的是字串,n代表是第幾個參數,設定m的值可以在輸出之前放置空格 
%n$md:代表輸出的是整數,n代表是第幾個參數,設定m的值可以在輸出之前放置空格,也可以設為0m,在輸出之前放置m個0 
%n$mf:代表輸出的是浮點數,n代表是第幾個參數,設定m的值可以控制小數位元,如m=2.2時,輸出格式為00.00

例如一個String中有多個需要替換的變數,可以在xml中定義如下變數: 

   <string name="info">
your name is <xliff:g id="NAME">%1$s</xliff:g>, and your age is
<xliff:g id="AGE">%2$s</xliff:g>
   </string>

 

程式中動態載入:

TextView tv = (TextView) findViewById(R.id.textView);

        String info = getResources().getString(R.string.info,"jnhoodlum","22");

        tv.setText(info);

 

最後要注意一點:在String裡要增加XLIFF的 xmlns:

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

Android中XLIFF的應用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.