android - 如何在 Android 数量字符串(复数)中使用零数量大小写?
问题描述
我正在尝试使用该getQuantityString
方法在我的 Kotlin 应用程序中
根据 android 开发人员指南Resources
进行检索。情况正常,但无法正常工作。这是我的代码。Quantity Strings
Quantity String
One
other
zero
// text
txtNewProfileCount.text = resources.getQuantityString(
R.plurals.shortlists_profile_count,
filteredCandidateVMList.size,
filteredCandidateVMList.size
)
// plurals code
<plurals name="shortlists_profile_count">
<item quantity="zero">Sorry, there are no new profiles in your various shortlists</item>
<item quantity="one">Please review the new profile in your various shortlists</item>
<item quantity="other">Please review the %1$d new profiles in your various shortlists</item>
</plurals>
如果数量是one
和other
,则结果是正确的。但在这种zero
情况下,结果是Please review the 0 new profiles in your various shortlists
。这不是我想要的结果。量大时如何解决zero
?
解决方案
该zero
案例从未在英语中使用过。英语仅使用one
and other
。复数资源仅适用于特定语言的语法独特结构。这在文档中进行了解释:
选择使用哪个字符串完全基于语法必要性。在英语中,即使数量为 0,0 的字符串也会被忽略,因为 0 在语法上与 2 或除 1 之外的任何其他数字没有区别(“零书”、“一本书”、“两本书”等上)。
if
因此,您必须使用代码中的语句手动选择单独的字符串资源。
推荐阅读
- javascript - BigQuery UDF 中使用了哪个版本的节点?
- python - 如何动态生成属性?
- javascript - 想要在一个文件中调用一个函数,而该函数的定义在另一个文件中
- python - 按值对字典进行排序,但当值相同时
- angular-cli - 如何使用 ng add 命令安装本地包 tarball 文件?
- c++ - 使用指针算法修改函数中的二维数组
- google-apps-script - 一款带有用户管理功能的问题调查应用 Google Apps Script 和 Google Sheets
- c - C - 结构数组初始化中空终止符的含义
- rust - 如何将对象数组传递给 WebAssembly 并使用 wasm-bindgen 将其转换为结构向量?
- python-3.x - dlib.image_window.add_overlay() 不显示部分面部标志的闭合图