I18n translate: one, other more?

Hello,

I would like to have a range of strings being returned using t()
function from I18n.

Example:
t(‘health’, :count => 0)

dead

t(‘health’, :count => 1)

injured

t(‘health’, :count => 2)

not well

t(‘health’, :count => 3)

so so

t(‘health’, :count => 4)

just fine

t(‘health’, :count => 5)

good

t(‘health’, :count => 6)

great

etc.

By default it only supports one and other. Is there a way to make it
work with many different counts? If not, what else could I do to make
this work?

Thanks in advance,
Hans

Heinz S. wrote in post #967521:

Hello,

I would like to have a range of strings being returned using t()
function from I18n.

Example:
t(‘health’, :count => 0)

dead

t(‘health’, :count => 1)

injured

t(‘health’, :count => 2)

not well

t(‘health’, :count => 3)

so so

t(‘health’, :count => 4)

just fine

t(‘health’, :count => 5)

good

t(‘health’, :count => 6)

great

etc.

DON’T DO THIS! This is a completely inappropriate use of t().

Instead, have a helper function that takes a number and returns the
appropriate string. Could be as simple as
def health(count)
statuses = [‘dead’, ‘injured’, ‘not well’…]
statues[count]
end

By default it only supports one and other. Is there a way to make it
work with many different counts? If not, what else could I do to make
this work?

Thanks in advance,
Hans

Again, don’t abuse I18N for this. But if you do have a legitimate
need for such a feature (say, different single, dual, and plural forms,
as in Arabic), then use a gettext-based solution (such as fast_gettext)
instead of Rails’ own I18N backend. Among its other advantages, gettext
handles different pluralizations better.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

DON’T DO THIS! This is a completely inappropriate use of t().

Instead, have a helper function that takes a number and returns the
appropriate string. Could be as simple as
def health(count)
statuses = [‘dead’, ‘injured’, ‘not well’…]
statues[count]
end

Looks a lot more reasonable, thanks!