Ruby-GetText-Package is a Localization(L10n) library and tools which modeled after GNU gettext package.
Pull request Compare This branch is 3 commits ahead, 121 commits behind mutoh:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Ruby-GetText-Package is a Localization(L10n) library and tool which is modeled after the GNU gettext package.

This library translates original messages to localized messages using client-side locale information(environment variable or CGI variable).

The tools for developers support creating, useing, and modifying localized message files(message catalogs).

((Rails)) Rails support has been removed. Rails / ActiveRecord specific code now lives in gettext_rails and gettext_activerecord.



  • Simple APIs(similar to GNU gettext)

  • rgettext creates po-files from

    • ruby scripts

    • glade-2 XML file(.glade)

    • ERB file(.rhtml, .erb)

    • Anything (with your own parsers)

    • The po-files are compatible to GNU gettext.

  • rmsgfmt creates a mo-file from a po-file. The mo-file is compatible to GNU gettext(msgfmt).

  • textdomain's scope is adapt to ruby class/module mechanism.

    • A class/module can have plural textdomains.

    • a message is looked up in its class/module and ancestors.

  • CGI support (gettext/cgi)

    • Locale is retrieved from client informations (HTTP_ACCEPT_LANGUAGE, HTTP_ACCEPT_CHARSET, QUERY_STRING(lang), Cookies(lang)).

  • String%() is extended to use named argument such as %{foo}" %{:foo => 1}. Notes that Ruby-1.9.x supports this format by itself.



  • Uninstall old gettext if exists.

    (sudo/su on POSIX system)
    gem uninstall gettext
  • gem

    #from github (edge/unstable)
    (sudo/su on POSIX system)
    gem install locale
    gem install mutoh-gettext -s
    #from rubyforge (stable)
    (sudo/su on POSIX system)
    gem install locale
    gem install gettext
  • download tar-ball

    # De-Compress archive and enter its top directory.
    (sudo/su on POSIX system)
    ruby setup.rb

You can also install files in your favorite directory by supplying setup.rb some options. Try ruby setup.rb --help.



  • _: Basic translation method Translates the message.


The gettext methods comes in 3 combinable flavors

  • n: Pluralized Returns singular or plural form, depending on how many you have.

    n_("Apple", "%{num} Apples", 3)
    n_(["Apple", "%{num} Apples"], 3)
  • p: context aware A context is a prefix to your translation, usefull when one word has different meanings, depending on its context.

    p_("Printer","Open") <=> p_("File","Open")
    is the same as s_("Printer|Open")  <=> s_("File|Open")
  • s: without context If a translation could not be found, return the msgid without context.

    s_("Printer|Open") => "Öffnen" #translation found
    s_("Printer|Open") => "Open"   #translation not found
  • combinations

    np_("Fruit", "Apple", "%{num} Apples", 3)
    ns_("Fruit|Apple","%{num} Apples", 3)
    np_(["Fruit","Apple","%{num} Apples"], 3)
    ns_(["Fruit|Apple","%{num} Apples"], 3)
  • N_, Nn_: Makes dynamic translation messages readable for the gettext parser. _(fruit) cannot be understood by the gettext parser. To help the parser find all your translations, you can add fruit = N_("Apple") which does not translate, but tells the parser: “Apple” needs translation.

    fruit = N_("Apple")   # same as fruit = "Apple"
    _(fruit)              # does a normal translation
    fruits = Nn_("Apple", "%{num} Apples")
    n_(fruits, 3)

Locale / Domain

GetText stores the locale your are using

GetText.locale = "en_US" # translate into english from now on
GetText.locale # => en_US


include GetText
set_locale "en_US"

Each locale can have different sets of translations (text domains) (e.g. Financial terms + Human-resource terms)



include GetText

For more details and options, have a look at the samples folder or consult the tutorial.


This program is licenced under the same licence as Ruby. (See the file 'COPYING'.)

  • mofile.rb

    • Copyright (C) 2001-2009 Masao Mutoh <mutoh at>

    • Copyright (C) 2001,2002 Masahiro Sakai <s01397ms at>

  • gettext.rb

    • Copyright (C) 2001-2009 Masao Mutoh <mutoh at>

    • Copyright (C) 2001,2002 Masahiro Sakai <s01397ms at>

  • rgettext

    • Copyright (C) 2001-2009 Masao Mutoh <mutoh at>

    • Copyright (C) 2001,2002 Yasushi Shoji <yashi at>

  • setup.rb

    • Copyright (C) 2000-2005 Minero Aoki <aamine at>

    • This file is released under LGPL. See the top of the install.rb.

  • Others

    • Copyright (C) 2001-2009 Masao Mutoh <mutoh at>


  • Bosnian(bs) - Sanjin Sehic <saserr at>

  • Bulgarian(bg) - Sava Chankov <sava.chankov at>

  • Catalan(ca) - Ramon Salvadó <rsalvado at>

  • Chinese(Simplified)(zh_CN)

    • Yang Bob < at> (current)

    • Yingfeng <blogyingfeng at>

  • Chinese(Traditional)(zh_TW)

    • Yang Bob < at> (current)

    • LIN CHUNG-YI <xmarsh at>

  • Croatian(hr) - Sanjin Sehic <saserr at>

  • Czech(cs) - Karel Miarka <kajism at>

  • Dutch(nl) - Menno Jonkers <ruby-gettext at>

  • Esperanto(eo) - Malte Milatz <malte at>

  • Estonian(et) - Erkki Eilonen <erkki at>

  • French(fr)

    • Vincent Isambart <vincent.isambart at> (current)

    • David Sulc <davidsulc at>

    • Laurent Sansonetti <laurent.sansonetti at>

  • German(de)

    • Patrick Lenz <patrick at> (current)

    • Detlef Reichl <detlef.reichl at>

    • Sven Herzberg <herzi at>

    • Sascha Ebach <se at>

  • Greek(el) - Vassilis Rizopoulos <damphyr at>

  • Hungarian(hu) - Tamás Tompa <tompata at>

  • Italian(it)

    • Marco Lazzeri <marco.lazzeri at>

    • Gabriele Renzi <surrender_it at>

  • Japanese(ja) - Masao Mutoh <mutoh at>

  • Korean(ko) - Gyoung-Yoon Noh <nohmad at>

  • Latvian(lv) - Aivars Akots <aivars.akots at>

  • Norwegian(nb) - Runar Ingebrigtsen <runar at>

  • Portuguese(Brazil)(pt_BR)

    • Antonio S. de A. Terceiro <terceiro at> (current)

    • Joao Pedrosa <joaopedrosa at>

  • Russian(ru) - Yuri Kozlov <kozlov.y at>

  • Serbian(sr) - Slobodan Paunović“ <slobodan.paunovic at>

  • Spanish(es)

    • David Espada <davinci at> (current)

    • David Moreno Garza <damog at>

  • Swedish(sv) - Nikolai Weibull <mailing-lists.ruby-talk at>

  • Ukrainian(ua) - Alex Rootoff <rootoff at>

  • Vietnamese(vi) - Ngoc Dao Thanh <ngocdaothanh at>

Status of translations

  • Bosnian(bs) - 1.90.0 (old)

  • Bulgarian(bg) - 2.0.0pre1 (new)

  • Catalan(ca) - 2.0.0pre1

  • Croatian(hr) - 1.90.0 (old)

  • Chinese(zh_CN) - 2.0.0pre1

  • Chinese(zh_TW) - 2.0.0pre1

  • Czech(cs) - 1.9.0 (old)

  • Dutch(nl) - 1.90.0 (old)

  • English(default) - 1.90.0 (old)

  • Esperanto(eo) - 2.0.0pre1

  • Estonian(et) - 2.0.0pre1

  • French(fr) - 2.0.0pre1

  • German(de) - 2.0.0pre1

  • Greek(el) - 2.0.0pre1

  • Hungarian(hu) - 2.0.0pre1

  • Italian(it) - 1.6.0 (old)

  • Japanese(ja) - 2.0.0pre1

  • Korean(ko) - 1.9.0 (old)

  • Latvian(lv) - 2.0.0pre1 (new)

  • Norwegian(nb) - 2.0.0pre1

  • Portuguese(Brazil)(pt_BR) - 2.0.0pre1

  • Russian(ru) - 2.0.0pre1

  • Serbian(sr) - 1.91.0 (old)

  • Spanish(es) - 2.0.0pre1

  • Swedish(sv) - 0.8.0 (too much old)

  • Ukrainian(ua) - 2.0.0pre1

  • Vietnamese(vi) - 2.0.0pre1


Masao Mutoh <mutoh at>