Ruby GetText Package is Native Language Support Library and Tools which modeled after GNU gettext package.
(Development times only)
ruby-gettext-package-0.2.1.tar.gz
De-Compress archive and enter its top directory.
Then type:
# ruby install.rb config # ruby install.rb setup # ruby install.rb install
You can also install files in your favor directory by
supplying install.rb some options. Try "ruby install.rb --help".
They are the text files with msgid(Original message) and msgstr(Translated message). You can create it with rgettext from your script file.
This is binary files which created from po-files by msgfmt.
domain is just mo-file name. Usually, it is called PACKAGE(like in GNOME).
GetText.bindtextdomain(domainname, path = nil, locale = nil)
GetText._(msgid)
GetText.gettext(msgid)
GetText.N_(msgid)
GetText.setlocale(locale)
rgettext is the tool which create po-files from your Ruby Scripts.
$rgettext hoge.rb -o hoge.po
For example, write hello.rb as follows.
require 'gettext' include GetText bindtextdomain("hello") print _("Hello World\n")
Create a po-file with rgettext.
$rgettext hello.rb -o hello.pot
This example for Japanese(not 2-byte string but 1-byte alphabet).
$cp hello.pot ja.po
Then edit ja.po as follows.
#: ../hello.rb:7 msgid "Hello World\n" msgstr "KON-NICHI-WA SEKAI\n"
In addition, you can use the some tools in GNU gettext package for maintainig po-file.
GetText.N_(msgid) is used with GetText._(msgid).
require 'gettext' include GetText bindtextdomain("hello_noop") msgs = [N_("Hello World"), N_("Hello World2")] msgs.each do |msg| print _(msg), "\n" end
In this case, rgettext can not recognize _(msg) as msgid.
But since you use GetText.N_(msgid) to define the messages, it is recognized as msgid by rgettext.
If po-file have some fuzzy comments as follows:
#: hello.rb:7 #, fuzzy msgid "Hello World" msgstr "KON-NICHI-WA SEKAI"
Then confirm the messages(msgid and msgstr) are correct, and remove "fuzzy" line.
#: hello.rb:7 msgid "Hello World" msgstr "KON-NICHI-WA SEKAI"
Finally, you make a mo-file, and put it into a path properly.
In this example, you don't set path in bindtextdomain(), GetText search mo-file in /usr/share/locale/#{lang}/LC_MESSAGES/ or /usr/local/share/locale/#{lang}/LC_MESSAGES/. So you put it into one of them.
Here, you put it into /usr/local/share/locale/ja/LC_MESSAGES/.
$msgfmt ja.po -o /usr/local/share/locale/ja/LC_MESSAGES/
$ruby hello.rb
Is it OK? Congratulations!
If you can't show the messages in your language, execute it with -d option.
$ruby -d hello.rb Search path:["/usr/share/locale", "/usr/local/share/locale"] locale:"ja_JP.eucJP" MO file is not found in /usr/share/locale/ja_JP.eucJP/LC_MESSAGES/hello.mo /usr/share/locale/ja_JP/LC_MESSAGES/hello.mo /usr/share/locale/ja/LC_MESSAGES/hello.mo /usr/local/share/locale/ja_JP.eucJP/LC_MESSAGES/hello.mo /usr/local/share/locale/ja_JP/LC_MESSAGES/hello.mo /usr/local/share/locale/ja/LC_MESSAGES/hello.mo
Check hello.mo is in one of those pathes.
This program is licenced under the same licence as Ruby.
(See the file 'COPYING'.)
Copyright (C) 2001 Masahiro Sakai <s01397ms@sfc.keio.ac.jp>
Copyright (C) 2001,2002 Masahiro Sakai <s01397ms@sfc.keio.ac.jp>, Masao Mutoh <mutoh@highwhay.ne.jp>
Copyright (C) 2001,2002 Yasushi Shoji <yashi@yashi.com>, Masao Mutoh <mutoh@highwhay.ne.jp>
Copyright (C) 2000,2001 Minero Aoki <aamine@loveruby.net>
This file is released under LGPL. See the top of the install.rb.
Copyright (C) 2001,2002 Masao Mutoh <mutoh@highwhay.ne.jp>
Masao Mutoh <mutoh@highway.ne.jp>
2002-02-22 Masao Mutoh <mutoh@highway.ne.jp>
2002-02-21 Masao Mutoh <mutoh@highway.ne.jp>
2002-02-13 Masao Mutoh <mutoh@highway.ne.jp>
2002-02-03 Masao Mutoh <mutoh@highway.ne.jp>
2002-01-06 Masao Mutoh <mutoh@highway.ne.jp>
2002-01-01 Masao Mutoh <mutoh@highway.ne.jp>
2001-12-24 Masao Mutoh <mutoh@highway.ne.jp>
$Id: ruby-gettext.rd,v 1.13 2002/02/22 14:15:35 mutoh Exp $