# File lib/i18n/backend/gettext.rb, line 32 32: def load_po(filename) 33: locale = ::File.basename(filename, '.po').to_sym 34: data = normalize(locale, parse(filename)) 35: { locale => data } 36: end
# File lib/i18n/backend/gettext.rb, line 42 42: def normalize(locale, data) 43: data.inject({}) do |result, (key, value)| 44: unless key.nil? || key.empty? 45: key, value = normalize_pluralization(locale, key, value) if key.index("\0000") 46: 47: parts = key.split('|').reverse 48: normalized = parts.inject({}) do |normalized, part| 49: normalized = { part => normalized.empty? ? value : normalized } 50: end 51: 52: # deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809 53: merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 } 54: result.merge!(normalized, &merger) 55: end 56: result 57: end 58: end
# File lib/i18n/backend/gettext.rb, line 60 60: def normalize_pluralization(locale, key, value) 61: # FIXME po_parser includes \000 chars that can not be turned into Symbols 62: key = key.gsub("\0000", I18n::Gettext::PLURAL_SEPARATOR).split(I18n::Gettext::PLURAL_SEPARATOR).first 63: 64: keys = I18n::Gettext.plural_keys(locale) 65: values = value.split("\0000") 66: raise "invalid number of plurals: #{values.size}, keys: #{keys.inspect}" if values.size != keys.size 67: 68: result = {} 69: values.each_with_index { |value, ix| result[keys[ix]] = value } 70: [key, result] 71: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.