سؤال

ActiveSupport::Inflector methods like titleize, capitalize, camelize do not work with Cyrillic (Russian, Belarussian, Ukraine, ...) letters.

'xyz'.titleize         
 # => "Xyz"              # OK
'абв'.titleize         
 # => "АБВ"              # FAIL

How can I use ActiveSupport::Inflector methods with Cyrillic letters?

هل كانت مفيدة؟

المحلول

We can use mb_chars to "save" Cyrillic string then ActiveSupport::Inflector methods should work:

'абв'.mb_chars.capitalize.to_s
 => "Абв"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top