-
-
Notifications
You must be signed in to change notification settings - Fork 861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for pluralization locales in component interpolation #471
Comments
Hello, |
What about an alternative implementation like: <i18n path="some.path" :plural="3" /> It feels weird that there's some significant functionality in this library that you can't use if you're using the |
IMHO, it would be better to have another component name, like |
Are there any updates on this? Im running into this problem quite often. I really like the proposal of @arantes555 |
As a workaround I'm currently handling interpolation + pluralization like this: const messages = {
en: {
'comments': '{n} {comments-text}',
'comments-plural': 'No comments | comment | comments',
}
} <i18n path="comments" tag="h1">
<b v-if="comments.length !== 0" slot="n">{{ comments.length }}</b>
<span slot="comments-text">{{$tc('comments-plural', comments.length)}}</span>
</i18n> It's not ideal, if anyone has better solution please let me know |
Something new? It will be so useful. |
@kazupon What do you mean by status: "Ready"? Is there a way to use pluralization in component interpolation? |
Are you planning to release it soon? It's a useful feature |
I've made a bit simplier, rails way pluralization: // https://github.com/eemeli/make-plural/blob/master/packages/plurals/plurals.js
const pluralizationRules = {
en: function (n) {
const s = String(n).split('.')
const v0 = !s[1]
return (n === 1 && v0 ? 'one' : 'other')
},
de: function (n) {
const s = String(n).split('.')
const v0 = !s[1]
return (n === 1 && v0 ? 'one' : 'other')
}
}
Vue.prototype.$t = function (key, ...values) {
const i18n = this.$i18n
const options = values[0] || {}
if (Object.keys(options).includes('count')) {
key = `${key}.${pluralizationRules[i18n.locale](options.count)}`
}
return i18n._t(key, i18n.locale, i18n._getMessages(), this, ...values)
} Usage: $t('some.key', { count: count }) {
some: {
key: {
"one": "One 1",
"other": "Other %{count}"
}
}
} |
This is a very useful feature. Any ETA? |
we supported in Vue I18n v9. |
Late to the party, but nuxt i18n is still on v8 so here's another workaround: <i18n :path="`some.key.${Math.min(2, count)}`">
<template #count>
<strong>{{ count }}</strong>
</template>
</i18n> module.exports = {
some: {
key: {
0: '{count} equals none',
1: '{count} equals one',
2: '{count} equals more than one',
},
},
}; |
In order to avoid having to add markup to translations it would be helpful if component interpolation would also work for pluralization locales.
The text was updated successfully, but these errors were encountered: