Hi, I had some trouble with character encodings when using rails AJAX support. It turned out that AJAX always uses UTF-8 to submit things. So if you can, use UTF-8 yourself, that makes things easier. However, I had to use the ISO-8859-15 encoding for some legacy reasons, so I had to convert the parameters manually. If you are interested in this (and some background information), I posted the full story here: http://www.kanthak.net/explorations/blog/rails/ajax_and_charsets.html I''m intersted how other people are dealing with this? Any suggestions for improvements? Sebastian
Might sound arrogant but after ditching everything in favor of UTF-8 I say this is my solution. I mean UTF-8 throughout the whole system, inside out. Because anything else is quite messy from the start, and then gets uber-messy when you begin to deal with web-services of any nature (including remote scripting). May I wonder what kind of "legacy reasons" you have for not going UTF? On 5-apr-05, at 11:39, Sebastian Kanthak wrote:> I had some trouble with character encodings when using rails AJAX > support. It turned out that AJAX always uses UTF-8 to submit things. > So if you can, use UTF-8 yourself, that makes things easier. However, > I had to use the ISO-8859-15 encoding for some legacy reasons, so I > had to convert the parameters manually. > > If you are interested in this (and some background information), I > posted the full story here: > http://www.kanthak.net/explorations/blog/rails/ajax_and_charsets.html > > I''m intersted how other people are dealing with this? Any suggestions > for improvements? >-- Julian "Julik" Tarkhanov
Quick note: Safari always interprets Ajax returns as ISO-8859-1, but there is a workaround, please see http://wiki.rubyonrails.com/rails/show/HowToUseUnicodeStrings (at the bottom of the page) Am 05.04.2005 um 14:48 schrieb Julian ''Julik'' Tarkhanov:> Might sound arrogant but after ditching everything in favor of UTF-8 I > say this is my solution. > I mean UTF-8 throughout the whole system, inside out. Because > anything else is quite messy from the start, and then gets uber-messy > when you begin to deal with web-services of any nature (including > remote scripting). > > May I wonder what kind of "legacy reasons" you have for not going UTF? > > On 5-apr-05, at 11:39, Sebastian Kanthak wrote: >> I had some trouble with character encodings when using rails AJAX >> support. It turned out that AJAX always uses UTF-8 to submit things. >> So if you can, use UTF-8 yourself, that makes things easier. However, >> I had to use the ISO-8859-15 encoding for some legacy reasons, so I >> had to convert the parameters manually. >> >> If you are interested in this (and some background information), I >> posted the full story here: >> http://www.kanthak.net/explorations/blog/rails/ajax_and_charsets.html >> >> I''m intersted how other people are dealing with this? Any suggestions >> for improvements? >> > > -- > Julian "Julik" Tarkhanov > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ahem. I ripped this out into a separate script and a simple russian word encoded in this way does not resolve back to russian letters in HTML. Am I mistaken or it is time for a ticket? Unfortunately cannot try it out on full-fledged Rails install now. #!/usr/local/bin/ruby -Ku -rjcode text = "<some_russian_text_here>" puts text.gsub(/([^\x00-\xa0])/u) { |s| "&#x%x;" % $1.unpack(''U'')[0] } On 5-apr-05, at 15:08, Thomas Fuchs wrote:> Quick note: Safari always interprets Ajax returns as ISO-8859-1, but > there is a workaround, please see > http://wiki.rubyonrails.com/rails/show/HowToUseUnicodeStrings (at the > bottom of the page) >-- Julian "Julik" Tarkhanov
Works for me with chinese characters, german umlauts, perfectly. i think text="<some_russian_text_here>" won''t work this way. you have to have properly encoded utf-8 (with \xxx\xxx), or read from a file or db. Am 05.04.2005 um 16:15 schrieb Julian ''Julik'' Tarkhanov:> Ahem. I ripped this out into a separate script and a simple russian > word encoded in this way does not resolve back to russian letters in > HTML. > Am I mistaken or it is time for a ticket? Unfortunately cannot try it > out on full-fledged Rails install now. > > #!/usr/local/bin/ruby -Ku -rjcode > > text = "<some_russian_text_here>" > puts text.gsub(/([^\x00-\xa0])/u) { |s| "&#x%x;" % > $1.unpack(''U'')[0] } > > On 5-apr-05, at 15:08, Thomas Fuchs wrote: > >> Quick note: Safari always interprets Ajax returns as ISO-8859-1, but >> there is a workaround, please see >> http://wiki.rubyonrails.com/rails/show/HowToUseUnicodeStrings (at >> the bottom of the page) >> > -- > Julian "Julik" Tarkhanov > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
If it works with chinese chars then... we''ll see how it behaves for me when I get to implementing ajaxies. On 5-apr-05, at 18:16, Thomas Fuchs wrote:> Works for me with chinese characters, german umlauts, perfectly. > > i think text="<some_russian_text_here>" won''t work this way. you have > to have properly encoded utf-8 (with \xxx\xxx), > or read from a file or db. >-- Julian "Julik" Tarkhanov
Julian ''Julik'' Tarkhanov wrote:> Might sound arrogant but after ditching everything in favor of UTF-8 I > say this is my solution. > I mean UTF-8 throughout the whole system, inside out. Because > anything else is quite messy from the start, and then gets uber-messy > when you begin to deal with web-services of any nature (including > remote scripting). > > May I wonder what kind of "legacy reasons" you have for not going UTF?basically some old programs that are reading the same data (my project is a rails frontend for it) and don''t understand UTF-8. So I had the choice of either changing all the old code or changing the rails code and so far, it worked pretty well with making rails deal with it. However, I completely agree with you that for new projects, UTF-8 everywhere is the way to go! Sebastian