Search code examples
vue.jsvue-i18nplural

Pluralization in vue i18n


Hi i am trying to pluralize based on 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'

Problem : currently it is displaying bo the messages which should not happen,is there anything wrong in the way which i have implemented?

enter image description here

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


Solution

  • From the documentation...

    Your template will need to use $tc() instead of $t().


    You can also improve / shorten your code somewhat by using {n} or {count} in your translation strings...

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

    and in your templates

    $tc("message.imageMessage", imageCount)