New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#ordinal
and #ordinalize
now support I18n
#32168
#ordinal
and #ordinalize
now support I18n
#32168
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @kamipo (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
0336cb7
to
9698b7b
Compare
…nalize` now support translations through I18n. { fr: { number: { nth: { ordinals: lambda do |_key, number:, **_options| if number.to_i.abs == 1 'er' else 'e' end end, ordinalized: lambda do |_key, number:, **_options| "#{number}#{ActiveSupport::Inflector.ordinal(number)}" end } } } }
9698b7b
to
f58e2dd
Compare
@kamipo any update on this? |
Salut @christianblais |
This will only be released with Rails 6 - it's not out yet. If you are on Rails 6 and still have some problems, feel free to contact me in private and we can walk through it together. |
What if you already have a huge en.yml translation file. Have to convert it to ruby hash to have ordinalized dates when doing
|
Silly me, you can just have en.yml and en.rb
Lovely, thanks all. |
ActiveSupport::Inflector#ordinal
andActiveSupport::Inflector#ordinalize
now support translations through I18n.Summary
The current implementation of
ActiveSupport::Inflector#ordinal
andActiveSupport::Inflector#ordinalize
only work in English. Thest
,nd
, andth
logic is all hardcoded, and obviously doesn't work in other languages. This patch moves that logic to I18n so it can be defined on a per-language basis.This is technically a noop; English should still work as usual, and no other language was added.
Other Information
I found one previous attempt here, dating back to 2014. Unfortunately, the approach wasn't flexible enough to support most languages.