i18n 0.5.3 → 0.5.4
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.
- checksums.yaml +15 -0
- data/CHANGELOG.textile +12 -3
- data/README.textile +4 -17
- data/lib/i18n.rb +5 -9
- data/lib/i18n/backend.rb +0 -1
- data/lib/i18n/backend/base.rb +4 -32
- data/lib/i18n/backend/gettext.rb +3 -3
- data/lib/i18n/backend/interpolation_compiler.rb +1 -1
- data/lib/i18n/backend/metadata.rb +1 -1
- data/lib/i18n/config.rb +1 -1
- data/lib/i18n/core_ext/kernel/surpress_warnings.rb +9 -0
- data/lib/i18n/core_ext/string/interpolate.rb +9 -0
- data/lib/i18n/exceptions.rb +1 -7
- data/lib/i18n/interpolate/ruby.rb +31 -0
- data/lib/i18n/locale/fallbacks.rb +3 -3
- data/lib/i18n/tests/localization/procs.rb +27 -26
- data/lib/i18n/version.rb +1 -1
- data/test/all.rb +8 -0
- data/test/api/all_features_test.rb +58 -0
- data/test/api/cascade_test.rb +28 -0
- data/test/api/chain_test.rb +24 -0
- data/test/api/fallbacks_test.rb +30 -0
- data/test/api/key_value_test.rb +28 -0
- data/test/api/memoize_test.rb +60 -0
- data/test/api/pluralization_test.rb +30 -0
- data/test/api/simple_test.rb +28 -0
- data/test/backend/cache_test.rb +83 -0
- data/test/backend/cascade_test.rb +85 -0
- data/test/backend/chain_test.rb +67 -0
- data/test/backend/exceptions_test.rb +23 -0
- data/test/backend/fallbacks_test.rb +116 -0
- data/test/backend/interpolation_compiler_test.rb +102 -0
- data/test/backend/key_value_test.rb +46 -0
- data/test/backend/memoize_test.rb +47 -0
- data/test/backend/metadata_test.rb +67 -0
- data/test/backend/pluralization_test.rb +44 -0
- data/test/backend/simple_test.rb +79 -0
- data/test/backend/transliterator_test.rb +81 -0
- data/test/core_ext/hash_test.rb +30 -0
- data/test/core_ext/string/interpolate_test.rb +99 -0
- data/test/gettext/api_test.rb +206 -0
- data/test/gettext/backend_test.rb +93 -0
- data/test/i18n/exceptions_test.rb +120 -0
- data/test/i18n/interpolate_test.rb +61 -0
- data/test/i18n/load_path_test.rb +26 -0
- data/test/i18n_test.rb +323 -0
- data/test/locale/fallbacks_test.rb +124 -0
- data/test/locale/tag/rfc4646_test.rb +142 -0
- data/test/locale/tag/simple_test.rb +32 -0
- data/test/run_all.rb +21 -0
- data/test/test_data/locales/de.po +72 -0
- data/test/test_data/locales/en.rb +3 -0
- data/test/test_data/locales/en.yml +3 -0
- data/test/test_data/locales/invalid/empty.yml +0 -0
- data/test/test_data/locales/plurals.rb +113 -0
- data/test/test_helper.rb +56 -0
- metadata +64 -48
- data/lib/i18n/backend/cldr.rb +0 -99
data/test/test_helper.rb
ADDED
@@ -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/setup'
|
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,15 +1,9 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 3
|
10
|
-
version: 0.5.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.4
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Sven Fuchs
|
14
8
|
- Joshua Harvey
|
15
9
|
- Matt Aimonetti
|
@@ -18,26 +12,23 @@ authors:
|
|
18
12
|
autorequire:
|
19
13
|
bindir: bin
|
20
14
|
cert_chain: []
|
21
|
-
|
22
|
-
date: 2013-12-09 00:00:00 Z
|
15
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
23
16
|
dependencies: []
|
24
|
-
|
25
17
|
description: New wave Internationalization support for Ruby.
|
26
18
|
email: rails-i18n@googlegroups.com
|
27
19
|
executables: []
|
28
|
-
|
29
20
|
extensions: []
|
30
|
-
|
31
21
|
extra_rdoc_files: []
|
32
|
-
|
33
|
-
|
22
|
+
files:
|
23
|
+
- CHANGELOG.textile
|
24
|
+
- MIT-LICENSE
|
25
|
+
- README.textile
|
34
26
|
- lib/i18n.rb
|
35
27
|
- lib/i18n/backend.rb
|
36
28
|
- lib/i18n/backend/base.rb
|
37
29
|
- lib/i18n/backend/cache.rb
|
38
30
|
- lib/i18n/backend/cascade.rb
|
39
31
|
- lib/i18n/backend/chain.rb
|
40
|
-
- lib/i18n/backend/cldr.rb
|
41
32
|
- lib/i18n/backend/fallbacks.rb
|
42
33
|
- lib/i18n/backend/flatten.rb
|
43
34
|
- lib/i18n/backend/gettext.rb
|
@@ -50,11 +41,13 @@ files:
|
|
50
41
|
- lib/i18n/backend/transliterator.rb
|
51
42
|
- lib/i18n/config.rb
|
52
43
|
- lib/i18n/core_ext/hash.rb
|
44
|
+
- lib/i18n/core_ext/kernel/surpress_warnings.rb
|
53
45
|
- lib/i18n/core_ext/string/interpolate.rb
|
54
46
|
- lib/i18n/exceptions.rb
|
55
47
|
- lib/i18n/gettext.rb
|
56
48
|
- lib/i18n/gettext/helpers.rb
|
57
49
|
- lib/i18n/gettext/po_parser.rb
|
50
|
+
- lib/i18n/interpolate/ruby.rb
|
58
51
|
- lib/i18n/locale.rb
|
59
52
|
- lib/i18n/locale/fallbacks.rb
|
60
53
|
- lib/i18n/locale/tag.rb
|
@@ -75,43 +68,66 @@ files:
|
|
75
68
|
- lib/i18n/tests/pluralization.rb
|
76
69
|
- lib/i18n/tests/procs.rb
|
77
70
|
- lib/i18n/version.rb
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
71
|
+
- test/all.rb
|
72
|
+
- test/api/all_features_test.rb
|
73
|
+
- test/api/cascade_test.rb
|
74
|
+
- test/api/chain_test.rb
|
75
|
+
- test/api/fallbacks_test.rb
|
76
|
+
- test/api/key_value_test.rb
|
77
|
+
- test/api/memoize_test.rb
|
78
|
+
- test/api/pluralization_test.rb
|
79
|
+
- test/api/simple_test.rb
|
80
|
+
- test/backend/cache_test.rb
|
81
|
+
- test/backend/cascade_test.rb
|
82
|
+
- test/backend/chain_test.rb
|
83
|
+
- test/backend/exceptions_test.rb
|
84
|
+
- test/backend/fallbacks_test.rb
|
85
|
+
- test/backend/interpolation_compiler_test.rb
|
86
|
+
- test/backend/key_value_test.rb
|
87
|
+
- test/backend/memoize_test.rb
|
88
|
+
- test/backend/metadata_test.rb
|
89
|
+
- test/backend/pluralization_test.rb
|
90
|
+
- test/backend/simple_test.rb
|
91
|
+
- test/backend/transliterator_test.rb
|
92
|
+
- test/core_ext/hash_test.rb
|
93
|
+
- test/core_ext/string/interpolate_test.rb
|
94
|
+
- test/gettext/api_test.rb
|
95
|
+
- test/gettext/backend_test.rb
|
96
|
+
- test/i18n/exceptions_test.rb
|
97
|
+
- test/i18n/interpolate_test.rb
|
98
|
+
- test/i18n/load_path_test.rb
|
99
|
+
- test/i18n_test.rb
|
100
|
+
- test/locale/fallbacks_test.rb
|
101
|
+
- test/locale/tag/rfc4646_test.rb
|
102
|
+
- test/locale/tag/simple_test.rb
|
103
|
+
- test/run_all.rb
|
104
|
+
- test/test_data/locales/de.po
|
105
|
+
- test/test_data/locales/en.rb
|
106
|
+
- test/test_data/locales/en.yml
|
107
|
+
- test/test_data/locales/invalid/empty.yml
|
108
|
+
- test/test_data/locales/plurals.rb
|
109
|
+
- test/test_helper.rb
|
81
110
|
homepage: http://github.com/svenfuchs/i18n
|
82
111
|
licenses: []
|
83
|
-
|
112
|
+
metadata: {}
|
84
113
|
post_install_message:
|
85
114
|
rdoc_options: []
|
86
|
-
|
87
|
-
require_paths:
|
115
|
+
require_paths:
|
88
116
|
- lib
|
89
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
hash: 17
|
104
|
-
segments:
|
105
|
-
- 1
|
106
|
-
- 3
|
107
|
-
- 5
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
108
126
|
version: 1.3.5
|
109
127
|
requirements: []
|
110
|
-
|
111
|
-
|
112
|
-
rubygems_version: 1.8.6
|
128
|
+
rubyforge_project: ! '[none]'
|
129
|
+
rubygems_version: 2.2.2
|
113
130
|
signing_key:
|
114
|
-
specification_version:
|
131
|
+
specification_version: 4
|
115
132
|
summary: New wave Internationalization support for Ruby
|
116
133
|
test_files: []
|
117
|
-
|
data/lib/i18n/backend/cldr.rb
DELETED
@@ -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
|