5 # Implements classical Gettext style accessors. To use this include the
6 # module to the global namespace or wherever you want to use it.
8 # include I18n::Gettext::Helpers
10 def gettext(msgid, options = {})
11 I18n.t(msgid, { :default => msgid, :separator => '|' }.merge(options))
15 def sgettext(msgid, separator = '|')
16 scope, msgid = I18n::Gettext.extract_scope(msgid, separator)
17 I18n.t(msgid, :scope => scope, :default => msgid, :separator => separator)
21 def pgettext(msgctxt, msgid)
22 separator = I18n::Gettext::CONTEXT_SEPARATOR
23 sgettext([msgctxt, msgid].join(separator), separator)
27 def ngettext(msgid, msgid_plural, n = 1)
28 nsgettext(msgid, msgid_plural, n)
33 # nsgettext('Fruits|apple', 'apples', 2)
34 # nsgettext(['Fruits|apple', 'apples'], 2)
35 def nsgettext(msgid, msgid_plural, n = 1, separator = '|')
37 msgid, msgid_plural, n, separator = msgid[0], msgid[1], msgid_plural, n
38 separator = '|' unless separator.is_a?(::String)
41 scope, msgid = I18n::Gettext.extract_scope(msgid, separator)
42 default = { :one => msgid, :other => msgid_plural }
43 I18n.t(msgid, :default => default, :count => n, :scope => scope, :separator => separator)
48 # npgettext('Fruits', 'apple', 'apples', 2)
49 # npgettext('Fruits', ['apple', 'apples'], 2)
50 def npgettext(msgctxt, msgid, msgid_plural, n = 1)
51 separator = I18n::Gettext::CONTEXT_SEPARATOR
54 msgid_plural, msgid, n = msgid[1], [msgctxt, msgid[0]].join(separator), msgid_plural
56 msgid = [msgctxt, msgid].join(separator)
59 nsgettext(msgid, msgid_plural, n, separator)