Method: GetText::TextDomainManager#translate_singluar_message

Defined in:
lib/gettext/runtime/textdomain_manager.rb

#translate_singluar_message(klass, msgid, div = nil) ⇒ Object

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”.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/gettext/runtime/textdomain_manager.rb', line 96

def translate_singluar_message(klass, msgid, div = nil)
  klass = ClassInfo.normalize_class(klass)
  key = [Locale.current, klass, msgid, div].hash
  msg = @@singular_message_cache[key]
  return msg if msg and @@cached
  # Find messages from related classes.
  each_textdomains(klass) do |textdomain, lang|
    msg = textdomain.translate_singluar_message(lang, msgid)
    break if msg
  end
  
  # If not found, return msgid.
  msg ||= msgid
  if div and msg == msgid
    if index = msg.rindex(div)
      msg = msg[(index + 1)..-1]
    end
  end
  @@singular_message_cache[key] = msg
end