zoukankan      html  css  js  c++  java
  • <Android 基础(十八)> XLIFF

    介绍

    XLIFF ,XML Localization Interchange File Format,XML本地化数据交换格式。


    实际使用

    1.布局文件

    activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            tools:context="mraz.com.uiwidgetdemo.MainActivity">
    
    
            <TextView
                android:id="@+id/tv_hello"
                android:textSize="10pt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hello" />
        </LinearLayout>
    </ScrollView>

    2.String资源文件

    <resources xmlns:xliff="http://schemas.android.com/tools">
        <string name="hello">your name is <xliff:g id="NAME">%1$s</xliff:g>, and your age is<xliff:g id="AGE">%2$s</xliff:g></string>
    
        <string name="hello_simple">your name is %1$s, and your age is %2$s</string>
    </resources>

    两种,一种是直接使用%1$s类似的格式,另外一种就是使用 xliff:g 给需要替换的内容加了个名字而已,效果是相同的。
    属性id可以随便命名
    %n$ms:代表输出的是字符串,n代表是第几个参数,设置m的值可以在输出之前放置空格
    %n$md:代表输出的是整数,n代表是第几个参数,设置m的值可以在输出之前放置空格,也可以设为0m,在输出之前放置m个0
    %n$mf:代表输出的是浮点数,n代表是第几个参数,设置m的值可以控制小数位数,如m=2.2时,输出格式为00.00


    3.程序中使用

    TextView textView= (TextView) findViewById(R.id.tv_hello);
    
    String hello =  getString(R.string.hello_simple, "android", "28");
    
    textView.setText(hello);

    结果:

    这里写图片描述

  • 相关阅读:
    shiro源码篇
    python内置模块之collections(六)
    python之自然语言处理入门(一)
    python第三方库之numpy基础
    python算法之近似熵、互近似熵算法
    MongoDB之conf配置文件详解(五)
    MongoDB之主从复制和副本集(四)
    MongoDB之python简单交互(三)
    python设计模式之常用创建模式总结(二)
    python设计模式之单例模式(一)
  • 原文地址:https://www.cnblogs.com/lanzhi/p/6467184.html
Copyright © 2011-2022 走看看