Module GetText
In: lib/gettext.rb
lib/gettext/po.rb
lib/gettext/po_entry.rb
lib/gettext/cgi.rb
lib/gettext/mo.rb
lib/gettext/po_format.rb
lib/gettext/version.rb
lib/gettext/class_info.rb
lib/gettext/text_domain_group.rb
lib/gettext/tools/msginit.rb
lib/gettext/tools/parser/glade.rb
lib/gettext/tools/parser/ruby.rb
lib/gettext/tools/parser/erb.rb
lib/gettext/tools/parser/haml.rb
lib/gettext/tools/xgettext.rb
lib/gettext/tools/msgmerge.rb
lib/gettext/tools/msgfmt.rb
lib/gettext/tools/task.rb
lib/gettext/tools/msgcat.rb
lib/gettext/locale_path.rb
lib/gettext/text_domain_manager.rb
lib/gettext/po_parser.rb
lib/gettext/text_domain.rb

Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>

License: Ruby‘s or LGPL

This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Methods

Classes and Modules

Module GetText::ClassInfo
Module GetText::HamlParser
Module GetText::POEntryForRubyParser
Module GetText::POFormat
Module GetText::TextDomainManager
Module GetText::Tools
Class GetText::ErbParser
Class GetText::GladeParser
Class GetText::LocalePath
Class GetText::MO
Class GetText::NoboundTextDomainError
Class GetText::PO
Class GetText::POEntry
Class GetText::POParser
Class GetText::ParseError
Class GetText::RubyParser
Class GetText::TextDomain
Class GetText::TextDomainGroup

Constants

VERSION = "3.2.9"

Public Instance methods

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.

  • msgid: the message id.
  • Returns: msgid.

This is same function as N_ but for ngettext.

  • msgid: the message id.
  • msgid_plural: the plural message id.
  • Returns: msgid.
_(msgid)

Alias for gettext

bindtextdomain(domainname, options = {})

Bind a text domain(%{path}/%{locale}/LC_MESSAGES/%{domainname}.mo) to your program. Normally, the texdomain scope becomes the class/module(and parent classes/included modules).

  • domainname: the text domain name.
  • options: options as an Hash.
    • :path - the path to the mo-files. When the value is nil, it will search default paths such as /usr/share/locale, /usr/local/share/locale)
    • :output_charset - The output charset. Same with GetText.set_output_charset. Usually, L10n library doesn‘t use this option. Application may use this once.
  • Returns: the GetText::TextDomainManager.

Includes GetText module and bind a text domain to a class.

  • klass: the target ruby class.
  • domainname: the text domain name.
  • options: options as an Hash. See GetText.bindtextdomain.

Gets the CGI object. If it is nil, returns new CGI object. This methods is appeared when requiring "gettext/cgi".

  • Returns: the CGI object

Same as GetText.set_cgi. This methods is appeared when requiring "gettext/cgi".

  • cgi_: CGI object
  • Returns: cgi_
current_locale=(lang)

Alias for set_current_locale

Translates msgid and return the message. This doesn‘t make a copy of the message.

You need to use String#dup if you want to modify the return value with destructive functions.

(e.g.1) _("Hello ").dup << "world"

But e.g.1 should be rewrite to:

(e.g.2) _("Hello %{val}") % {:val => "world"}

Because the translator may want to change the position of "world".

  • msgid: the message id.
  • Returns: localized text by msgid. If there are not binded mo-file, it will return msgid.
locale=(lang)

Alias for set_locale

n_(msgid, msgid_plural, n = nil)

Alias for ngettext

The ngettext is similar to the gettext function as it finds the message catalogs in the same way. But it takes two extra arguments for plural form.

  • msgid: the singular form.
  • msgid_plural: the plural form.
  • n: a number used to determine the plural form.
  • Returns: the localized text which key is msgid_plural if n is plural(follow plural-rule) or msgid. "plural-rule" is defined in po-file.
np_(msgctxt, msgids, arg2 = nil, arg3 = nil)

Alias for npgettext

The npgettext is similar to the nsgettext function.

  e.g.) np_("Special", "An apple", "%{num} Apples", num) == ns_("Special|An apple", "%{num} Apples", num)
  • msgctxt: the message context.
  • msgid: the singular form.
  • msgid_plural: the plural form.
  • n: a number used to determine the plural form.
  • Returns: the localized text which key is msgid_plural if n is plural(follow plural-rule) or msgid. "plural-rule" is defined in po-file.
ns_(msgid, msgid_plural, n="|", seperator = "|")

Alias for nsgettext

The nsgettext is similar to the ngettext. But if there are no localized text, it returns a last part of msgid separeted "div".

  • msgid: the singular form with "div". (e.g. "Special|An apple")
  • msgid_plural: the plural form. (e.g. "%{num} Apples")
  • n: a number used to determine the plural form.
  • Returns: the localized text which key is msgid_plural if n is plural(follow plural-rule) or msgid. "plural-rule" is defined in po-file.

Gets the current output_charset which is set using GetText.set_output_charset.

output_charset=(charset)

Alias for set_output_charset

p_(msgctxt, msgid)

Alias for pgettext

Translates msgid with msgctxt. This methods is similer with s_().

 e.g.) p_("File", "New")   == s_("File|New")
       p_("File", "Open")  == s_("File|Open")
  • msgctxt: the message context.
  • msgid: the message id.
  • Returns: the localized text by msgid. If there are no localized text, it returns msgid.

See: www.gnu.org/software/autoconf/manual/gettext/Contexts.html

s_(msgid, seperator = "|")

Alias for sgettext

Sets a CGI object. This methods is appeared when requiring "gettext/cgi".

  • cgi_: CGI object
  • Returns: self

Set the locale to the current thread. Note that if set_locale is set, this value is ignored. If you need, set_locale(nil); set_current_locale(lang)

Set the locale. This value forces the locale whole the programs. This method calls Locale.set_app_language_tags, Locale.default, Locale.current. Use Locale methods if you need to handle locales more flexible.

Sets charset(String) such as "euc-jp", "sjis", "CP932", "utf-8", … You shouldn‘t use this in your own Libraries.

Translates msgid, but if there are no localized text, it returns a last part of msgid separeted "div".

  • msgid: the message id.
  • separator: separator or nil for no seperation.
  • Returns: the localized text by msgid. If there are no localized text, it returns a last part of the msgid separeted by "seperator". Movie|Location -> Location

See: www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC151

[Validate]