[ruby-gnome2-doc-cvs] [Hiki] update - tips_i18n

Back to archive index

ruby-****@lists***** ruby-****@lists*****
2003年 7月 12日 (土) 01:38:36 JST


-------------------------
REMOTE_ADDR = 210.249.204.48
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/?tips_i18n
-------------------------
= How to write the non-ascii texts
All strings you pass to GTK+ functions must be in UTF-8. 
Of course, Ruby-GNOME2 is the same.

Usually, you have written ruby scripts in your locale and charset not UTF-8.

So you may confuse how to write the texts in Ruby-GNOME2 at first.

I introduce some way to write non-ascii characters in Ruby-GNOME2.


== 1 Write scripts in UTF-8
This is the easiest way if you use the editors which support UTF-8.

It may be better to define $KCODE = 'u' in the head of your script.

 $KCODE = 'u'
 require 'gtk2'
 
 ...

Also you can use -K option.

== 2 Write script in your charset and convert it with iconv
Write your script with your favorite editor which doesn't support UTF-8.
You save it with your charset(not UTF-8).

Then you convert it with iconv when you run it.

 iconv -f <your charset> -t utf-8 foo.rb |ruby -
 iconv -f euc-jp -t utf-8 foo.rb |ruby -

As the result, this is the same as 1st way. So it may be better to define $KCODE = 'u' at first.

== 3 Use GLib.convert for each texts.
GLib.convert converts a string from one character set to another. 

 require 'gtk2'
 
 Gtk::Button.new(GLib.convert("RYOUKAI", "utf-8", "euc-jp"))  #str, to, from

I don't recommand this way for static texts. Usually GLib.convert uses when you read non-ascii, non-utf-8 texts from files, networks.

== 4 ((<Ruby-GetText-Package|URL:http://ponx.s5.xrea.com/hiki/ruby-gettext.html>))
So far, they are not support i18n(L10n). It may be no problem if you distribute your scripts locally. 
But if you want to distribute it whole the world, you need to support i18n(L10n). 

((<Ruby-GetText-Package|URL:http://ponx.s5.xrea.com/hiki/ruby-gettext.html>)) is the one of the solution which replace English texts to localized texts. 
And it's also compatible with GNU GetText Package. 
Try if you are intersted in.

== ChangeLog
:2003-07-08 Masao Mutoh
 Initial Release
-------------------------
= How to write the non-ascii texts
All strings you pass to GTK+ functions must be in UTF-8. 
Of course, Ruby-GNOME2 has the same requirement.

Usually, you have written ruby scripts in your locale and charset, which
isn't necessarily UTF-8.

So you may be confused about how to write texts in Ruby-GNOME2 at first.

Here is a summary of your options:

== 1 Write scripts in UTF-8
This is the easiest way if you use an editor that supports UTF-8.

It may help to define $KCODE = 'u' in the head of your script.

 $KCODE = 'u'
 require 'gtk2'
 
 ...

Also you can use the -K option to Ruby.

== 2 Write the script in your charset and convert it with iconv
Write your script with your favorite editor which doesn't support UTF-8.
You save it with your own (non-UTF-8) charset.

Then you convert it with iconv when you run it.

 iconv -f <your charset> -t utf-8 foo.rb |ruby -
 iconv -f euc-jp -t utf-8 foo.rb |ruby -

Effectively, this is the same as the first method. So it may again be
better to define $KCODE = 'u' in your script.

== 3 Use GLib.convert for each string.
GLib.convert converts a string from one character set to another. 

 require 'gtk2'
 
 Gtk::Button.new(GLib.convert("RYOUKAI", "utf-8", "euc-jp"))  #str, to,
from

I don't recommand this way for static texts. Usually you should use
GLib.convert when you read non-ascii, non-utf-8 texts from files or
networks.

== 4 ((<Ruby-GetText-Package|URL:http://ponx.s5.xrea.com/hiki/ruby-gettext.html>))
So far, they don't support i18n (L10n). It may be no problem if you
distribute your scripts locally. 
But if you want to distribute it whole the world, you need to support
i18n (L10n). 

((<Ruby-GetText-Package|URL:http://ponx.s5.xrea.com/hiki/ruby-gettext.html>))
is the one of the solutions which automates replacing English text with
localized text.
It's also compatible with the GNU gettext Package. 
Try it if you are interested.

== ChangeLog
:2003-07-08 Evan Martin 
 Fixed up the English
:2003-07-08 Masao Mutoh
 Initial Release




ruby-gnome2-cvs メーリングリストの案内
Back to archive index