问题: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'

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

在此处输入图像描述

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

解答

来自文档...

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


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

en: {
  message: {
    imageMessage: "{n} image downloaded | {n} images downloaded"
  }
}

并在您的模板中

$tc("message.imageMessage", imageCount)
Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐