Module: I18n::Helpers::Gettext

Defined in:
lib/i18n/helpers/gettext.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

#_(msgid, options = {}) ⇒ Object



8
9
10
# File 'lib/i18n/helpers/gettext.rb', line 8

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

#ngettext(msgid, msgid_plural, n = 1) ⇒ Object



21
22
23
# File 'lib/i18n/helpers/gettext.rb', line 21

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

#nsgettext(msgid, msgid_plural, n = 1, separator = nil) ⇒ Object



25
26
27
28
29
30
# File 'lib/i18n/helpers/gettext.rb', line 25

def nsgettext(msgid, msgid_plural, n = 1, separator = nil)
  scope, msgid = I18n::Gettext.extract_scope(msgid, separator)
  default = { :one => msgid, :other => msgid_plural }
  msgid = [msgid, I18n::Gettext::PLURAL_SEPARATOR, msgid_plural].join
  I18n.t(msgid, :default => default, :count => n, :scope => scope)
end

#pgettext(msgctxt, msgid, separator = I18n::Gettext::CONTEXT_SEPARATOR) ⇒ Object



17
18
19
# File 'lib/i18n/helpers/gettext.rb', line 17

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

#sgettext(msgid, separator = '|') ⇒ Object



12
13
14
15
# File 'lib/i18n/helpers/gettext.rb', line 12

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