From a61c4dfa70892d21a96802398605880cfda75c90 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 28 Oct 2008 18:35:12 +0100 Subject: Follow style conventions --- .../vendor/i18n-0.0.1/i18n/backend/simple.rb | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3 From d5b0ba66323062b54974fc224a909ffabf400a13 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 28 Oct 2008 19:28:51 +0100 Subject: Make I18n::Backend::Simple reload its translations in development mode [DHH] --- .../active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') 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 1fd75de74f..f34e880bfd 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 @@ -6,6 +6,10 @@ module I18n INTERPOLATION_RESERVED_KEYS = %w(scope default) MATCH = /(\\\\)?\{\{([^\}]+)\}\}/ + def initialize + Dispatcher.to_prepare { reload } + end + # Accepts a list of paths to translation files. Loads translations from # plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml # for details. @@ -69,8 +73,11 @@ module I18n @initialized ||= false end - protected + def reload + @initialized = false + end + protected def init_translations load_translations(*I18n.load_path) @initialized = true @@ -88,7 +95,7 @@ module I18n def lookup(locale, key, scope = []) return unless key init_translations unless initialized? - keys = I18n.send :normalize_translation_keys, locale, key, scope + keys = I18n.send(:normalize_translation_keys, locale, key, scope) keys.inject(translations) do |result, k| if (x = result[k.to_sym]).nil? return nil -- cgit v1.2.3 From 1b0afb31dfc71674b054459c2e0418ca3a709467 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 28 Oct 2008 19:38:26 +0100 Subject: A few more style changes --- activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb index 344c77aecf..9b0b69f58b 100755 --- a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb @@ -150,10 +150,10 @@ module I18n # I18n.t [:foo, :bar], :scope => :baz def translate(key, options = {}) locale = options.delete(:locale) || I18n.locale - backend.translate locale, key, options + backend.translate(locale, key, options) rescue I18n::ArgumentError => e raise e if options[:raise] - send @@exception_handler, e, locale, key, options + send(@@exception_handler, e, locale, key, options) end alias :t :translate @@ -180,8 +180,8 @@ module I18n # keys are Symbols. def normalize_translation_keys(locale, key, scope) keys = [locale] + Array(scope) + [key] - keys = keys.map{|k| k.to_s.split(/\./) } - keys.flatten.map{|k| k.to_sym} + keys = keys.map { |k| k.to_s.split(/\./) } + keys.flatten.map { |k| k.to_sym } end end end \ No newline at end of file -- cgit v1.2.3 From 4684e76aefca2c49d3421e7184a1d568e2cc0dac Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Tue, 28 Oct 2008 21:55:59 +0100 Subject: Remove reload call from vendored gem. Breaks a bunch of stuff as Dispatcher isn't always defined. This call will be moved into Dispatcher in a bit. --- .../lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'activesupport/lib') 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 f34e880bfd..c682eadf85 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 @@ -6,10 +6,6 @@ module I18n INTERPOLATION_RESERVED_KEYS = %w(scope default) MATCH = /(\\\\)?\{\{([^\}]+)\}\}/ - def initialize - Dispatcher.to_prepare { reload } - end - # Accepts a list of paths to translation files. Loads translations from # plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml # for details. -- cgit v1.2.3 From 4dbfe18b37ad4fa95eecb9082a446c798e84e499 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 29 Oct 2008 10:51:56 +0100 Subject: Proper API for reloading translations --- activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb | 7 +++++++ .../lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb index 9b0b69f58b..40e82d8225 100755 --- a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb @@ -67,6 +67,13 @@ module I18n def load_path=(load_path) @@load_path = load_path end + + # Tells the backend to reload translations. Used in situations like the + # Rails development environment. Backends can implement whatever strategy + # is useful. + def reload! + backend.reload! + end # Translates, pluralizes and interpolates a given key using a given locale, # scope, and default, as well as interpolation values. 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 c682eadf85..bdda55d3fe 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 @@ -69,8 +69,9 @@ module I18n @initialized ||= false end - def reload + def reload! @initialized = false + @translations = nil end protected -- cgit v1.2.3 From ea2545fd8dfcaafcf6eff58c0afe57c55e2c6317 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 30 Oct 2008 12:42:23 +0100 Subject: Update the default deprecation message to not promise that theres more info at the Rails site [#776 state:resolved] --- activesupport/lib/active_support/deprecation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb index 950bca60a6..b4d8f61b8c 100644 --- a/activesupport/lib/active_support/deprecation.rb +++ b/activesupport/lib/active_support/deprecation.rb @@ -51,8 +51,8 @@ module ActiveSupport private def deprecation_message(callstack, message = nil) - message ||= "You are using deprecated behavior which will be removed from Rails 2.0." - "DEPRECATION WARNING: #{message} See http://www.rubyonrails.org/deprecation for details. #{deprecation_caller_message(callstack)}" + message ||= "You are using deprecated behavior which will be removed from the next major or minor release." + "DEPRECATION WARNING: #{message}. #{deprecation_caller_message(callstack)}" end def deprecation_caller_message(callstack) -- cgit v1.2.3 From ef53d915164da7f757d03c4a70fe38e374c08b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= Date: Thu, 30 Oct 2008 18:45:30 +0200 Subject: Don't rely on string CoreExtensions in StringInquirer since it is sometimes expected to work before the core extension are loaded Signed-off-by: David Heinemeier Hansson --- activesupport/lib/active_support/string_inquirer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/string_inquirer.rb b/activesupport/lib/active_support/string_inquirer.rb index cd722a3cfb..e6b1f39225 100644 --- a/activesupport/lib/active_support/string_inquirer.rb +++ b/activesupport/lib/active_support/string_inquirer.rb @@ -11,7 +11,7 @@ module ActiveSupport # class StringInquirer < String def method_missing(method_name, *arguments) - if method_name.to_s.ends_with?("?") + if method_name.to_s[-1,1] == "?" self == method_name.to_s[0..-2] else super -- cgit v1.2.3 From e466ae13e9b6d901e3e39bb9ceeafd83e266ce81 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 31 Oct 2008 18:41:25 +0100 Subject: Fixed the option merging in Array#to_xml [#1126 state:resolved] --- activesupport/lib/active_support/core_ext/array/conversions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 11c128da22..cf3e03f62c 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -172,7 +172,7 @@ module ActiveSupport #:nodoc: else xml.tag!(root, options[:skip_types] ? {} : {:type => "array"}) { yield xml if block_given? - each { |e| e.to_xml(opts.merge!({ :skip_instruct => true })) } + each { |e| e.to_xml(opts.merge({ :skip_instruct => true })) } } end end -- cgit v1.2.3