0

Using rails 3.0.9 with ruby 1.9.2.

I have to make a list of places (which contains accents and non standard letters) to fill a select box.

Using a helper doesn't work (already searched it), as I get the following error:

invalid multibyte char (US-ASCII)

It apparently has something to do with ruby and not with rails.

I also read that the best solution is to put the list in a translation file, and so I did, but now I can't retrieve the list.

Before, I had:

def madrid_area_array
  [
    "Chapinería",
    "Ciempozuelos",
    "Cobeña",
  ]
end

Now, I have in my .yml:

places:
  spain:
    madrid:
      chapin: "Chapinería"
      ciempo: "Ciempozuelos"
      cobena: "Cobeña"

When I used the helper (in case anyone wonders, symbols like í get literally written in select drop boxes, you don't get 'í'), I could call madrid_area_array to fill the select menu. Now, I can't call the translation file, and have to make an intermediate helper with translations:

def madrid_area_array
  [
    t(:chapin, :scope => "spain.madrid", :locale => "places"),
    t(:ciempo, :scope => "spain.madrid", :locale => "places"),
    t(:cobena, :scope => "spain.madrid", :locale => "places")
  ]
end

Is there any way to get all the entries from a translation subtree? like:

 t(*, :scope => "spain.madrid", :locale => "places")
chech
  • 1,085
  • 14
  • 21
  • are you really trying to internationalise your application of it is just because of the error? In the latter case, did you tried to add `# encoding: utf-8` to the top of your file (as in this question http://stackoverflow.com/questions/1739836/invalid-multibyte-char-us-ascii-with-rails-and-ruby-1-9) –  Feb 13 '12 at 11:53
  • @marcolinux i am internationalising my app even though the example doesn't seem like it, as city names are translated through different languages. i am trying to solve the # encoding: utf-8 problem on another side, and it's a PITA, because writing it in the rails files with utf-8 chars doesn't solve it, and there's no way i'm filling all my files with patches because ruby developers think ASCII-US is worldwide used, kudos for them not – chech Feb 15 '12 at 11:17

0 Answers0