Method: GetText::TextDomainManager#translate_singular_message

Defined in:
lib/gettext/text_domain_manager.rb

#translate_singular_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".


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

def translate_singular_message(klass, msgid, div = nil)
  klass = ClassInfo.normalize_class(klass)
  key = [Locale.current, klass, msgid, div]
  msg = @@singular_message_cache[key]
  return msg if msg and @@cached
  # Find messages from related classes.
  each_text_domains(klass) do |text_domain, lang|
    msg = text_domain.translate_singular_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