I’m having a problem that’s testing my sanity. In my rails application, I’m loading a escaped UTF-8 string from an I18n translation file to be used in my application routes. However, rails is not unescaping the string when used in routing. Here’s my translation file:
---
ru:
activerecord:
models:
item:
other: "\xD0\xA2\xD0\xBE\xD0\xB2\xD0\xB0\xD1\x80\xD1\x8B" # UTF-8 escaped version of "Товары". (to_yaml is doing the escaping btw)
And here’s my config/routes.rb
match "/#{Item.model_name.human(:count => :other).downcase}" => "items#index"
However, when navigating to this route, I get:
Routing Error
No route matches "/%d0%a2%d0%be%d0%b2%d0%b0%d1%80%d1%8b"
If the UTF-8 is stored in the translation file unescaped, everything works fine. to_yaml is escaping the string and causing the problem. Is there any way to force yaml to retain the original string?
BTW, I’m using Rails 3.0.7, Ruby 1.9.2. Thanks guys!
I was able to store the original UTF-8 string without converting the string to Ruby internal encoding by using ya2yaml instead of to_yaml. However, I had to encode the params hash’s keys & values to UTF-8(keys were being encoded as ASCII-8BIT and values as UTF-8) before the yaml was generated properly: