lib/gettext.rb in gettext-2.1.0 vs lib/gettext.rb in gettext-2.2.0
- old
+ new
@@ -1,9 +1,11 @@
+# encoding: utf-8
+
=begin
gettext.rb - GetText module
- Copyright (C) 2001-2009 Masao Mutoh
+ Copyright (C) 2001-2010 Masao Mutoh
Copyright (C) 2001-2003 Masahiro Sakai
Masao Mutoh <mutomasa at gmail.com>
Masahiro Sakai <s01397ms@sfc.keio.ac.jp>
@@ -12,11 +14,11 @@
=end
if Object.constants.include? "Gem"
begin
begin
- gem 'locale', '>=2.0.4'
+ gem 'locale', '>=2.0.5'
rescue Gem::LoadError
end
rescue NoMethodError
else LoadError
end
@@ -45,18 +47,18 @@
mod.extend self
end
# bindtextdomain(domainname, options = {})
#
- # Bind a textdomain(%{path}/%{locale}/LC_MESSAGES/%{domainname}.mo) to
+ # Bind a textdomain(%{path}/%{locale}/LC_MESSAGES/%{domainname}.mo) to
# your program.
- # Normally, the texdomain scope becomes the class/module(and parent
+ # Normally, the texdomain scope becomes the class/module(and parent
# classes/included modules).
#
# * domainname: the textdomain 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
+ # * :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.
#
@@ -66,11 +68,11 @@
# Includes GetText module and bind a textdomain to a class.
# * klass: the target ruby class.
# * domainname: the textdomain name.
# * options: options as an Hash. See GetText.bindtextdomain.
- def bindtextdomain_to(klass, domainname, *options)
+ def bindtextdomain_to(klass, domainname, *options)
if options[0].kind_of? Hash
opts = options[0]
else
# for backward compatibility.
opts = {}
@@ -81,21 +83,21 @@
klass.__send__(:include, GetText)
end
TextDomainManager.bind_to(klass, domainname, opts)
end
- # Binds a existed textdomain to your program.
+ # Binds a existed textdomain to your program.
# This is the same function with GetText.bindtextdomain but simpler(and faster) than bindtextdomain.
- # Note that you need to call GetText.bindtextdomain first. If the domainname hasn't bound yet,
+ # Note that you need to call GetText.bindtextdomain first. If the domainname hasn't bound yet,
# raises GetText::NoboundTextDomainError.
# * domainname: a textdomain name.
# * Returns: the GetText::TextDomainManager.
def textdomain(domainname) #:nodoc:
textdomain_to(self, domainname)
end
- # Includes GetText module and bind an exsited textdomain to a class.
+ # Includes GetText module and bind an exsited textdomain to a class.
# See textdomain for more detail.
# * klass: the target ruby class.
# * domainname: the textdomain name.
def textdomain_to(klass, domainname) #:nodoc:
@@ -107,17 +109,17 @@
# call-seq:
# gettext(msgid)
# _(msgid)
#
# Translates msgid and return the message.
- # This doesn't make a copy of 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.
+ # 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".
@@ -130,16 +132,16 @@
# call-seq:
# sgettext(msgid, div = '|')
# s_(msgid, div = '|')
#
- # Translates msgid, but if there are no localized text,
+ # 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,
+ # * Returns: the localized text by msgid. If there are no localized text,
# it returns a last part of the msgid separeted by "seperator".
# <tt>Movie|Location -> Location</tt>
# See: http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC151
def sgettext(msgid, seperator = "|")
TextDomainManager.translate_singluar_message(self, msgid, seperator)
@@ -153,11 +155,11 @@
# 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,
+ # * Returns: the localized text by msgid. If there are no localized text,
# it returns msgid.
# See: http://www.gnu.org/software/autoconf/manual/gettext/Contexts.html
def pgettext(msgctxt, msgid)
TextDomainManager.translate_singluar_message(self, "#{msgctxt}\004#{msgid}", "\004")
end
@@ -166,11 +168,11 @@
# ngettext(msgid, msgid_plural, n)
# ngettext(msgids, n) # msgids = [msgid, msgid_plural]
# n_(msgid, msgid_plural, n)
# n_(msgids, n) # msgids = [msgid, msgid_plural]
#
- # The ngettext is similar to the gettext function as it finds the message catalogs in the same way.
+ # 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.
@@ -185,11 +187,11 @@
# nsgettext(msgids, n, div = "|") # msgids = [msgid, msgid_plural]
# ns_(msgid, msgid_plural, n, div = "|")
# ns_(msgids, n, div = "|") # msgids = [msgid, msgid_plural]
#
# The nsgettext is similar to the ngettext.
- # But if there are no localized text,
+ # 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.
@@ -225,37 +227,37 @@
msgid_ctxt = "#{msgctxt}\004#{msgid}"
msgid_plural = arg2
opt1 = arg3
opt2 = nil
end
-
+
msgstr = TextDomainManager.translate_plural_message(self, msgid_ctxt, msgid_plural, opt1, opt2)
if msgstr == msgid_ctxt
msgid
else
msgstr
end
end
-
+
# makes dynamic translation messages readable for the gettext parser.
# <tt>_(fruit)</tt> cannot be understood by the gettext parser. To help the parser find all your translations,
# you can add <tt>fruit = N_("Apple")</tt> which does not translate, but tells the parser: "Apple" needs translation.
# * msgid: the message id.
# * Returns: msgid.
def N_(msgid)
msgid
end
- # This is same function as N_ but for ngettext.
+ # This is same function as N_ but for ngettext.
# * msgid: the message id.
# * msgid_plural: the plural message id.
# * Returns: msgid.
def Nn_(msgid, msgid_plural)
[msgid, msgid_plural]
end
- # Sets charset(String) such as "euc-jp", "sjis", "CP932", "utf-8", ...
+ # Sets charset(String) such as "euc-jp", "sjis", "CP932", "utf-8", ...
# You shouldn't use this in your own Libraries.
# * charset: an output_charset
# * Returns: self
def set_output_charset(charset)
TextDomainManager.output_charset = charset
@@ -275,12 +277,12 @@
Locale.set_app_language_tags(lang)
Locale.default = lang
Locale.current = lang
end
- # Set the locale to the current thread.
+ # 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)
+ # If you need, set_locale(nil); set_current_locale(lang)
def set_current_locale(lang)
Locale.current = lang
end
def locale