vuex-i18n icon indicating copy to clipboard operation
vuex-i18n copied to clipboard

Translating plural statements, lack of documentation

Open jonasgroendahl opened this issue 7 years ago • 3 comments

Hello!

So far I have not been able to translate plural statements like for example: $t('{count} car ::: {count} cars', {count: count},count)

How should my key-value pair look in the translation variable? I can't seem to find any information on this in the documentation. This is how my translation variable from English to Danish would initially look by looking at the docs, but nothing is being translated:

const da = {
  "{count} cars" : "{count} biler",
  "{count} car" : "{count} bil",
}

jonasgroendahl avatar Jan 18 '18 13:01 jonasgroendahl

OK after a few hours at trying different stuff, i tried the following which worked:

const da = {
 "{count} car ::: {count} cars" : "{count} bil ::: {count} biler"
}

Hope this is useful to anyone

jonasgroendahl avatar Jan 18 '18 13:01 jonasgroendahl

Hi @jonasgroendahl

Apparently the description in the readme is not very clear. I will update the description in the coming days.

// using the translation directly (as specified in the current readme)
{{ $t('You have {count} new message ::: You have {count} new messages', {count: 5}, 5) }}

// using a key to lookup the translations
{{ $t('mykey', {count: 5}, 5) }}

const translations {
  'mykey': 'You have {count} new message ::: You have {count} new messages'
}

// alternative specification with array for translations
const translations {
  'mykey': [
    'You have {count} new message',
    'You have {count} new messages'
  ]
}

Hope this clarifies things for now.

tikiatua avatar Jan 18 '18 14:01 tikiatua

Hi @tikiatua

Is it possible to add the 0 option ? Meaning having apple: [ 'no apples', 'one apple', '{count} apples' ] ?

Thank you

The-BlackWidow avatar Mar 06 '18 17:03 The-BlackWidow