# Displaying Asian characters in StyledTextCtrl

**URL:** <https://www.ruby-forum.com/t/displaying-asian-characters-in-styledtextctrl/165646>\
**Category:** wxRuby\
**Created:** [April 16, 2009, 1:35am UTC](https://www.ruby-forum.com/t/displaying-asian-characters-in-styledtextctrl/165646 "2009-04-16T01:35:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zzhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7cd45c/32.png) [@zzhan](https://www.ruby-forum.com/u/zzhan)\
**Post date:** [April 16, 2009, 1:35am UTC](https://www.ruby-forum.com/t/displaying-asian-characters-in-styledtextctrl/165646/1 "2009-04-16T01:35:20Z")

</div>

Hi,

I used r18n-desktop ([http://r18n.rubyforge.org/](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

---

<div class="post-metadata">

**Author:** ![zzhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7cd45c/32.png) [@zzhan](https://www.ruby-forum.com/u/zzhan)\
**Post date:** [April 16, 2009, 3:57am UTC](https://www.ruby-forum.com/t/displaying-asian-characters-in-styledtextctrl/165646/2 "2009-04-16T03:57:22Z")

</div>

The section you need to look at, is here:  
[http://wxruby.rubyforge.org/doc/styledtextctrl.html#text\_encoding](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

---

<div class="post-metadata">

**Author:** ![zzhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7cd45c/32.png) [@zzhan](https://www.ruby-forum.com/u/zzhan)\
**Post date:** [April 16, 2009, 6:47am UTC](https://www.ruby-forum.com/t/displaying-asian-characters-in-styledtextctrl/165646/3 "2009-04-16T06:47:03Z")

</div>

Thanks Mario

> [http://wxruby.rubyforge.org/doc/styledtextctrl.html#text\_encoding](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

---

<div class="post-metadata">

**Author:** ![zzhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7cd45c/32.png) [@zzhan](https://www.ruby-forum.com/u/zzhan)\
**Post date:** [April 16, 2009, 7:28am UTC](https://www.ruby-forum.com/t/displaying-asian-characters-in-styledtextctrl/165646/4 "2009-04-16T07:28:22Z")

</div>

How exactly are you saving the file?

---

<div class="post-metadata">

**Author:** ![zzhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7cd45c/32.png) [@zzhan](https://www.ruby-forum.com/u/zzhan)\
**Post date:** [April 16, 2009, 7:54am UTC](https://www.ruby-forum.com/t/displaying-asian-characters-in-styledtextctrl/165646/5 "2009-04-16T07:54:38Z")

</div>

> 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
