Rails taking care for your to handle UTF-8. How about when you need to generate a CSV file? It can't be UTF-8. It has to be one of the localized encodings. There is no javascript way to know what is a default locale on the windows client. You may assume it based on your major audience location, (still wrong assumption). BTW CSV is not 'comma-delimited' in general for Excel. Excel uses system locale/regional settings for list element separator. For example Spanish/German/Portuguese use semi-colon. If you export file from US Excel and send it to your friend in Germany, he might have a hard time importing it into his Excel
However this piece of code helps to convert from UTF-8 into 'whatever' Iconv supports
class String
def from_utf8(encoding_to = "ISO-8859-1")
str = self.clone
ic = Iconv.new encoding_to, 'UTF-8'
non_utf_str = ""
begin
non_utf_str << ic.iconv(str)
rescue Exception => e
non_utf_str << e.success
ch, str = e.failed.chars.split(//, 2)
non_utf_str << "?"
retry
end
return non_utf_str
end
end
...
"This is in Russian Привет Медвед".from_utf8 => "This is in Russian ?????? ??????"