bind textdomain to the class.
# File lib/gettext/runtime/textdomain_manager.rb, line 65 65: def bind_to(klass, domainname, options = {}) 66: warn "Bind the domain '#{domainname}' to '#{klass}'. " if $DEBUG 67: 68: charset = options[:output_charset] || self.output_charset 69: textdomain = create_or_find_textdomain(domainname,options[:path],charset) 70: target_klass = ClassInfo.normalize_class(klass) 71: create_or_find_textdomain_group(target_klass).add(textdomain) 72: @@gettext_classes << target_klass unless @@gettext_classes.include? target_klass 73: 74: textdomain 75: end
Set the value whether cache messages or not. true to cache messages, otherwise false.
Default is true. If $DEBUG is false, messages are not checked even if this value is true.
# File lib/gettext/runtime/textdomain_manager.rb, line 41 41: def cached=(val) 42: @@cached = val 43: TextDomain.cached = val 44: end
Return the cached value.
# File lib/gettext/runtime/textdomain_manager.rb, line 47 47: def cached? 48: TextDomain.cached? 49: end
for testing.
# File lib/gettext/runtime/textdomain_manager.rb, line 184 184: def clear_all_textdomains 185: @@textdomain_pool = {} 186: @@textdomain_group_pool = {} 187: @@gettext_classes = [] 188: clear_caches 189: end
for testing.
# File lib/gettext/runtime/textdomain_manager.rb, line 192 192: def clear_caches 193: @@singular_message_cache = {} 194: @@plural_message_cache = {} 195: end
Gets the output charset.
# File lib/gettext/runtime/textdomain_manager.rb, line 52 52: def output_charset 53: @@output_charset 54: end
Sets the output charset.The program can have a output charset.
# File lib/gettext/runtime/textdomain_manager.rb, line 57 57: def output_charset=(charset) 58: @@output_charset = charset 59: @@textdomain_pool.each do |key, textdomain| 60: textdomain.output_charset = charset 61: end 62: end
Find textdomain by name
# File lib/gettext/runtime/textdomain_manager.rb, line 32 32: def textdomain_pool(domainname) 33: @@textdomain_pool[domainname] 34: end
This function is similar to the get_singluar_message function as it finds the message catalogs in the same way. But it takes two extra arguments for plural form. The msgid parameter must contain the singular form of the string to be converted. It is also used as the key for the search in the catalog. The msgid_plural parameter is the plural form. The parameter n is used to determine the plural form. If no message catalog is found msgid1 is returned if n == 1, otherwise msgid2. And if msgid includes “div”, it returns a last part of msgid separeted “div”.
msgid: the singular form with “div”. (e.g. “Special|An apple”, “An apple”)
msgid_plural: the plural form. (e.g. “%{num} Apples”)
n: a number used to determine the plural form.
div: the separator. Default is “|”.
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.
or
: msgid and msgid_plural an Array
n: a number used to determine the plural form.
div: the separator. Default is “|”.
# File lib/gettext/runtime/textdomain_manager.rb, line 139 139: def translate_plural_message(klass, arg1, arg2, arg3 = "|", arg4 = "|") 140: klass = ClassInfo.normalize_class(klass) 141: # parse arguments 142: if arg1.kind_of?(Array) 143: msgid = arg1[0] 144: msgid_plural = arg1[1] 145: n = arg2 146: if arg3 and arg3.kind_of? Numeric 147: raise ArgumentError, _("3rd parmeter is wrong: value = %{number}") % {:number => arg3} 148: end 149: div = arg3 150: else 151: msgid = arg1 152: msgid_plural = arg2 153: n = arg3 154: div = arg4 155: end 156: 157: key = [Locale.current, klass, msgid, msgid_plural, div].hash 158: msgs = @@plural_message_cache[key] 159: unless (msgs and @@cached) 160: # Find messages from related classes. 161: msgs = nil 162: each_textdomains(klass) do |textdomain, lang| 163: msgs = textdomain.translate_plural_message(lang, msgid, msgid_plural) 164: break if msgs 165: end 166: 167: msgs = [[msgid, msgid_plural], TextDomain::DEFAULT_PLURAL_CALC] unless msgs 168: 169: msgstrs = msgs[0] 170: if div and msgstrs[0] == msgid and index = msgstrs[0].rindex(div) 171: msgstrs[0] = msgstrs[0][(index + 1)..1] 172: end 173: @@plural_message_cache[key] = msgs 174: end 175: 176: # Return the singular or plural message. 177: msgstrs = msgs[0] 178: plural = msgs[1].call(n) 179: return msgstrs[plural] if plural.kind_of?(Numeric) 180: return plural ? msgstrs[1] : msgstrs[0] 181: end
Translates msgid, but if there are no localized text, it returns a last part of msgid separeted “div” or whole of the msgid with no “div”.
msgid: the message id.
div: separator or nil.
Returns: the localized text by msgid. If there are no localized text, it returns a last part of msgid separeted “div”.
# File lib/gettext/runtime/textdomain_manager.rb, line 96 96: def translate_singluar_message(klass, msgid, div = nil) 97: klass = ClassInfo.normalize_class(klass) 98: key = [Locale.current, klass, msgid, div].hash 99: msg = @@singular_message_cache[key] 100: return msg if msg and @@cached 101: # Find messages from related classes. 102: each_textdomains(klass) do |textdomain, lang| 103: msg = textdomain.translate_singluar_message(lang, msgid) 104: break if msg 105: end 106: 107: # If not found, return msgid. 108: msg ||= msgid 109: if div and msg == msgid 110: if index = msg.rindex(div) 111: msg = msg[(index + 1)..1] 112: end 113: end 114: @@singular_message_cache[key] = msg 115: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.