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
# File lib/i18n/gettext/helpers.rb, line 11 11: def gettext(msgid, options = {}) 12: I18n.t(msgid, { :default => msgid, :separator => '|' }.merge(options)) 13: end
# File lib/i18n/gettext/helpers.rb, line 28 28: def ngettext(msgid, msgid_plural, n = 1) 29: nsgettext(msgid, msgid_plural, n) 30: end
Method signatures:
npgettext('Fruits', 'apple', 'apples', 2) npgettext('Fruits', ['apple', 'apples'], 2)
# File lib/i18n/gettext/helpers.rb, line 51 51: def npgettext(msgctxt, msgid, msgid_plural, n = 1) 52: separator = I18n::Gettext::CONTEXT_SEPARATOR 53: 54: if msgid.is_a?(Array) 55: msgid_plural, msgid, n = msgid[1], [msgctxt, msgid[0]].join(separator), msgid_plural 56: else 57: msgid = [msgctxt, msgid].join(separator) 58: end 59: 60: nsgettext(msgid, msgid_plural, n, separator) 61: end
Method signatures:
nsgettext('Fruits|apple', 'apples', 2) nsgettext(['Fruits|apple', 'apples'], 2)
# File lib/i18n/gettext/helpers.rb, line 36 36: def nsgettext(msgid, msgid_plural, n = 1, separator = '|') 37: if msgid.is_a?(Array) 38: msgid, msgid_plural, n, separator = msgid[0], msgid[1], msgid_plural, n 39: separator = '|' unless separator.is_a?(::String) 40: end 41: 42: scope, msgid = I18n::Gettext.extract_scope(msgid, separator) 43: default = { :one => msgid, :other => msgid_plural } 44: I18n.t(msgid, :default => default, :count => n, :scope => scope, :separator => separator) 45: end
# File lib/i18n/gettext/helpers.rb, line 22 22: def pgettext(msgctxt, msgid) 23: separator = I18n::Gettext::CONTEXT_SEPARATOR 24: sgettext([msgctxt, msgid].join(separator), separator) 25: end
# File lib/i18n/gettext/helpers.rb, line 16 16: def sgettext(msgid, separator = '|') 17: scope, msgid = I18n::Gettext.extract_scope(msgid, separator) 18: I18n.t(msgid, :scope => scope, :default => msgid, :separator => separator) 19: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.