i18n 0.5.0beta1 → 0.5.0beta2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of i18n might be problematic. Click here for more details.

Files changed (62) hide show
  1. data/README.textile +4 -17
  2. data/ci/Gemfile.no-rails +5 -0
  3. data/ci/Gemfile.no-rails.lock +17 -0
  4. data/ci/Gemfile.rails-2.3.x +9 -0
  5. data/ci/Gemfile.rails-2.3.x.lock +26 -0
  6. data/ci/Gemfile.rails-3.x +9 -0
  7. data/ci/Gemfile.rails-3.x.lock +26 -0
  8. data/lib/i18n.rb +4 -8
  9. data/lib/i18n/backend.rb +0 -1
  10. data/lib/i18n/backend/base.rb +4 -32
  11. data/lib/i18n/backend/gettext.rb +3 -3
  12. data/lib/i18n/backend/interpolation_compiler.rb +1 -1
  13. data/lib/i18n/backend/metadata.rb +1 -1
  14. data/lib/i18n/config.rb +1 -1
  15. data/lib/i18n/core_ext/kernel/surpress_warnings.rb +9 -0
  16. data/lib/i18n/core_ext/string/interpolate.rb +0 -96
  17. data/lib/i18n/exceptions.rb +0 -6
  18. data/lib/i18n/interpolate/ruby.rb +31 -0
  19. data/lib/i18n/locale/fallbacks.rb +3 -3
  20. data/lib/i18n/tests/localization/procs.rb +32 -19
  21. data/lib/i18n/tests/localization/time.rb +2 -2
  22. data/lib/i18n/version.rb +1 -1
  23. data/test/all.rb +8 -0
  24. data/test/api/all_features_test.rb +58 -0
  25. data/test/api/cascade_test.rb +28 -0
  26. data/test/api/chain_test.rb +24 -0
  27. data/test/api/fallbacks_test.rb +30 -0
  28. data/test/api/key_value_test.rb +28 -0
  29. data/test/api/memoize_test.rb +60 -0
  30. data/test/api/pluralization_test.rb +30 -0
  31. data/test/api/simple_test.rb +28 -0
  32. data/test/backend/cache_test.rb +83 -0
  33. data/test/backend/cascade_test.rb +85 -0
  34. data/test/backend/chain_test.rb +67 -0
  35. data/test/backend/exceptions_test.rb +23 -0
  36. data/test/backend/fallbacks_test.rb +116 -0
  37. data/test/backend/interpolation_compiler_test.rb +102 -0
  38. data/test/backend/key_value_test.rb +46 -0
  39. data/test/backend/memoize_test.rb +47 -0
  40. data/test/backend/metadata_test.rb +67 -0
  41. data/test/backend/pluralization_test.rb +44 -0
  42. data/test/backend/simple_test.rb +79 -0
  43. data/test/backend/transliterator_test.rb +81 -0
  44. data/test/core_ext/hash_test.rb +30 -0
  45. data/test/gettext/api_test.rb +206 -0
  46. data/test/gettext/backend_test.rb +93 -0
  47. data/test/i18n/exceptions_test.rb +116 -0
  48. data/test/i18n/interpolate_test.rb +60 -0
  49. data/test/i18n/load_path_test.rb +26 -0
  50. data/test/i18n_test.rb +236 -0
  51. data/test/locale/fallbacks_test.rb +124 -0
  52. data/test/locale/tag/rfc4646_test.rb +142 -0
  53. data/test/locale/tag/simple_test.rb +32 -0
  54. data/test/run_all.rb +21 -0
  55. data/test/test_data/locales/de.po +72 -0
  56. data/test/test_data/locales/en.rb +3 -0
  57. data/test/test_data/locales/en.yml +3 -0
  58. data/test/test_data/locales/invalid/empty.yml +1 -0
  59. data/test/test_data/locales/plurals.rb +113 -0
  60. data/test/test_helper.rb +56 -0
  61. metadata +116 -14
  62. data/lib/i18n/backend/cldr.rb +0 -99
@@ -0,0 +1,56 @@
1
+ $KCODE = 'u' if RUBY_VERSION <= '1.9'
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+
6
+ # Do not load the i18n gem from libraries like active_support.
7
+ #
8
+ # This is required for testing against Rails 2.3 because active_support/vendor.rb#24 tries
9
+ # to load I18n using the gem method. Instead, we want to test the local library of course.
10
+ alias :gem_for_ruby_19 :gem # for 1.9. gives a super ugly seg fault otherwise
11
+ def gem(gem_name, *version_requirements)
12
+ gem_name =='i18n' ? puts("skipping loading the i18n gem ...") : super
13
+ end
14
+
15
+ require 'bundler/setup'
16
+ require 'i18n'
17
+ require 'mocha'
18
+ require 'test_declarative'
19
+
20
+ class Test::Unit::TestCase
21
+ def teardown
22
+ I18n.locale = nil
23
+ I18n.default_locale = :en
24
+ I18n.load_path = []
25
+ I18n.available_locales = nil
26
+ I18n.backend = nil
27
+ end
28
+
29
+ def translations
30
+ I18n.backend.instance_variable_get(:@translations)
31
+ end
32
+
33
+ def store_translations(*args)
34
+ data = args.pop
35
+ locale = args.pop || :en
36
+ I18n.backend.store_translations(locale, data)
37
+ end
38
+
39
+ def locales_dir
40
+ File.dirname(__FILE__) + '/test_data/locales'
41
+ end
42
+ end
43
+
44
+ module Kernel
45
+ def setup_rufus_tokyo
46
+ require 'rufus/tokyo'
47
+ rescue LoadError => e
48
+ puts "can't use KeyValue backend because: #{e.message}"
49
+ end
50
+ end
51
+
52
+ Object.class_eval do
53
+ def meta_class
54
+ class << self; self; end
55
+ end
56
+ end unless Object.method_defined?(:meta_class)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1150612293
4
+ hash: -1150612296
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 0beta1
10
- version: 0.5.0beta1
9
+ - 0beta2
10
+ version: 0.5.0beta2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sven Fuchs
@@ -19,10 +19,67 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-11-14 00:00:00 +01:00
22
+ date: 2010-11-18 00:00:00 +01:00
23
23
  default_executable:
24
- dependencies: []
25
-
24
+ dependencies:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ prerelease: false
28
+ requirement: &id001 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ hash: 7
34
+ segments:
35
+ - 3
36
+ - 0
37
+ - 0
38
+ version: 3.0.0
39
+ type: :development
40
+ version_requirements: *id001
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3-ruby
43
+ prerelease: false
44
+ requirement: &id002 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ type: :development
54
+ version_requirements: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ prerelease: false
58
+ requirement: &id003 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: test_declarative
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ type: :development
82
+ version_requirements: *id004
26
83
  description: New wave Internationalization support for Ruby.
27
84
  email: rails-i18n@googlegroups.com
28
85
  executables: []
@@ -32,13 +89,16 @@ extensions: []
32
89
  extra_rdoc_files: []
33
90
 
34
91
  files:
35
- - lib/i18n.rb
36
- - lib/i18n/backend.rb
92
+ - ci/Gemfile.no-rails
93
+ - ci/Gemfile.no-rails.lock
94
+ - ci/Gemfile.rails-2.3.x
95
+ - ci/Gemfile.rails-2.3.x.lock
96
+ - ci/Gemfile.rails-3.x
97
+ - ci/Gemfile.rails-3.x.lock
37
98
  - lib/i18n/backend/base.rb
38
99
  - lib/i18n/backend/cache.rb
39
100
  - lib/i18n/backend/cascade.rb
40
101
  - lib/i18n/backend/chain.rb
41
- - lib/i18n/backend/cldr.rb
42
102
  - lib/i18n/backend/fallbacks.rb
43
103
  - lib/i18n/backend/flatten.rb
44
104
  - lib/i18n/backend/gettext.rb
@@ -49,33 +109,75 @@ files:
49
109
  - lib/i18n/backend/pluralization.rb
50
110
  - lib/i18n/backend/simple.rb
51
111
  - lib/i18n/backend/transliterator.rb
112
+ - lib/i18n/backend.rb
52
113
  - lib/i18n/config.rb
53
114
  - lib/i18n/core_ext/hash.rb
115
+ - lib/i18n/core_ext/kernel/surpress_warnings.rb
54
116
  - lib/i18n/core_ext/string/interpolate.rb
55
117
  - lib/i18n/exceptions.rb
56
- - lib/i18n/gettext.rb
57
118
  - lib/i18n/gettext/helpers.rb
58
119
  - lib/i18n/gettext/po_parser.rb
59
- - lib/i18n/locale.rb
120
+ - lib/i18n/gettext.rb
121
+ - lib/i18n/interpolate/ruby.rb
60
122
  - lib/i18n/locale/fallbacks.rb
61
- - lib/i18n/locale/tag.rb
62
123
  - lib/i18n/locale/tag/parents.rb
63
124
  - lib/i18n/locale/tag/rfc4646.rb
64
125
  - lib/i18n/locale/tag/simple.rb
65
- - lib/i18n/tests.rb
126
+ - lib/i18n/locale/tag.rb
127
+ - lib/i18n/locale.rb
66
128
  - lib/i18n/tests/basics.rb
67
129
  - lib/i18n/tests/defaults.rb
68
130
  - lib/i18n/tests/interpolation.rb
69
131
  - lib/i18n/tests/link.rb
70
- - lib/i18n/tests/localization.rb
71
132
  - lib/i18n/tests/localization/date.rb
72
133
  - lib/i18n/tests/localization/date_time.rb
73
134
  - lib/i18n/tests/localization/procs.rb
74
135
  - lib/i18n/tests/localization/time.rb
136
+ - lib/i18n/tests/localization.rb
75
137
  - lib/i18n/tests/lookup.rb
76
138
  - lib/i18n/tests/pluralization.rb
77
139
  - lib/i18n/tests/procs.rb
140
+ - lib/i18n/tests.rb
78
141
  - lib/i18n/version.rb
142
+ - lib/i18n.rb
143
+ - test/all.rb
144
+ - test/api/all_features_test.rb
145
+ - test/api/cascade_test.rb
146
+ - test/api/chain_test.rb
147
+ - test/api/fallbacks_test.rb
148
+ - test/api/key_value_test.rb
149
+ - test/api/memoize_test.rb
150
+ - test/api/pluralization_test.rb
151
+ - test/api/simple_test.rb
152
+ - test/backend/cache_test.rb
153
+ - test/backend/cascade_test.rb
154
+ - test/backend/chain_test.rb
155
+ - test/backend/exceptions_test.rb
156
+ - test/backend/fallbacks_test.rb
157
+ - test/backend/interpolation_compiler_test.rb
158
+ - test/backend/key_value_test.rb
159
+ - test/backend/memoize_test.rb
160
+ - test/backend/metadata_test.rb
161
+ - test/backend/pluralization_test.rb
162
+ - test/backend/simple_test.rb
163
+ - test/backend/transliterator_test.rb
164
+ - test/core_ext/hash_test.rb
165
+ - test/gettext/api_test.rb
166
+ - test/gettext/backend_test.rb
167
+ - test/i18n/exceptions_test.rb
168
+ - test/i18n/interpolate_test.rb
169
+ - test/i18n/load_path_test.rb
170
+ - test/i18n_test.rb
171
+ - test/locale/fallbacks_test.rb
172
+ - test/locale/tag/rfc4646_test.rb
173
+ - test/locale/tag/simple_test.rb
174
+ - test/run_all.rb
175
+ - test/test_data/locales/de.po
176
+ - test/test_data/locales/en.rb
177
+ - test/test_data/locales/en.yml
178
+ - test/test_data/locales/invalid/empty.yml
179
+ - test/test_data/locales/plurals.rb
180
+ - test/test_helper.rb
79
181
  - README.textile
80
182
  - MIT-LICENSE
81
183
  - CHANGELOG.textile
@@ -1,99 +0,0 @@
1
- require 'cldr'
2
-
3
- module I18n
4
- module Backend
5
- module Cldr
6
- include ::Cldr::Format
7
-
8
- def localize(locale, object, format = :default, options = {})
9
- options[:as] ||= detect_type(object, options)
10
- send(:"format_#{options[:as]}", locale, object, format, options)
11
- end
12
-
13
- def format_decimal(locale, object, format = :default, options = {})
14
- formatter(locale, :decimal, format).apply(object, options)
15
- end
16
-
17
- def format_integer(locale, object, format = :default, options = {})
18
- format_object(number, options.merge(:precision => 0))
19
- end
20
-
21
- def format_currency(locale, object, format = :default, options = {})
22
- options.merge!(:currency => lookup_currency(locale, options[:currency], object)) if options[:currency].is_a?(Symbol)
23
- formatter(locale, :currency, format).apply(object, options)
24
- end
25
-
26
- def format_percent(locale, object, format = :default, options = {})
27
- formatter(locale, :percent, format).apply(object, options)
28
- end
29
-
30
- def format_date(locale, object, format = :default, options = {})
31
- formatter(locale, :date, format).apply(object, options)
32
- end
33
-
34
- def format_time(locale, object, format = :default, options = {})
35
- formatter(locale, :time, format).apply(object, options)
36
- end
37
-
38
- def format_datetime(locale, object, format = :default, options = {})
39
- key = :"calendars.gregorian.formats.datetime.#{format}.pattern"
40
- date = I18n.l(object, :format => options[:date_format] || format, :locale => locale, :as => :date)
41
- time = I18n.l(object, :format => options[:time_format] || format, :locale => locale, :as => :time)
42
- I18n.t(key, :date => date, :time => time, :locale => locale, :raise => true)
43
- end
44
-
45
- protected
46
-
47
- def detect_type(object, options)
48
- options.has_key?(:currency) ? :currency : case object
49
- when ::Numeric
50
- :decimal
51
- when ::Date, ::DateTime, ::Time
52
- object.class.name.downcase.to_sym
53
- else
54
- raise_unspecified_format_type!
55
- end
56
- end
57
-
58
- def formatter(locale, type, format)
59
- (@formatters ||= {})[:"#{locale}.#{type}.#{format}"] ||= begin
60
- format = lookup_format(locale, type, format)
61
- data = lookup_format_data(locale, type)
62
- ::Cldr::Format.const_get(type.to_s.camelize).new(format, data)
63
- end
64
- end
65
-
66
- def lookup_format(locale, type, format)
67
- key = case type
68
- when :date, :time, :datetime
69
- :"calendars.gregorian.formats.#{type}.#{format}.pattern"
70
- else
71
- :"numbers.formats.#{type}.patterns.#{format || :default}"
72
- end
73
- I18n.t(key, :locale => locale, :raise => true)
74
- end
75
-
76
- def lookup_format_data(locale, type)
77
- key = case type
78
- when :date, :time, :datetime
79
- :'calendars.gregorian'
80
- else
81
- :'numbers.symbols'
82
- end
83
- I18n.t(key, :locale => locale, :raise => true)
84
- end
85
-
86
- def lookup_currency(locale, currency, count)
87
- I18n.t(:"currencies.#{currency}", :locale => locale, :count => count)
88
- end
89
-
90
- def raise_unspecified_format_type!
91
- raise ArgumentError.new("You have to specify a format type, e.g. :as => :number.")
92
- end
93
-
94
- def raise_unspecified_currency!
95
- raise ArgumentError.new("You have to specify a currency, e.g. :currency => 'EUR'.")
96
- end
97
- end
98
- end
99
- end