Displaying Asian characters in StyledTextCtrl

Hi,

I used r18n-desktop (http://r18n.rubyforge.org/) for localization, it
worked well.

But I have trouble displaying Chinese characters in StyledTextCtrl,

On Mac, the control accepts characters, but failed to save (could be
problems in my application, the file becomes empty)
on Windows, typed or copied chinese characters showed as blocks,
failed to save as well.

I did a search ‘Unicode’ in this forum, couldn’t find relevant posts.

Thanks,
Zhimin

The section you need to look at, is here:
http://wxruby.rubyforge.org/doc/styledtextctrl.html#text_encoding

Scintilla defaults to the system’s encoding, so if you have a different
encoding from your target encoding, it won’t work. Try using thoes
methods,
and see if it makes any difference when your getting text from the
Scintilla
control.

hth,

Mario

Thanks Mario

http://wxruby.rubyforge.org/doc/styledtextctrl.html#text_encoding

I did notice this as well, few meaningful examples found on Internet.

def initialize
super()
self.set_code_page(STC_CP_UTF8)
end

The problem (not being able to save the file) remains.

Regards,
Zhimin

How exactly are you saving the file?

How exactly are you saving the file?

class EditorSession < Wx::StyledTextCtrl

def initialize
  super
  # ...
  self.set_code_page(STC_CP_UTF8)
  # ...
end

def save_file(name)
  puts "calling save file #{name} "
  begin
    super
    puts "saved Ok"
    # ...
  rescue => e
    puts "error: saving file: #{e}"
    logger.warn "failed to save #{name}: #{e}"
  end
end

Output:
calling save file F:/samples/chinese_spec.rb
saved Ok

Then the file content is cleared.

Zhimin