This project is archived and is in readonly mode.
titleize missing in ActiveSupport::Multibyte::Chars
Reported by johan.rejeep (at gmail) | June 12th, 2009 @ 08:56 AM | in 3.0.2
Hi!
I'm missing the method titleize in ActiveSupport::Multibyte::Chars.
Example:
"VarfÖr gick åke bakÅt".mb_chars.titleize.to_s
Gives me:
"VarfÖr Gick åke BakÅt" When I expect:
"Varför Gick Åke Bakåt"
I solved it in my project with a simple monkey patch:
class ActiveSupport::Multibyte::Chars
def titleize
self.split(/(\s)/).collect { |e| e.mb_chars.capitalize.to_s }.join($1)
end end
Comments and changes to this ticket
-
Manfred Stienstra August 11th, 2009 @ 02:24 PM
- 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 May 28th, 2010 @ 08:52 PM
- 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
capitalize
method 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
classify
orunderscore
method, when you can just do something like:Inflector.transliterate(string).tableize
if 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 June 15th, 2010 @ 10:58 PM
- Milestone cleared.
- Assigned user set to José Valim
-
Repository June 19th, 2010 @ 11:59 PM
- State changed from open to resolved
(from [667522ca9834ce1f173a3421fb0bf0f555324c6f]) Adds titleize/titlecase to AS::Multibyte::Chars
[#2794 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/667522ca9834ce1f173a3421fb0bf0... -
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 2794 titleize missing in ActiveSupport::Multibyte::Chars [#2794 state:resolved]