public
Fork of rails/rails
Description: Ruby on Rails - forked for implementing I18n patch
Homepage: http://rubyonrails.org
Clone URL: git://github.com/svenfuchs/rails.git
I18n: introduce I18n.load_path in favor of I18n.load_translations and 
change Simple backend to load translations lazily
svenfuchs (author)
Mon Sep 15 01:26:50 -0700 2008
commit  592b2a5c91d5a7e9cabf9eadaa49f2788d21dcde
tree    3aedb4336916fd376042c8c9eb6fcf41f75b2077
parent  5ba6598e4ca08b3bc721fe92c1ed13bae1a87e3b
...
43
44
45
46
 
47
48
49
...
43
44
45
 
46
47
48
49
0
@@ -43,7 +43,7 @@ require 'action_view/base'
0
 require 'action_view/partials'
0
 require 'action_view/template_error'
0
 
0
-I18n.load_translations "#{File.dirname(__FILE__)}/action_view/locale/en-US.yml"
0
+I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en-US.yml"
0
 
0
 require 'action_view/helpers'
0
 
...
78
79
80
81
 
...
78
79
80
 
81
0
@@ -78,4 +78,4 @@ require 'active_record/connection_adapters/abstract_adapter'
0
 require 'active_record/schema_dumper'
0
 
0
 require 'active_record/i18n_interpolation_deprecation'
0
-I18n.load_translations File.dirname(__FILE__) + '/active_record/locale/en-US.yml'
0
+I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en-US.yml'
...
6
7
8
 
 
 
9
10
11
12
13
14
 
 
15
16
17
...
6
7
8
9
10
11
12
13
14
15
16
 
17
18
19
20
21
0
@@ -6,12 +6,16 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
   def setup
0
     reset_callbacks Topic
0
     @topic = Topic.new
0
+ @old_load_path, @old_backend = I18n.load_path, I18n.backend
0
+ I18n.load_path.clear
0
+ I18n.backend = I18n::Backend::Simple.new
0
     I18n.backend.store_translations('en-US', :activerecord => {:errors => {:messages => {:custom => nil}}})
0
   end
0
 
0
   def teardown
0
     reset_callbacks Topic
0
- I18n.load_translations File.dirname(__FILE__) + '/../../lib/active_record/locale/en-US.yml'
0
+ I18n.load_path.replace @old_load_path
0
+ I18n.backend = @old_backend
0
   end
0
 
0
   def unique_topic
...
56
57
58
59
 
60
61
62
...
56
57
58
 
59
60
61
62
0
@@ -56,7 +56,7 @@ require 'active_support/time_with_zone'
0
 
0
 require 'active_support/secure_random'
0
 
0
-I18n.load_translations File.dirname(__FILE__) + '/active_support/locale/en-US.yml'
0
+I18n.load_path << File.dirname(__FILE__) + '/active_support/locale/en-US.yml'
0
 
0
 Inflector = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Inflector', 'ActiveSupport::Inflector')
0
 Dependencies = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Dependencies', 'ActiveSupport::Dependencies')
...
10
11
12
13
 
 
14
15
16
...
49
50
51
52
53
54
 
 
 
55
56
57
58
59
 
 
 
 
 
 
 
 
 
 
 
60
61
62
...
175
176
177
178
179
180
 
181
...
10
11
12
 
13
14
15
16
17
...
50
51
52
 
 
 
53
54
55
56
57
 
 
 
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
184
185
186
 
 
 
187
188
0
@@ -10,7 +10,8 @@ require 'i18n/exceptions'
0
 
0
 module I18n
0
   @@backend = nil
0
- @@default_locale = 'en-US'
0
+ @@load_path = nil
0
+ @@default_locale = :'en-US'
0
   @@exception_handler = :default_exception_handler
0
     
0
   class << self
0
@@ -49,14 +50,22 @@ module I18n
0
       @@exception_handler = exception_handler
0
     end
0
     
0
- # Allows client libraries to pass arguments that specify a source for
0
- # translation data to be loaded by the backend. The backend defines
0
- # acceptable sources.
0
+ # Allow clients to register paths providing translation data sources. The
0
+ # backend defines acceptable sources.
0
+ #
0
     # E.g. the provided SimpleBackend accepts a list of paths to translation
0
     # files which are either named *.rb and contain plain Ruby Hashes or are
0
- # named *.yml and contain YAML data.)
0
- def load_translations(*args)
0
- backend.load_translations(*args)
0
+ # named *.yml and contain YAML data. So for the SimpleBackend clients may
0
+ # register translation files like this:
0
+ # I18n.load_path << 'path/to/locale/en-US.yml'
0
+ def load_path
0
+ @@load_path ||= []
0
+ end
0
+
0
+ # Sets the load path instance. Custom implementations are expected to
0
+ # behave like a Ruby Array.
0
+ def load_path=(load_path)
0
+ @@load_path = load_path
0
     end
0
     
0
     # Translates, pluralizes and interpolates a given key using a given locale,
0
@@ -175,6 +184,4 @@ module I18n
0
       keys.flatten.map{|k| k.to_sym}
0
     end
0
   end
0
-end
0
-
0
-
0
+end
0
\ No newline at end of file
...
1
 
2
3
4
...
59
60
61
 
 
 
 
62
 
 
 
 
 
63
64
65
...
72
73
74
 
75
76
77
...
94
95
96
97
 
98
99
100
...
 
1
2
3
4
...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
...
81
82
83
84
85
86
87
...
104
105
106
 
107
108
109
110
0
@@ -1,4 +1,4 @@
0
-require 'strscan'
0
+require 'yaml'
0
 
0
 module I18n
0
   module Backend
0
@@ -59,7 +59,16 @@ module I18n
0
         object.strftime(format)
0
       end
0
       
0
+ def initialized?
0
+ @initialized ||= false
0
+ end
0
+
0
       protected
0
+
0
+ def init_translations
0
+ load_translations(*I18n.load_path)
0
+ @initialized = true
0
+ end
0
         
0
         def translations
0
           @translations ||= {}
0
@@ -72,6 +81,7 @@ module I18n
0
         # <tt>%w(currency format)</tt>.
0
         def lookup(locale, key, scope = [])
0
           return unless key
0
+ init_translations unless initialized?
0
           keys = I18n.send :normalize_translation_keys, locale, key, scope
0
           keys.inject(translations){|result, k| result[k.to_sym] or return nil }
0
         end
0
@@ -94,7 +104,7 @@ module I18n
0
         rescue MissingTranslationData
0
           nil
0
         end
0
-
0
+
0
         # Picks a translation from an array according to English pluralization
0
         # rules. It will pick the first translation if count is not equal to 1
0
         # and the second translation if it is equal to 1. Other backends can

Comments

    No one has commented yet.