Module: I18n::Gettext::Helpers
- Defined in:
- lib/i18n/gettext/helpers.rb
Overview
Instance Method Summary collapse
- #gettext(msgid, options = EMPTY_HASH) ⇒ Object (also: #_)
-
#N_(msgsid) ⇒ Object
Makes dynamic translation messages readable for the gettext parser.
- #ngettext(msgid, msgid_plural, n = 1) ⇒ Object (also: #n_)
-
#npgettext(msgctxt, msgid, msgid_plural, n = 1) ⇒ Object
(also: #np_)
Method signatures: npgettext(‘Fruits’, ‘apple’, ‘apples’, 2) npgettext(‘Fruits’, [‘apple’, ‘apples’], 2).
-
#nsgettext(msgid, msgid_plural, n = 1, separator = '|') ⇒ Object
(also: #ns_)
Method signatures: nsgettext(‘Fruits|apple’, ‘apples’, 2) nsgettext([‘Fruits|apple’, ‘apples’], 2).
- #pgettext(msgctxt, msgid) ⇒ Object (also: #p_)
- #sgettext(msgid, separator = '|') ⇒ Object (also: #s_)
Instance Method Details
#gettext(msgid, options = EMPTY_HASH) ⇒ Object Also known as: _
21 22 23 |
# File 'lib/i18n/gettext/helpers.rb', line 21 def gettext(msgid, = EMPTY_HASH) I18n.t(msgid, { :default => msgid, :separator => '|' }.merge()) end |
#N_(msgsid) ⇒ Object
Makes dynamic translation messages readable for the gettext parser. _(fruit)
cannot be understood by the gettext parser. To help the parser find all your translations, you can add fruit = N_("Apple")
which does not translate, but tells the parser: “Apple” needs translation.
-
msgid: the message id.
-
Returns: msgid.
17 18 19 |
# File 'lib/i18n/gettext/helpers.rb', line 17 def N_(msgsid) msgsid end |
#ngettext(msgid, msgid_plural, n = 1) ⇒ Object Also known as: n_
38 39 40 |
# File 'lib/i18n/gettext/helpers.rb', line 38 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)
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/i18n/gettext/helpers.rb', line 61 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)
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/i18n/gettext/helpers.rb', line 46 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_
32 33 34 35 |
# File 'lib/i18n/gettext/helpers.rb', line 32 def pgettext(msgctxt, msgid) separator = I18n::Gettext::CONTEXT_SEPARATOR sgettext([msgctxt, msgid].join(separator), separator) end |
#sgettext(msgid, separator = '|') ⇒ Object Also known as: s_
26 27 28 29 |
# File 'lib/i18n/gettext/helpers.rb', line 26 def sgettext(msgid, separator = '|') scope, msgid = I18n::Gettext.extract_scope(msgid, separator) I18n.t(msgid, :scope => scope, :default => msgid, :separator => separator) end |