vue i18n 中的复数形式

6 plural vue.js vue-i18n

嗨,我正在尝试基于https://kazupon.github.io/vue-i18n/guide/pluralization.html进行复数化

imageCount== 1
          ? $t("message.imageMessage", 1, { imageCount})
          : $t("message.imageMessage", imageCount, {
              imageCount
            })



imageMessage: '{imageCount} image downloaded | {imageCount} images downloaded'
Run Code Online (Sandbox Code Playgroud)

问题:目前它正在显示不应该发生的消息,我实施的方式有什么问题吗?

在此输入图像描述

Codesandbox:https://codesandbox.io/s/lingering-haze-z9jzt?file =/src/components/HelloWorld.vue

Phi*_*hil 9

文档中...

您的模板将需要使用$tc()而不是$t().


您还可以通过在翻译字符串中使用{n}或来稍微改进/缩短您的代码......{count}

en: {
  message: {
    imageMessage: "{n} image downloaded | {n} images downloaded"
  }
}
Run Code Online (Sandbox Code Playgroud)

并在您的模板中

$tc("message.imageMessage", imageCount)
Run Code Online (Sandbox Code Playgroud)