如何在 rails 中用单词复数?

How to pluralize in rails with words?

我想用单词代替数字来使翻译复数化。

因此,例如,我希望能够进行翻译,结果是:

"The Patriots came back to win the Superbowl by scoring thirty-one points in a row."

...而不是:

"The Patriots came back to win the Superbowl by scoring 31 points in a row."

有办法吗?

我想你要找的是 humanize:

2.humanize  # => "two"
4.humanize  # => "four"
8.humanize  # => "eight"

或者您的情况:

str = "The Patriots came back to win the Superbowl by scoring 31 points in a row."
humanized = str.gsub(/\d+/) do |match|
  match.to_i.humanize  
end    
humanized # => "The Patriots came back to win the Superbowl by scoring thirty-one points in a row."