public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
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]
dhh (author)
Tue Nov 18 05:23:13 -0800 2008
commit  d9b92ee11b33fed5c7a94a91415fa846705f7dd3
tree    b936c0e1b7c9d3fbe8656a1b3a449383dcc00d55
parent  75fb8dfb996f5c5d8b64d10ce7b27eeb681d5316
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.3.0/3.0*
0
 
0
+* 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]
0
+
0
 * BACKWARDS INCOMPATIBLE: Renamed application.rb to application_controller.rb and removed all the special casing that was in place to support the former. You must do this rename in your own application when you upgrade to this version [DHH]
0
 
0
 
...
44
45
46
 
47
48
49
...
199
200
201
 
 
202
203
204
...
44
45
46
47
48
49
50
...
200
201
202
203
204
205
206
207
0
@@ -44,6 +44,7 @@ BASE_DIRS = %w(
0
   app
0
   config/environments
0
   config/initializers
0
+  config/locales
0
   components
0
   db
0
   doc
0
@@ -199,6 +200,8 @@ task :copy_configs do
0
   cp "configs/initializers/inflections.rb", "#{PKG_DESTINATION}/config/initializers/inflections.rb"
0
   cp "configs/initializers/mime_types.rb",  "#{PKG_DESTINATION}/config/initializers/mime_types.rb"
0
 
0
+  cp "configs/locales/en.yml", "#{PKG_DESTINATION}/config/locales/en.yml"
0
+
0
   cp "environments/boot.rb",        "#{PKG_DESTINATION}/config/boot.rb"
0
   cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
0
   cp "environments/production.rb",  "#{PKG_DESTINATION}/config/environments/production.rb"
...
45
46
47
 
 
 
 
 
48
49
50
...
45
46
47
48
49
50
51
52
53
54
55
0
@@ -45,6 +45,11 @@ Rails::Initializer.run do |config|
0
   # Run "rake -D time" for a list of tasks for finding time zone names. Comment line to use default local time.
0
   config.time_zone = 'UTC'
0
 
0
+  # The internationalization framework can be changed to have another default locale (standard is :en) or more load paths.
0
+  # All files from config/locales/*.rb,yml are added automatically.
0
+  # config.i18n.load_path << Dir[File.join(RAILS_ROOT, 'my', 'locales', '*.{rb,yml}')]
0
+  # config.i18n.default_locale = :de
0
+
0
   # Your secret key for verifying cookie session data integrity.
0
   # If you change this key, all old sessions will become invalid!
0
   # Make sure the secret is at least 30 characters and all random, 
...
147
148
149
 
150
 
 
151
152
153
...
504
505
506
 
 
 
 
 
 
 
 
 
 
 
 
507
508
509
...
732
733
734
 
 
 
735
736
737
...
755
756
757
 
758
759
760
...
967
968
969
 
 
 
 
 
 
 
 
 
 
 
 
970
971
972
...
147
148
149
150
151
152
153
154
155
156
...
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
...
747
748
749
750
751
752
753
754
755
...
773
774
775
776
777
778
779
...
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
0
@@ -147,7 +147,10 @@ module Rails
0
       initialize_dependency_mechanism
0
       initialize_whiny_nils
0
       initialize_temporary_session_directory
0
+
0
       initialize_time_zone
0
+      initialize_i18n
0
+
0
       initialize_framework_settings
0
       initialize_framework_views
0
 
0
@@ -504,6 +507,18 @@ Run `rake gems:install` to install the missing gems.
0
       end
0
     end
0
 
0
+    # Set the i18n configuration from config.i18n but special-case for the load_path which should be 
0
+    # appended to what's already set instead of overwritten.
0
+    def initialize_i18n
0
+      configuration.i18n.each do |setting, value|
0
+        if setting == :load_path
0
+          I18n.load_path += value
0
+        else
0
+          I18n.send("#{setting}=", value)
0
+        end
0
+      end
0
+    end
0
+
0
     # Initializes framework-specific settings for each of the loaded frameworks
0
     # (Configuration#frameworks). The available settings map to the accessors
0
     # on each of the corresponding Base classes.
0
@@ -732,6 +747,9 @@ Run `rake gems:install` to install the missing gems.
0
     # timezone to <tt>:utc</tt>.
0
     attr_accessor :time_zone
0
 
0
+    # Accessor for i18n settings.
0
+    attr_accessor :i18n
0
+
0
     # Create a new Configuration instance, initialized with the default
0
     # values.
0
     def initialize
0
@@ -755,6 +773,7 @@ Run `rake gems:install` to install the missing gems.
0
       self.database_configuration_file  = default_database_configuration_file
0
       self.routes_configuration_file    = default_routes_configuration_file
0
       self.gems                         = default_gems
0
+      self.i18n                         = default_i18n
0
 
0
       for framework in default_frameworks
0
         self.send("#{framework}=", Rails::OrderedOptions.new)
0
@@ -967,6 +986,18 @@ Run `rake gems:install` to install the missing gems.
0
       def default_gems
0
         []
0
       end
0
+
0
+      def default_i18n
0
+        i18n = Rails::OrderedOptions.new
0
+        i18n.load_path = []
0
+
0
+        if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
0
+          i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
0
+          i18n.load_path.flatten!
0
+        end
0
+
0
+        i18n
0
+      end
0
   end
0
 end
0
 
...
65
66
67
 
 
 
68
69
70
...
143
144
145
 
146
147
148
...
65
66
67
68
69
70
71
72
73
...
146
147
148
149
150
151
152
0
@@ -65,6 +65,9 @@ class AppGenerator < Rails::Generator::Base
0
       m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb"
0
       m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb"
0
 
0
+      # Locale
0
+      m.template "configs/locales/en.yml", "config/locales/en.yml"
0
+
0
       # Environments
0
       m.file "environments/boot.rb",    "config/boot.rb"
0
       m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret }
0
@@ -143,6 +146,7 @@ class AppGenerator < Rails::Generator::Base
0
     app/views/layouts
0
     config/environments
0
     config/initializers
0
+    config/locales
0
     db
0
     doc
0
     lib
...
18
19
20
21
22
23
24
...
260
261
262
263
264
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
...
18
19
20
 
21
22
23
...
259
260
261
 
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
0
@@ -18,7 +18,6 @@ class ConfigurationMock < Rails::Configuration
0
 end
0
 
0
 class Initializer_load_environment_Test < Test::Unit::TestCase
0
-
0
   def test_load_environment_with_constant
0
     config = ConfigurationMock.new("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb")
0
     assert_nil $initialize_test_set_from_env
0
@@ -260,5 +259,51 @@ uses_mocha "Initializer plugin loading tests" do
0
         @initializer.load_plugins
0
       end
0
   end
0
-
0
 end
0
+
0
+uses_mocha 'i18n settings' do
0
+  class InitializerSetupI18nTests < Test::Unit::TestCase
0
+    def test_no_config_locales_dir_present_should_return_empty_load_path
0
+      File.stubs(:exist?).returns(false)
0
+      assert_equal [], Rails::Configuration.new.i18n.load_path
0
+    end
0
+
0
+    def test_config_locales_dir_present_should_be_added_to_load_path
0
+      File.stubs(:exist?).returns(true)
0
+      Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
0
+      assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path
0
+    end
0
+    
0
+    def test_config_defaults_should_be_added_with_config_settings
0
+      File.stubs(:exist?).returns(true)
0
+      Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
0
+
0
+      config = Rails::Configuration.new
0
+      config.i18n.load_path << "my/other/locale.yml"
0
+
0
+      assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path
0
+    end
0
+    
0
+    def test_config_defaults_and_settings_should_be_added_to_i18n_defaults
0
+      File.stubs(:exist?).returns(true)
0
+      Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
0
+
0
+      config = Rails::Configuration.new
0
+      config.i18n.load_path << "my/other/locale.yml"
0
+
0
+      Rails::Initializer.run(:initialize_i18n, config)
0
+      assert_equal [ 
0
+       "./test/../../activesupport/lib/active_support/locale/en-US.yml",
0
+       "./test/../../actionpack/lib/action_view/locale/en-US.yml",
0
+       "my/test/locale.yml",
0
+       "my/other/locale.yml" ], I18n.load_path
0
+    end
0
+    
0
+    def test_setting_another_default_locale
0
+      config = Rails::Configuration.new
0
+      config.i18n.default_locale = :de
0
+      Rails::Initializer.run(:initialize_i18n, config)
0
+      assert_equal :de, I18n.default_locale
0
+    end
0
+  end
0
+end
0
\ No newline at end of file

Comments