diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-10-28 18:35:12 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-10-28 18:35:12 +0100 |
commit | a61c4dfa70892d21a96802398605880cfda75c90 (patch) | |
tree | 2c7fb683954ea14e826b2a28dc27eaf41ad178de /activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb | |
parent | 1df157cd38c9246a87f0643f78be7f8fdb5bb474 (diff) | |
download | rails-a61c4dfa70892d21a96802398605880cfda75c90.tar.gz rails-a61c4dfa70892d21a96802398605880cfda75c90.tar.bz2 rails-a61c4dfa70892d21a96802398605880cfda75c90.zip |
Follow style conventions
Diffstat (limited to 'activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb')
-rw-r--r-- | activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb index 30e3655b7b..1fd75de74f 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb @@ -10,7 +10,7 @@ module I18n # plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml # for details. def load_translations(*filenames) - filenames.each {|filename| load_file filename } + filenames.each { |filename| load_file(filename) } end # Stores translations for the given locale in memory. @@ -23,12 +23,12 @@ module I18n 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 + return key.map { |k| translate(locale, k, options) } if key.is_a? Array reserved = :scope, :default count, scope, default = options.values_at(:count, *reserved) options.delete(:default) - values = options.reject{|name, value| reserved.include? name } + values = options.reject { |name, value| reserved.include?(name) } entry = lookup(locale, key, scope) if entry.nil? @@ -37,8 +37,8 @@ module I18n raise(I18n::MissingTranslationData.new(locale, key, options)) end end - entry = pluralize locale, entry, count - entry = interpolate locale, entry, values + entry = pluralize(locale, entry, count) + entry = interpolate(locale, entry, values) entry end @@ -170,21 +170,21 @@ module I18n # for all other file extensions. def load_file(filename) type = File.extname(filename).tr('.', '').downcase - raise UnknownFileType.new(type, filename) unless respond_to? :"load_#{type}" + raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}") data = send :"load_#{type}", filename # TODO raise a meaningful exception if this does not yield a Hash - data.each{|locale, d| merge_translations locale, d } + data.each { |locale, d| merge_translations(locale, d) } end # Loads a plain Ruby translations file. eval'ing the file must yield # a Hash containing translation data with locales as toplevel keys. def load_rb(filename) - eval IO.read(filename), binding, filename + eval(IO.read(filename), binding, filename) end # Loads a YAML translations file. The data must have locales as # toplevel keys. def load_yml(filename) - YAML::load IO.read(filename) + YAML::load(IO.read(filename)) end # Deep merges the given translations hash with the existing translations @@ -192,16 +192,16 @@ module I18n def merge_translations(locale, data) locale = locale.to_sym translations[locale] ||= {} - data = deep_symbolize_keys data + data = deep_symbolize_keys(data) # deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809 - merger = proc{|key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 } - translations[locale].merge! data, &merger + merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 } + translations[locale].merge!(data, &merger) end # Return a new hash with all keys and nested keys converted to symbols. def deep_symbolize_keys(hash) - hash.inject({}){|result, (key, value)| + hash.inject({}) { |result, (key, value)| value = deep_symbolize_keys(value) if value.is_a? Hash result[(key.to_sym rescue key) || key] = value result @@ -209,4 +209,4 @@ module I18n end end end -end +end
\ No newline at end of file |