diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-18 14:23:13 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-18 14:23:13 +0100 |
commit | d9b92ee11b33fed5c7a94a91415fa846705f7dd3 (patch) | |
tree | b936c0e1b7c9d3fbe8656a1b3a449383dcc00d55 /railties/lib | |
parent | 75fb8dfb996f5c5d8b64d10ce7b27eeb681d5316 (diff) | |
download | rails-d9b92ee11b33fed5c7a94a91415fa846705f7dd3.tar.gz rails-d9b92ee11b33fed5c7a94a91415fa846705f7dd3.tar.bz2 rails-d9b92ee11b33fed5c7a94a91415fa846705f7dd3.zip |
Added config.i18n settings gatherer to config/environment, auto-loading of all locales in config/locales/*.rb,yml, and config/locales/en.yml as a sample locale [DHH]
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/initializer.rb | 31 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/applications/app/app_generator.rb | 4 |
2 files changed, 35 insertions, 0 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index e3a0e3bad1..3e97a17e0e 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -147,7 +147,10 @@ module Rails initialize_dependency_mechanism initialize_whiny_nils initialize_temporary_session_directory + initialize_time_zone + initialize_i18n + initialize_framework_settings initialize_framework_views @@ -504,6 +507,18 @@ Run `rake gems:install` to install the missing gems. 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. + def initialize_i18n + configuration.i18n.each do |setting, value| + if setting == :load_path + I18n.load_path += value + else + I18n.send("#{setting}=", value) + end + end + end + # Initializes framework-specific settings for each of the loaded frameworks # (Configuration#frameworks). The available settings map to the accessors # on each of the corresponding Base classes. @@ -732,6 +747,9 @@ Run `rake gems:install` to install the missing gems. # timezone to <tt>:utc</tt>. attr_accessor :time_zone + # Accessor for i18n settings. + attr_accessor :i18n + # Create a new Configuration instance, initialized with the default # values. def initialize @@ -755,6 +773,7 @@ Run `rake gems:install` to install the missing gems. self.database_configuration_file = default_database_configuration_file self.routes_configuration_file = default_routes_configuration_file self.gems = default_gems + self.i18n = default_i18n for framework in default_frameworks self.send("#{framework}=", Rails::OrderedOptions.new) @@ -967,6 +986,18 @@ Run `rake gems:install` to install the missing gems. def default_gems [] end + + def default_i18n + i18n = Rails::OrderedOptions.new + i18n.load_path = [] + + if File.exist?(File.join(RAILS_ROOT, 'config', 'locales')) + i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')] + i18n.load_path.flatten! + end + + i18n + end end end diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 8c9bc63fc6..d68c425871 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -65,6 +65,9 @@ class AppGenerator < Rails::Generator::Base m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" + # Locale + m.template "configs/locales/en.yml", "config/locales/en.yml" + # Environments m.file "environments/boot.rb", "config/boot.rb" m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret } @@ -143,6 +146,7 @@ class AppGenerator < Rails::Generator::Base app/views/layouts config/environments config/initializers + config/locales db doc lib |