Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
复数可以在Android中翻译吗?_Android - Fatal编程技术网

复数可以在Android中翻译吗?

复数可以在Android中翻译吗?,android,Android,在Android中有没有翻译复数的方法 我的应用程序会推送类似“任务将在X分钟后过期”的通知,但我需要用几种语言执行此操作。应该没有问题。只需在特定语言的资源文件夹中定义复数(例如,res/values-es/plurals.xml)。这张照片正好展示了这类事情: res/values/strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <plurals name="numberOf

在Android中有没有翻译复数的方法


我的应用程序会推送类似“任务将在X分钟后过期”的通知,但我需要用几种语言执行此操作。

应该没有问题。只需在特定语言的资源文件夹中定义复数(例如,
res/values-es/plurals.xml
)。这张照片正好展示了这类事情:

res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <plurals name="numberOfSongsAvailable">
        <!--
             As a developer, you should always supply "one" and "other"
             strings. Your translators will know which strings are actually
             needed for their language. Always include %d in "one" because
             translators will need to use %d for languages where "one"
             doesn't mean 1 (as explained above).
          -->
        <item quantity="one">%d song found.</item>
        <item quantity="other">%d songs found.</item>
    </plurals>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <plurals name="numberOfSongsAvailable">
        <item quantity="one">Znaleziono %d piosenkę.</item>
        <item quantity="few">Znaleziono %d piosenki.</item>
        <item quantity="other">Znaleziono %d piosenek.</item>
    </plurals>
</resources>
在代码中,您可以这样使用它:

int count = getNumberOfsongsAvailable();
Resources res = getResources();
String songsFound = res.getQuantityString(R.plurals.numberOfSongsAvailable, count, count);

我不知道有什么方法可以让android框架做到这一点。我总是在每个语言文件夹中使用一个字符串资源表示单数(例如
通知字符串\u单数
),另一个字符串资源表示复数(例如
通知字符串\u复数
),然后根据
x==1
我知道您仍然可以手动执行,就像您在回答中所示,但是为什么翻译编辑器在AS中不显示它们呢?