hi, i am trying to build and application that accepts different languages and characters. There is two yaml files: english and frensh. i first load the content of the French file as a hash array the dump it back using the following command File.open(french.yaml, "w") {|f| YAML.dump(join_hash, f)} Everything is working fine; however ruby encodes a string with foreign characters when it converts back to yaml. e.g "français".to_yaml => becomes "fran\xC3\xA7ais" is there any way i can go around this; i have already wasted two days researching. Your help well be greatly appreciated regards MO -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mouhannad Oweism wrote:> hi, > i am trying to build and application that accepts different languages > and characters. There is two yaml files: english and frensh. i first > load the content of the French file as a hash array the dump it back > using the following command > File.open(french.yaml, "w") {|f| YAML.dump(join_hash, f)} > Everything is working fine; however ruby encodes a string with foreign > characters when it converts back to yaml. > e.g > "français".to_yaml => becomes "fran\xC3\xA7ais" >Well, \xC3\xA7 is the code point for the UTF8 representation of ç, so it seems to be working at some level. Ruby does not natively support UTF8. I believe that to enable UTF8 support in Rails you need to add this to your environment.rb file: # Set these for unicode support $KCODE = ''u'' require ''jcode'' However, I cannot say whether or not this will help you in your specific instance. In ruby script/console running in a DOS box on my Windows XP your string above renders as "franaceais" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne wrote: Take a look at iconv. http://wiki.rubyonrails.com/rails/pages/iconv -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne wrote:> James Byrne wrote: > Take a look at iconv. > http://wiki.rubyonrails.com/rails/pages/iconvThanks for the link James. This way can help in translating this: puts Iconv.new(''UTF-8'', ''UTF-8'').iconv("fran\xC3\xA7ais").inspect => français However what I am interested in is conv = "français".to_yaml puts Iconv.new(''UTF-8'', ''UTF-8'').iconv(conv).inspect => NOTHING HAPPENS Any suggestions? MO -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mouhannad Oweism wrote:> James Byrne wrote: >> James Byrne wrote: >> Take a look at iconv. >> http://wiki.rubyonrails.com/rails/pages/iconv > > Thanks for the link James. This way can help in translating this: > > puts Iconv.new(''UTF-8'', ''UTF-8'').iconv("fran\xC3\xA7ais").inspect => > français > > However what I am interested in is > > conv = "français".to_yaml > > puts Iconv.new(''UTF-8'', ''UTF-8'').iconv(conv).inspect => NOTHING HAPPENS > > > Any suggestions?This is a bug in Ruby''s YAML parser --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---