# Handling Unicode in WxRuby

**URL:** <https://www.ruby-forum.com/t/handling-unicode-in-wxruby/209623>\
**Category:** wxRuby\
**Created:** [July 19, 2011, 3:23am UTC](https://www.ruby-forum.com/t/handling-unicode-in-wxruby/209623 "2011-07-19T03:23:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 19, 2011, 3:23am UTC](https://www.ruby-forum.com/t/handling-unicode-in-wxruby/209623/1 "2011-07-19T03:23:00Z")

</div>

If I am using Ruby 1.8.7, what are some recommended practices for  
supporting Unicode within a WxRuby application? My understanding, based  
on web research, is that I should use the multibyte module of Active  
Support in order to add Unicode support to Ruby 1.8.7 (Ruby 1.9 includes  
Unicode support natively).

Generally, I have read the recommendation that it is best to do  
everything in UTF-8. I can try to do so, but am wondering how WxRuby  
handles strings that are passed to set properties, e.g., the text of a  
label. Does this library expect strings to be in a certain encoding?  
How can UTF-8 be specified to WxRuby?

Jamal

---

<div class="post-metadata">

**Author:** ![jamal86](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ebca7d/32.png) [@jamal86](https://www.ruby-forum.com/u/jamal86)\
**Post date:** [July 19, 2011, 1:39pm UTC](https://www.ruby-forum.com/t/handling-unicode-in-wxruby/209623/2 "2011-07-19T13:39:23Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Am 19.07.2011 02:51, schrieb Jamal M.:

> If I am using Ruby 1.8.7, what are some recommended practices for  
> supporting Unicode within a WxRuby application? My understanding,  
> based on web research, is that I should use the multibyte module of  
> Active Support in order to add Unicode support to Ruby 1.8.7 (Ruby  
> 1.9 includes Unicode support natively).

I’d highly recommend using Ruby 1.9. It’s much more painless.  
Back in times before I switched to Ruby 1.9, I used the Iconv module  
(stdlib) to convert all my strings to UTF-8. If I remember correctly, it  
worked like this:

require “iconv”  
ary = Iconv.iconv(“UTF-8”, “yoursourceencoding”, “1st\_string”,  
“2nd\_string”)

> Generally, I have read the recommendation that it is best to do  
> everything in UTF-8. I can try to do so, but am wondering how  
> WxRuby handles strings that are passed to set properties, e.g., the  
> text of a label. Does this library expect strings to be in a certain  
> encoding? How can UTF-8 be specified to WxRuby?

wxRuby expects your strings to be UTF-8-encoded, there’s no way to tell  
wxRuby you want to use another encoding AFAIK. wxRuby just passes the  
strings directly to the underlying wxWidgets, resulting in incorrect  
characters being displayed in the final GUI.

> Jamal

Vale,  
Marvin

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.11 (GNU/Linux)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org/](http://enigmail.mozdev.org/)

iQEcBAEBAgAGBQJOJVfUAAoJELh1XLHFkqhaLksH/R5Dp4YXAKWgrVvXcZRks2WV  
bKn8IgtLTn5oPXRXu4Xsgazl/GhtOed4bw21GpNt6LKYbUPDvrHpVKMH9oJOaFXy  
9WG4n+Gn3chUlmmh3eid6aVVRWKPLwU7HX3NJE66Y0NAFBo9bR6ch7d+9ELhHgQk  
53sWabyfYPouvELGbigK/0DLmCiz/A3z0/9KqDxWAgCNcBdsiQjbQ4UWMjC+yNmT  
Uc0pncrL9jWFLoJ6RddcS2RQUnmGUaLqAAozrq0hmWJ5csTrDxMAZ1hb8i4IYW7X  
ngeTkPdOLNBRovHN9tqxbODHVQatfb4P7VhTi7H6g+ueqeAHDaIcOyZRIfZWZ5U=  
=bOuD  
-----END PGP SIGNATURE-----
