Method: GetText::TextDomain#translate_singluar_message
- Defined in:
- lib/gettext/runtime/textdomain.rb
#translate_singluar_message(lang, msgid) ⇒ Object
Translates the translated string.
-
lang: Locale::Tag::Simple’s subclass.
-
msgid: the original message.
-
Returns: the translated string or nil.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gettext/runtime/textdomain.rb', line 70 def (lang, msgid) return "" if msgid == "" or msgid.nil? lang_key = lang.to_s mofile = nil if self.class.cached? mofile = @mofiles[lang_key] end unless mofile mofile = load_mo(lang) end if (! mofile) or (mofile ==:empty) return nil end msgstr = mofile[msgid] if msgstr and (msgstr.size > 0) msgstr elsif msgid.include?("\000") # Check "aaa\000bbb" and show warning but return the singluar part. ret = nil msgid_single = msgid.split("\000")[0] mofile.each{|key, val| if key =~ /^#{Regexp.quote(msgid_single)}\000/ # Usually, this is not caused to make po-files from rgettext. warn %Q[Warning: n_("#{msgid_single}", "#{msgid.split("\000")[1]}") and n_("#{key.gsub(/\000/, '", "')}") are duplicated.] ret = val break end } ret else ret = nil mofile.each{|key, val| if key =~ /^#{Regexp.quote(msgid)}\000/ ret = val.split("\000")[0] break end } ret end end |