Module: I18n::Gettext::Helpers

Defined in:
lib/active_support/vendor/i18n-0.4.1/i18n/gettext/helpers.rb

Overview

Implements classical Gettext style accessors. To use this include the module to the global namespace or wherever you want to use it.

include I18n::Helpers::Gettext

Instance Method Summary collapse

Instance Method Details

#gettext(msgid, options = {}) ⇒ Object Also known as: _



11
12
13
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/gettext/helpers.rb', line 11

def gettext(msgid, options = {})
  I18n.t(msgid, { :default => msgid, :separator => '|' }.merge(options))
end

#ngettext(msgid, msgid_plural, n = 1) ⇒ Object Also known as: n_



28
29
30
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/gettext/helpers.rb', line 28

def ngettext(msgid, msgid_plural, n = 1)
  nsgettext(msgid, msgid_plural, n)
end

#npgettext(msgctxt, msgid, msgid_plural, n = 1) ⇒ Object Also known as: np_

Method signatures:

npgettext('Fruits', 'apple', 'apples', 2)
npgettext('Fruits', ['apple', 'apples'], 2)


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/gettext/helpers.rb', line 51

def npgettext(msgctxt, msgid, msgid_plural, n = 1)
  separator = I18n::Gettext::CONTEXT_SEPARATOR

  if msgid.is_a?(Array)
    msgid_plural, msgid, n = msgid[1], [msgctxt, msgid[0]].join(separator), msgid_plural
  else
    msgid = [msgctxt, msgid].join(separator)
  end

  nsgettext(msgid, msgid_plural, n, separator)
end

#nsgettext(msgid, msgid_plural, n = 1, separator = '|') ⇒ Object Also known as: ns_

Method signatures:

nsgettext('Fruits|apple', 'apples', 2)
nsgettext(['Fruits|apple', 'apples'], 2)


36
37
38
39
40
41
42
43
44
45
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/gettext/helpers.rb', line 36

def nsgettext(msgid, msgid_plural, n = 1, separator = '|')
  if msgid.is_a?(Array)
    msgid, msgid_plural, n, separator = msgid[0], msgid[1], msgid_plural, n
    separator = '|' unless separator.is_a?(::String)
  end

  scope, msgid = I18n::Gettext.extract_scope(msgid, separator)
  default = { :one => msgid, :other => msgid_plural }
  I18n.t(msgid, :default => default, :count => n, :scope => scope, :separator => separator)
end

#pgettext(msgctxt, msgid) ⇒ Object Also known as: p_



22
23
24
25
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/gettext/helpers.rb', line 22

def pgettext(msgctxt, msgid)
  separator = I18n::Gettext::CONTEXT_SEPARATOR
  sgettext([msgctxt, msgid].join(separator), separator)
end

#sgettext(msgid, separator = '|') ⇒ Object Also known as: s_



16
17
18
19
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/gettext/helpers.rb', line 16

def sgettext(msgid, separator = '|')
  scope, msgid = I18n::Gettext.extract_scope(msgid, separator)
  I18n.t(msgid, :scope => scope, :default => msgid, :separator => separator)
end