Forum: Ruby on Rails chinese lang failed in SaltedHashLogin

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joe Y. (Guest)
on 2006-12-31 01:38
(Received via mailing list)
Hi,

I'm using SaltedHashLogin, it works well.

now, I want to switch language to be Chinese, so I edit a new yaml in
utf-8 with all
Chinese value inside.

Then I encouter "Rails application failed to start properly" problem
when start...

In the server.log, the error info is:
../lib/localization.rb:55:in `iconv': "\xe4\xb8\xad\xe6\x96\x87"
(Iconv::IllegalSequence)

And the code for this is:
  def self.load_localized_strings
    # Load language files
    Dir[RAILS_ROOT + '/lang/*.yaml'].each do |filename|
      filename =~ /(([a-z]+_?)+)\.yaml$/
      hash = YAML::load(File.read(filename))
      file_charset = hash['file_charset'] || 'ascii'
      lang = $1

      # convert string keys to symbols
      symbol_hash = Hash.new
      Iconv.open(CONFIG[:web_charset], file_charset) do |i|
        hash.each do |key, value|
          symbol_hash[key.to_sym] = i.iconv(value)
          if key =~ /^active_record_errors_(.*)/
            ActiveRecord::Errors.default_error_messages[$1.to_sym] =
              symbol_hash[key.to_sym]
          end
        end
      end

      LOCALIZED_STRINGS[lang] = symbol_hash
    end
  end

any one have any idea?
my lang file is saved in utf-8 format.

Thanks there,
ssyangy
This topic is locked and can not be replied to.