Ruby on rails 如何在rails中使用单词进行复数化?
我想翻译成复数形式,用数字代替数字 例如,我希望能有一个翻译结果:Ruby on rails 如何在rails中使用单词进行复数化?,ruby-on-rails,ruby,rails-i18n,Ruby On Rails,Ruby,Rails I18n,我想翻译成复数形式,用数字代替数字 例如,我希望能有一个翻译结果: "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." 有什么方法可以做到这一点吗?我想你想要的是: 或者在您的情况下: str = "The Pa
"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."
有什么方法可以做到这一点吗?我想你想要的是: 或者在您的情况下:
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."
我想你要找的是: 或者在您的情况下:
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."
在您的示例中,您使用的是已经人性化的字符串。你的正则表达式已经关闭了。哦,我的错。。你说“regex关闭”是什么意思?它不会做你认为它会做的事。:)试试看,好的接球!不知道我是怎么搞砸的,一开始它会打印31张@SergioTulentsev正则表达式现在应该可以了,对吧?“不知道我怎么搞砸了”-你的字符串一开始是人性化的,然后正则表达式什么都没做在你的例子中,你使用的是已经人性化的字符串。你的正则表达式已经关闭了。哦,我的错。。你说“regex关闭”是什么意思?它不会做你认为它会做的事。:)试试看,好的接球!不知道我是怎么搞砸的,一开始它会打印31张@SergioTulentsev正则表达式现在应该没问题了,对吧?“不知道我怎么搞砸了”-你的字符串从一开始就是人性化的,然后正则表达式什么都没做欢迎堆栈溢出。请阅读“”和“”,以及链接页和“”。你的问题问得不好。你找过了吗?如果不是,为什么?如果是的话,在哪里,为什么没有帮助?你写代码了吗?若否,原因为何?如果是这样,那么演示您所问的问题所需的最少代码是多少?欢迎使用堆栈溢出。请阅读“”和“”,以及链接页和“”。你的问题问得不好。你找过了吗?如果不是,为什么?如果是的话,在哪里,为什么没有帮助?你写代码了吗?若否,原因为何?如果是这样,那么演示您所问问题所需的最低代码是什么?