Skip to content

Comment on "this gem is awesome".to_spanish # = "esta joya es impresionante"

Comments

What's causing this?

    ruby-1.8.7-p302 > "Where is the bathroom?".to_spanish
    => "\302\277D\303\263nde est\303\241 el ba\303\261o?"

Ruby 1.8 displays non-ascii characters in the shell using octal escape sequences. \302\277 is ¿, \303\263 is ó and so forth. It should be fine to work with (eg, saving to a database or displaying in a template) as long as you know the encoding. I just glanced at the code, but it looks like it just takes whatever the Google Translate API gives it, which I'm guessing is UTF-8.

Listed under "Roadmap" in the readme is the following:

Investigate Unicode support for Ruby 1.8. to_lang has only been tested with 1.9.

Do you have a copy of 1.9 to test with?

Ah, yes. Much better:

    ruby-1.9.2-p0 > "Where is the bathroom?".to_spanish
    => "¿Dónde está el baño?" 
Thanks

Accents and special chars, I think it is trying to output "¿Dónde está el baño?"

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.