2010-01-22 14:44:29 -05:00
|
|
|
require "active_support"
|
|
|
|
require "rails"
|
|
|
|
|
2010-01-24 19:06:12 -05:00
|
|
|
module ActiveSupport
|
|
|
|
class Railtie < Rails::Railtie
|
2010-03-26 13:47:55 -04:00
|
|
|
config.active_support = ActiveSupport::OrderedOptions.new
|
2010-01-24 19:06:12 -05:00
|
|
|
|
|
|
|
# Loads support for "whiny nil" (noisy warnings when methods are invoked
|
|
|
|
# on +nil+ values) if Configuration#whiny_nils is true.
|
2010-01-26 15:05:50 -05:00
|
|
|
initializer "active_support.initialize_whiny_nils" do |app|
|
2010-01-24 19:06:12 -05:00
|
|
|
require 'active_support/whiny_nil' if app.config.whiny_nils
|
|
|
|
end
|
|
|
|
|
|
|
|
# Sets the default value for Time.zone
|
|
|
|
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
|
2010-01-26 15:05:50 -05:00
|
|
|
initializer "active_support.initialize_time_zone" do |app|
|
2010-01-24 19:06:12 -05:00
|
|
|
require 'active_support/core_ext/time/zones'
|
|
|
|
zone_default = Time.__send__(:get_zone, app.config.time_zone)
|
|
|
|
|
|
|
|
unless zone_default
|
|
|
|
raise \
|
|
|
|
'Value assigned to config.time_zone not recognized.' +
|
|
|
|
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
|
|
|
|
end
|
|
|
|
|
|
|
|
Time.zone_default = zone_default
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-22 19:29:29 -05:00
|
|
|
module I18n
|
|
|
|
class Railtie < Rails::Railtie
|
2010-03-26 13:47:55 -04:00
|
|
|
config.i18n = ActiveSupport::OrderedOptions.new
|
2010-02-20 09:46:55 -05:00
|
|
|
config.i18n.railties_load_path = []
|
2010-01-22 19:29:29 -05:00
|
|
|
config.i18n.load_path = []
|
2010-04-16 16:16:21 -04:00
|
|
|
config.i18n.fallbacks = ActiveSupport::OrderedOptions.new
|
2010-01-22 19:29:29 -05:00
|
|
|
|
2010-01-26 15:05:50 -05:00
|
|
|
initializer "i18n.initialize" do
|
2010-03-29 20:08:08 -04:00
|
|
|
ActiveSupport.on_load(:i18n) do
|
2010-01-22 19:29:29 -05:00
|
|
|
I18n.reload!
|
2010-03-07 09:24:30 -05:00
|
|
|
|
|
|
|
ActionDispatch::Callbacks.to_prepare do
|
|
|
|
I18n.reload!
|
|
|
|
end
|
2010-01-22 19:29:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Set the i18n configuration from config.i18n but special-case for
|
|
|
|
# the load_path which should be appended to what's already set instead of overwritten.
|
|
|
|
config.after_initialize do |app|
|
|
|
|
app.config.i18n.each do |setting, value|
|
2010-01-25 16:00:07 -05:00
|
|
|
case setting
|
2010-02-20 09:46:55 -05:00
|
|
|
when :railties_load_path
|
2010-01-25 16:00:07 -05:00
|
|
|
app.config.i18n.load_path.unshift(*value)
|
|
|
|
when :load_path
|
2010-01-22 19:29:29 -05:00
|
|
|
I18n.load_path += value
|
2010-04-16 16:16:21 -04:00
|
|
|
when :fallbacks
|
|
|
|
init_fallbacks(value) if value && validate_fallbacks(value)
|
2010-01-22 19:29:29 -05:00
|
|
|
else
|
|
|
|
I18n.send("#{setting}=", value)
|
|
|
|
end
|
|
|
|
end
|
2010-01-24 04:27:42 -05:00
|
|
|
|
|
|
|
I18n.reload!
|
2010-01-22 19:29:29 -05:00
|
|
|
end
|
2010-04-16 16:16:21 -04:00
|
|
|
|
|
|
|
class << self
|
|
|
|
protected
|
|
|
|
|
|
|
|
def init_fallbacks(fallbacks)
|
|
|
|
include_fallbacks_module
|
|
|
|
args = case fallbacks
|
|
|
|
when ActiveSupport::OrderedOptions
|
|
|
|
[*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
|
|
|
|
when Hash, Array
|
|
|
|
Array.wrap(fallbacks)
|
|
|
|
else # TrueClass
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
I18n.fallbacks = I18n::Locale::Fallbacks.new(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_fallbacks_module
|
|
|
|
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_fallbacks(fallbacks)
|
|
|
|
case fallbacks
|
|
|
|
when ActiveSupport::OrderedOptions
|
|
|
|
!fallbacks.empty?
|
|
|
|
when TrueClass, Array, Hash
|
|
|
|
true
|
|
|
|
else
|
|
|
|
raise "Unexpected fallback type #{fallbacks.inspect}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-01-22 19:29:29 -05:00
|
|
|
end
|
2010-01-22 14:44:29 -05:00
|
|
|
end
|