Sha256: 92979452a897a6bedc29bcd71d25b552e2b474d310871c210eb8de4627d54385
Contents?: true
Size: 1.75 KB
Versions: 2
Compression:
Stored size: 1.75 KB
Contents
module I18n module Backend # Genderized backend. # Currently it is subclass of Advanced backend from # russian gem - it will be changed in naxt releases. class Genderized < Advanced # If entry is a hash and it includes given gender, # return entry for given gender. def genderize(locale, entry, gender) return entry unless entry.is_a?(Hash) and gender and entry.has_key?(gender.to_sym) entry[gender.to_sym] end def translate(locale, key, options = {}) raise InvalidLocale.new(locale) if locale.nil? return key.map{|k| translate locale, k, options } if key.is_a? Array reserved = :scope, :default, :gender count, scope, default, gender = options.values_at(:count, *reserved) options.delete(:default) values = options.reject{|name, value| reserved.include? name } entry = lookup(locale, key, scope) if entry.nil? entry = default(locale, default, options) if entry.nil? raise(I18n::MissingTranslationData.new(locale, key, options)) end end entry = genderize(locale, entry, gender) entry = pluralize locale, entry, count entry = interpolate locale, entry, values entry end def pluralize(locale, entry, count) return entry unless entry.is_a?(Hash) and count key = :zero if count == 0 && entry.has_key?(:zero) locale_pluralize = lookup(locale, :pluralize) if locale_pluralize && locale_pluralize.respond_to?(:call) key ||= locale_pluralize.call(count) else key ||= default_pluralizer(count) end return entry unless entry.has_key?(key) entry[key] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
drogus-genderized-0.0.3 | lib/genderized/backend/genderized.rb |
drogus-genderized-0.0.4 | lib/genderized/backend/genderized.rb |