Android的多元化不工作,需要帮​​助 [英] Android Pluralization not working, need help

查看:188
本文介绍了Android的多元化不工作,需要帮​​助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图利用复数资源与Android,但还没有任何运气。

I've been attempting to utilize the plurals resource with Android but have not had any luck.

下面是我为我的复数形式的资源文件:

Here is my resource file for my plurals:

<?xml version="1.0" encoding="utf-8"?>
    <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
        <plurals name="meters">
            <item quantity="one">1 meter</item>
            <item quantity="other">
                <xliff:g id="count">%d</xliff:g>
                meters
            </item>
        </plurals>
        <plurals name="degrees">
            <item quantity="one">1 degree</item>
            <item quantity="other">
                <xliff:g id="count">%d</xliff:g>
                degrees
            </item>
        </plurals>
    </resources>

...然后这里是code,当我试图从我的资源提取量字符串我使用:

...and then here is the code I am using when I attempt to extract the quantity string from my resources:

Resources res = this.getResources();
tTemp.setText(res.getQuantityString(R.plurals.degrees, this.mObject.temp_c.intValue()));

...但在TextView的文本仍有待%D度%D米

没有人知道发生了什么事?我调试的code和res.getQuantityString(...)调用返回一个字符串,其值%D度 %D米。虽然在数量正好是1它不正确evalute到 1度1米

Does anyone know what is happening? I've debugged the code and the res.getQuantityString(...) call is returning a String whose value is %d degrees or %d meters. Though when the quantity happens to be 1 it does correctly evalute to 1 degree or 1 meter.

在此先感谢您的帮助!

问候,celestialorb。

Regards, celestialorb.

推荐答案

似乎需要指定两次计数,所述第一被用来确定要使用的字符串,第二是,被替换成的所述一个串。例如,

It appears that you need to specify the count twice, the first is used to determine the string to use, and the second is the one that is replaced into the string. e.g.

Resources res = this.getResources();
int tv = this.mObject.temp_c.intValue();
tTemp.setText(res.getQuantityString(R.plurals.degrees, tv, tv));

和至少在我的测试中,到目前为止, XLIFF:例不需要在资源要素

And at least in my testing so far, the xliff:g elements in the resource aren't needed.

这篇关于Android的多元化不工作,需要帮​​助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆