How can I use proper word after number, depending on that number. For example I have message that says: for 23 monthes, or it can be 21 month. So I have to inflect depending on number -- 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.
On Oct 27, 2010, at 8:35 AM, Vitaliy Yanchuk wrote:> How can I use proper word after number, depending on that number. > For example I have message that says: > > for 23 monthes, or it can be 21 month. > So I have to inflect depending on number > > --If you''re in a Rails view, you can say: pluralize(n, ''month'') If you''re just in plain Ruby, it might depend on the pluralization rule: "#{n} month#{''s'' unless n == 1}" "#{n} part#{n == 1 ? ''y'' : ''ies''}" "#{n} fish" -Rob Rob Biedenharn Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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.
On 27 October 2010 14:07, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote:> > If you''re just in plain Ruby, it might depend on the pluralization rule: > > "#{n} month#{''s'' unless n == 1}" > > "#{n} part#{n == 1 ? ''y'' : ''ies''}" > > "#{n} fish" >You can also use String.pluralize "#{n} {n == 1 ? ''month'' : ''month''.pluralize}" http://apidock.com/rails/ActiveSupport/Inflector/pluralize -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 27, 2010, at 9:19 AM, Michael Pavling wrote:> On 27 October 2010 14:07, Rob Biedenharn > <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote: >> >> If you''re just in plain Ruby, it might depend on the pluralization >> rule: >> >> "#{n} month#{''s'' unless n == 1}" >> >> "#{n} part#{n == 1 ? ''y'' : ''ies''}" >> >> "#{n} fish" >> > > You can also use String.pluralize > "#{n} {n == 1 ? ''month'' : ''month''.pluralize}" > > http://apidock.com/rails/ActiveSupport/Inflector/pluralizeTrue, but my point was that you may not even need the help from ActiveSupport for something simple (i.e., you are dealing with a known rather than an arbitrary noun). You can even do things like: "#{n} #{n == 1 ? ''error prevents'' : ''errors prevent''} the saving of the record." which tends to get very little help from the Inflector. -Rob Rob Biedenharn Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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.
Rob Biedenharn wrote in post #957481:> On Oct 27, 2010, at 8:35 AM, Vitaliy Yanchuk wrote: > >> How can I use proper word after number, depending on that number. >> For example I have message that says: >> >> for 23 monthes, or it can be 21 month. >> So I have to inflect depending on number >> >> -- > > > If you''re in a Rails view, you can say: > > pluralize(n, ''month'')[...] ...but you probably shouldn''t if you''re going to internationalize the application; different languages have different pluralization rules. Any good I18N library should have a generalized pluralization function (for example, there''s n_ in fast_gettext). 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.
On Oct 27, 10:40 am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Rob Biedenharn wrote in post #957481:> On Oct 27, 2010, at 8:35 AM, Vitaliy Yanchuk wrote: > > >> How can I use proper word after number, depending on that number. > >> For example I have message that says: > > >> for 23 monthes, or it can be 21 month. > >> So I have to inflect depending on number > > >> -- > > > If you''re in a Rails view, you can say: > > > pluralize(n, ''month'') > > [...] > > ...but you probably shouldn''t if you''re going to internationalize the > application; different languages have different pluralization rules. > Any good I18N library should have a generalized pluralization function > (for example, there''s n_ in fast_gettext).I believe the proper Rails way to do it is the following: # view.html.erb t(:month_count, :count => month_number) # locale/en.yml en: month_count: one: ''1 month'' other: ''%{count} months'' -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tim Shaffer wrote in post #957518:> On Oct 27, 10:40am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> > If you''re in a Rails view, you can say: >> >> > pluralize(n, ''month'') >> >> [...] >> >> ...but you probably shouldn''t if you''re going to internationalize the >> application; different languages have different pluralization rules. >> Any good I18N library should have a generalized pluralization function >> (for example, there''s n_ in fast_gettext). > > I believe the proper Rails way to do it is the following: > > # view.html.erb > > t(:month_count, :count => month_number)Only if you''re using Rails'' dreadful I18N. I stay as far away from that as I can.> > # locale/en.yml > > en: > month_count: > one: ''1 month'' > other: ''%{count} months''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.