Search code examples
ruby-on-railsrubyruby-on-rails-3internationalizationactivesupport

Rails Parameterize using Transliterate Doesn't work with Arabic/Unicode Strings


I have a string containing Arabic charachters "محمود"

When I try to parameterize this string, it returns empty string ""

x = "محمود"
x.parameterize    => ""

I have checked parameterize code and found it calls I18n.transliterate which returns question marks "?????"

I tried to customize transliteration referring to previous question How do you customize transliterations in a Rails 3 app?

But still returning blank string.

Any help?


Solution

  • The parameterize method is supposed to render the string URL safe, and there's a strict limit on what kind of characters can appear in the URL. Generally anything not strictly a-z or 0-9 or - is stripped.

    You could always try and fix it so that multi-byte UTF-8 characters are admitted by default. The current implementation is really quite lacking. Instead of allowing only a small set of specific characters, a more robust version would strip out the troublesome ones.