-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
String with more than one count
#908
Comments
should be possible like: http://i18next.com/translate/nesting/#withpluralandoptions |
did this solve your demand? |
yes, not as clean as I wish, but it does. |
yes...not the easiest thing to reach...looking at languages having multiple pluralforms that stuff gets complicated very fast. If you got an idea to improve that? |
I thought we can have something like this.
Your locale files would look like this.
or this will also works
Let me know if you like the concept. |
hm...rather inspiring, what might work is:
which is a 'regular' nesting call, but here: https://github.com/i18next/i18next/blob/master/src/Interpolator.js#L126
we call basically i18next.t with new cloned options there we might transform the girl/boy count value into a regular count for the nested call (
|
Can I make it a contribution? Oh and I see lots of things that I would argue about the nesting operator. I have feelings that it should be deprecated on how it is now, but I don't have enough background on the motivation to have this feature to begin with. I have a strong feeling that nesting with options shouldn't be a thing, I can see it being useful in some circumstances, but at least shouldn't be encouraged. |
Agree on nesting with options is somehow a little over the top...was introduced in v1. But as it's not overly complicated i would keep it. But i think we could add the convert for "girl" to count without the need of transformCounts - if new options included girl and count i think it's save and backwards compatible. If you like you can make the contribution. PR would be welcome...else i will see if i got on this (hopefully sooner than later) |
argh...missed that one...will reopen for implementation...hopefully get this done soon...as it looks like a nice improvement |
Oh, I started implementing this to submit it as a PR, but I got stuck at some point, I'm not familiar with the code base and then I totally forgot about it. |
didn't got to it myself...so still hanging here for a long time :( but lets keep it in the hope xmas holiday gives the time |
guess we will close this for now...PR would still be welcome but i guess for the few cases this is needed the current solution is an option. If more often needed i guess using ICU would be easier: https://github.com/i18next/i18next-icu |
I stumbled upon this issue while looking for similar functionality. Almost switched away from the This seems to be now be possible via https://www.i18next.com/translation-function/nesting#passing-options-to-nestings The example in the docs works, but I find this clearer: {
"girlsAndBoys": "They have $t(girls, {\"count\": {{girls}} }) and $t(boys, {\"count\": {{boys}} })",
"boys": "{{count}} boy",
"boys_plural": "{{count}} boys",
"girls": "{{count}} girl",
"girls_plural": "{{count}} girls"
} i18next.t('girlsAndBoys', {girls: 3, boys: 2}); // They have 3 girls and 2 boys |
@andreialecu hello :) the world is small mate |
Today I encountered a situation that need to have a string with more than one
count
, and I was not sure how to deal with it.How would I structure this to offer the 4 possible plural/singular combinations?
The text was updated successfully, but these errors were encountered: