Skip to content
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

Add i18n capabilities to ActiveSupport::Inflector#titleize #34844

Closed
wants to merge 1 commit into from

Conversation

christianblais
Copy link
Contributor

Similar to what #32168 did to ordinal and ordinalized, this PR adds I18n capabilities to titleize.

Summary

titleize currently capitalizes all the words of a string, which unfortunately doesn't work in all languages. Taking "raiders of the lost ark" as an example, what would become "Raiders Of The Lost Ark" in English should instead become "Raiders of the lost ark" in French. Other languages might very well treat this differently too. This PR moves the logic to an I18n rule, where each language will be able to define their own rule.

I was afraid titleize could be used for some internal mechanics, but the method definition clearly state otherwise. Given that information, this should be a safe change.

Other Information

This is a noop. The English rule acts exactly the same as it used too, and no other languages are provided by default.

Original version of titleize used to capitalize all words. Unfortunately,
this isn't a universal rule and should be configurable on a per language
basis. This PR moves the titleize logic to I18n in such a way that each
language can define how sentences should be titleized.
Copy link
Member

@gmcgibbon gmcgibbon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea, but I think this PR and the previously merged one don't take into account a default locale that isn't :en.

I18n.default_locale = :ja
1.ordinalize
# => "translation missing: ja.number.nth.ordinalized"

They both seem like breaking changes to me. Can we instead make the procs a default value for any locale, or perhaps that's not possible? Maybe something to patch in a followup PR.

@rails-bot
Copy link

rails-bot bot commented Dec 18, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Dec 18, 2019
@rails-bot rails-bot bot closed this Dec 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants