This project is archived and is in readonly mode.
titleize missing in ActiveSupport::Multibyte::Chars
-
Manfred Stienstra
- State changed from new to open
That's correct, none of the inflection methods are multibyte safe. Inflection methods were primarily written to juggle table and constant names and are used quite a lot in core code. I'm afraid Rails would slow down a lot if we would make them multibyte safe.
However, I wouldn't mind accepting a patch with a ActiveSupport::Multibyte::Inflections module which can be included into Chars to add these methods.
-
Norman Clarke
- Tag changed from encoding, string, utf to encoding, patch, string, utf
The attached patch resolves the reported issue.
Rather than create an Inflector module, however, I just added a #titleize method to Multibyte::Chars.
This was for two reasons. One, there was already a
capitalizemethod there, and this is conceptually similar.Two, none of the other methods in Inflector seem particularly useful in a multibyte context: what's the point of a separate
classifyorunderscoremethod, when you can just do something like:Inflector.transliterate(string).tableizeif you really need to get a table name from a string with multibyte chars. If we provide a method for this, it's not entirely clear to me how we should handle non-Roman strings that can't easily be approximated to ASCII, since for example, Ruby doesn't allow UTF-8 characters in constants. Also, pluralizing non-English strings will generally just lead to hilarity:
"Männer".mb_chars.tableize # => "manners"That looks completely absurd to a German speaker. :-)
-
Santiago Pastorino
- Milestone cleared.
- Assigned user set to José Valim
-
Repository
- State changed from open to resolved
(from [667522ca9834ce1f173a3421fb0bf0f555324c6f]) Adds titleize/titlecase to AS::Multibyte::Chars
[#2794 titleize missing in ActiveSupport::Multibyte::Chars state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/667522ca9834ce1f173a3421fb0bf0...
