vue.js - 如何声明自定义复数规则 vue-i18n Vue 3?
问题描述
我有一条来自 https://kazupon.github.io/vue-i18n/guide/pluralization.html#accessing-the-number-via-the-pre-defined-argument的复数规则, 但以形式声明
setup() {
const { t, locale } = useI18n({
pluralizationRules: {
ru: function (choice, choicesLength) {
if (choice === 0) {
return 0;
}
const teen = choice > 10 && choice < 20;
const endsWithOne = choice % 10 === 1;
if (choicesLength < 4) {
return !teen && endsWithOne ? 1 : 2;
}
if (!teen && endsWithOne) {
return 1;
}
if (!teen && choice % 10 >= 2 && choice % 10 <= 4) {
return 2;
}
return choicesLength < 4 ? 2 : 3;
},
},
});
return { t, locale };
},
不会改变任何东西(即,0 - секунд,1 - секунда,其余为 секунд)
- 我怎样才能解决这个问题
我需要
...1 секунда
...2-...3-...4 секунды
...0-...5-...6-...7-...8-...9 секунд
<i18n>
{
"en": {
"seconds":"{count} seconds | {count} second | {count} seconds"
},
"ru":{
"seconds":"{count} секунд | {count} секунда | {count} секунд"
}
}
</i18n>
解决方案
我很快查看了 vue-i18n 的来源,并注意到两者都有pluralRules
并且pluralizationRules
具有相同的类型。对我来说,它使用pluralRules
而不是pluralizationRules
.
推荐阅读
- java - 如何从java中的链接列表中的节点检索对象的内容
- google-cloud-platform - 使用 XCom 通过 GoogleCloudStorageToBigQueryOperator 在 Airflow 中加载 Schema
- android - Android:如何制作特殊的recyclerview布局
- observable - 当我尝试编译时,我不断收到这个错误类不是抽象的,并且没有覆盖 MyObserver 中的抽象方法 update(Object)
- strftime - 如何编写符合 Flake8 的 strftime 表达式?
- javascript - 如何将 Google Analytics api 响应放入工作表中?
- aws-amplify - 放大 @model 语法以仅生成创建和更新突变(而不是删除)
- vuejs2 - 使用 Nuxt.js 将事件传递给父组件
- java - 在添加之前检查 ArrayList 中元素的 ID 是否已经存在
- javascript - 使用javascript在表格中移动图像