Gettext is a project mainly written in Ruby, based on the View license.
Ruby-GetText-Package is a Localization(L10n) library and tools which modeled after GNU gettext package.
= gettext - Ruby-GetText-Package
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 locale_rails[http://github.com/mutoh/locale_rails/tree/master], gettext_rails[http://github.com/mutoh/gettext_rails/tree/master] and gettext_activerecord[http://github.com/mutoh/gettext_activerecord/tree/master].
== Website
== Features
Translate singular/plural messages with simple APIs(similar to GNU gettext)
Thread safety. Message resources are shared from all threads, but returns translated messages of the current thread's locale.
Tools to find message IDs
Extract message IDs to po-files using rgettext from
rmsgfmt creates a mo-file from a po-file. The mo-file is compatible to GNU gettext(msgfmt).
Using rgettext/rmsgfmt as Rake tasks
textdomain's scope is adapt to ruby class/module mechanism.
CGI support (gettext/cgi)
String%() is extended to use named argument such as %{foo}" %{:foo => 1}. Notes that Ruby-1.9.x supports this format by itself.
== Requirements
== Install
Uninstall old gettext if exists. (You need to do this when updating 1.93.0 -> 2.0.1) (sudo/su on POSIX system) gem uninstall gettext
gem
(sudo/su on POSIX system) gem install gettext
download tar-ball
(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.
== Usage ===Translation
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)
=== Bind textdomains to the classes. A textdomain has a translation file in each language. A module/class can have multi textdomains. This means the libraries/applications can have their own textdomains.
class Foo include GetText bindtextdomain "your_app_domain_name" end
class Book include GetText bindtextdomain "general" bindtextdomain "book" end
=== Locale If you need to set the locale by yourself, then use: GetText.locale = "en_US" # translate into english from now on GetText.locale # => en_US Or include GetText set_locale "en_US"
For more details and options, have a look at the samples folder or consult the tutorial[http://www.yotabanana.com/hiki/ruby-gettext-howto.html].
== License This program is licenced under the same licence as Ruby(See COPYING) or LGPL(Lesser General Public License: http://www.gnu.org/licenses/lgpl-3.0.txt).
mofile.rb
gettext.rb
rgettext
setup.rb
Others
== Translators
== Status of translations
== Maintainer
Masao Mutoh