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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk 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, > HansAgain, 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 marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > 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! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.