i18n 0.9.5 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -13
- data/lib/i18n/backend/base.rb +46 -17
- data/lib/i18n/backend/cache.rb +8 -9
- data/lib/i18n/backend/cache_file.rb +36 -0
- data/lib/i18n/backend/cascade.rb +3 -1
- data/lib/i18n/backend/chain.rb +33 -3
- data/lib/i18n/backend/fallbacks.rb +11 -13
- data/lib/i18n/backend/flatten.rb +2 -0
- data/lib/i18n/backend/gettext.rb +4 -0
- data/lib/i18n/backend/interpolation_compiler.rb +3 -1
- data/lib/i18n/backend/key_value.rb +31 -2
- data/lib/i18n/backend/memoize.rb +10 -2
- data/lib/i18n/backend/metadata.rb +5 -3
- data/lib/i18n/backend/pluralization.rb +2 -0
- data/lib/i18n/backend/simple.rb +26 -8
- data/lib/i18n/backend/transliterator.rb +2 -0
- data/lib/i18n/backend.rb +3 -0
- data/lib/i18n/config.rb +20 -2
- data/lib/i18n/core_ext/hash.rb +42 -24
- data/lib/i18n/exceptions.rb +23 -16
- data/lib/i18n/gettext/helpers.rb +3 -1
- data/lib/i18n/gettext/po_parser.rb +7 -7
- data/lib/i18n/gettext.rb +2 -0
- data/lib/i18n/interpolate/ruby.rb +5 -3
- data/lib/i18n/locale/fallbacks.rb +1 -1
- data/lib/i18n/locale.rb +2 -0
- data/lib/i18n/middleware.rb +2 -0
- data/lib/i18n/tests/interpolation.rb +5 -4
- data/lib/i18n/tests/localization/date.rb +28 -6
- data/lib/i18n/tests/localization/date_time.rb +27 -6
- data/lib/i18n/tests/localization/time.rb +26 -4
- data/lib/i18n/tests.rb +2 -0
- data/lib/i18n/version.rb +3 -1
- data/lib/i18n.rb +72 -30
- metadata +24 -58
- data/gemfiles/Gemfile.rails-3.2.x +0 -10
- data/gemfiles/Gemfile.rails-4.0.x +0 -10
- data/gemfiles/Gemfile.rails-4.1.x +0 -10
- data/gemfiles/Gemfile.rails-4.2.x +0 -10
- data/gemfiles/Gemfile.rails-5.0.x +0 -10
- data/gemfiles/Gemfile.rails-5.1.x +0 -10
- data/gemfiles/Gemfile.rails-master +0 -10
- data/lib/i18n/core_ext/kernel/suppress_warnings.rb +0 -8
- data/lib/i18n/core_ext/string/interpolate.rb +0 -9
- data/test/api/all_features_test.rb +0 -58
- data/test/api/cascade_test.rb +0 -28
- data/test/api/chain_test.rb +0 -24
- data/test/api/fallbacks_test.rb +0 -30
- data/test/api/key_value_test.rb +0 -24
- data/test/api/memoize_test.rb +0 -56
- data/test/api/override_test.rb +0 -42
- data/test/api/pluralization_test.rb +0 -30
- data/test/api/simple_test.rb +0 -28
- data/test/backend/cache_test.rb +0 -109
- data/test/backend/cascade_test.rb +0 -86
- data/test/backend/chain_test.rb +0 -122
- data/test/backend/exceptions_test.rb +0 -36
- data/test/backend/fallbacks_test.rb +0 -219
- data/test/backend/interpolation_compiler_test.rb +0 -118
- data/test/backend/key_value_test.rb +0 -61
- data/test/backend/memoize_test.rb +0 -79
- data/test/backend/metadata_test.rb +0 -48
- data/test/backend/pluralization_test.rb +0 -45
- data/test/backend/simple_test.rb +0 -103
- data/test/backend/transliterator_test.rb +0 -84
- data/test/core_ext/hash_test.rb +0 -36
- data/test/gettext/api_test.rb +0 -214
- data/test/gettext/backend_test.rb +0 -92
- data/test/i18n/exceptions_test.rb +0 -117
- data/test/i18n/gettext_plural_keys_test.rb +0 -20
- data/test/i18n/interpolate_test.rb +0 -91
- data/test/i18n/load_path_test.rb +0 -34
- data/test/i18n/middleware_test.rb +0 -24
- data/test/i18n_test.rb +0 -462
- data/test/locale/fallbacks_test.rb +0 -133
- data/test/locale/tag/rfc4646_test.rb +0 -143
- data/test/locale/tag/simple_test.rb +0 -32
- data/test/run_all.rb +0 -20
- data/test/test_data/locales/de.po +0 -82
- data/test/test_data/locales/en.rb +0 -3
- data/test/test_data/locales/en.yml +0 -3
- data/test/test_data/locales/invalid/empty.yml +0 -0
- data/test/test_data/locales/invalid/syntax.yml +0 -4
- data/test/test_data/locales/plurals.rb +0 -113
- data/test/test_helper.rb +0 -61
data/lib/i18n/backend/simple.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'i18n/backend/base'
|
4
|
+
|
1
5
|
module I18n
|
2
6
|
module Backend
|
3
7
|
# A simple backend that reads translations from YAML files and stores them in
|
@@ -15,6 +19,8 @@ module I18n
|
|
15
19
|
#
|
16
20
|
# I18n::Backend::Simple.include(I18n::Backend::Pluralization)
|
17
21
|
class Simple
|
22
|
+
using I18n::HashRefinements
|
23
|
+
|
18
24
|
(class << self; self; end).class_eval { public :include }
|
19
25
|
|
20
26
|
module Implementation
|
@@ -28,7 +34,7 @@ module I18n
|
|
28
34
|
# This uses a deep merge for the translations hash, so existing
|
29
35
|
# translations will be overwritten by new ones only at the deepest
|
30
36
|
# level of the hash.
|
31
|
-
def store_translations(locale, data, options =
|
37
|
+
def store_translations(locale, data, options = EMPTY_HASH)
|
32
38
|
if I18n.enforce_available_locales &&
|
33
39
|
I18n.available_locales_initialized? &&
|
34
40
|
!I18n.available_locales.include?(locale.to_sym) &&
|
@@ -57,6 +63,19 @@ module I18n
|
|
57
63
|
super
|
58
64
|
end
|
59
65
|
|
66
|
+
def eager_load!
|
67
|
+
init_translations unless initialized?
|
68
|
+
super
|
69
|
+
end
|
70
|
+
|
71
|
+
def translations(do_init: false)
|
72
|
+
# To avoid returning empty translations,
|
73
|
+
# call `init_translations`
|
74
|
+
init_translations if do_init && !initialized?
|
75
|
+
|
76
|
+
@translations ||= {}
|
77
|
+
end
|
78
|
+
|
60
79
|
protected
|
61
80
|
|
62
81
|
def init_translations
|
@@ -64,22 +83,21 @@ module I18n
|
|
64
83
|
@initialized = true
|
65
84
|
end
|
66
85
|
|
67
|
-
def translations
|
68
|
-
@translations ||= {}
|
69
|
-
end
|
70
|
-
|
71
86
|
# Looks up a translation from the translations hash. Returns nil if
|
72
87
|
# either key is nil, or locale, scope or key do not exist as a key in the
|
73
88
|
# nested translations hash. Splits keys or scopes containing dots
|
74
89
|
# into multiple keys, i.e. <tt>currency.format</tt> is regarded the same as
|
75
90
|
# <tt>%w(currency format)</tt>.
|
76
|
-
def lookup(locale, key, scope = [], options =
|
91
|
+
def lookup(locale, key, scope = [], options = EMPTY_HASH)
|
77
92
|
init_translations unless initialized?
|
78
93
|
keys = I18n.normalize_keys(locale, key, scope, options[:separator])
|
79
94
|
|
80
95
|
keys.inject(translations) do |result, _key|
|
81
|
-
|
82
|
-
|
96
|
+
return nil unless result.is_a?(Hash)
|
97
|
+
unless result.has_key?(_key)
|
98
|
+
_key = _key.to_s.to_sym
|
99
|
+
return nil unless result.has_key?(_key)
|
100
|
+
end
|
83
101
|
result = result[_key]
|
84
102
|
result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol)
|
85
103
|
result
|
data/lib/i18n/backend.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module I18n
|
2
4
|
module Backend
|
3
5
|
autoload :Base, 'i18n/backend/base'
|
4
6
|
autoload :InterpolationCompiler, 'i18n/backend/interpolation_compiler'
|
5
7
|
autoload :Cache, 'i18n/backend/cache'
|
8
|
+
autoload :CacheFile, 'i18n/backend/cache_file'
|
6
9
|
autoload :Cascade, 'i18n/backend/cascade'
|
7
10
|
autoload :Chain, 'i18n/backend/chain'
|
8
11
|
autoload :Fallbacks, 'i18n/backend/fallbacks'
|
data/lib/i18n/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'set'
|
2
4
|
|
3
5
|
module I18n
|
@@ -5,7 +7,7 @@ module I18n
|
|
5
7
|
# The only configuration value that is not global and scoped to thread is :locale.
|
6
8
|
# It defaults to the default_locale.
|
7
9
|
def locale
|
8
|
-
defined?(@locale) && @locale ? @locale : default_locale
|
10
|
+
defined?(@locale) && @locale != nil ? @locale : default_locale
|
9
11
|
end
|
10
12
|
|
11
13
|
# Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
|
@@ -57,7 +59,7 @@ module I18n
|
|
57
59
|
@@available_locales = nil if @@available_locales.empty?
|
58
60
|
@@available_locales_set = nil
|
59
61
|
end
|
60
|
-
|
62
|
+
|
61
63
|
# Returns true if the available_locales have been initialized
|
62
64
|
def available_locales_initialized?
|
63
65
|
( !!defined?(@@available_locales) && !!@@available_locales )
|
@@ -143,5 +145,21 @@ module I18n
|
|
143
145
|
def enforce_available_locales=(enforce_available_locales)
|
144
146
|
@@enforce_available_locales = enforce_available_locales
|
145
147
|
end
|
148
|
+
|
149
|
+
# Returns the current interpolation patterns. Defaults to
|
150
|
+
# I18n::DEFAULT_INTERPOLATION_PATTERNS.
|
151
|
+
def interpolation_patterns
|
152
|
+
@@interpolation_patterns ||= I18n::DEFAULT_INTERPOLATION_PATTERNS.dup
|
153
|
+
end
|
154
|
+
|
155
|
+
# Sets the current interpolation patterns. Used to set a interpolation
|
156
|
+
# patterns.
|
157
|
+
#
|
158
|
+
# E.g. using {{}} as a placeholder like "{{hello}}, world!":
|
159
|
+
#
|
160
|
+
# I18n.config.interpolation_patterns << /\{\{(\w+)\}\}/
|
161
|
+
def interpolation_patterns=(interpolation_patterns)
|
162
|
+
@@interpolation_patterns = interpolation_patterns
|
163
|
+
end
|
146
164
|
end
|
147
165
|
end
|
data/lib/i18n/core_ext/hash.rb
CHANGED
@@ -1,29 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module I18n
|
2
|
+
module HashRefinements
|
3
|
+
refine Hash do
|
4
|
+
using I18n::HashRefinements
|
5
|
+
def except(*keys)
|
6
|
+
dup.except!(*keys)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def except!(*keys)
|
10
|
+
keys.each { |key| delete(key) }
|
11
|
+
self
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end unless Hash.method_defined?(:deep_symbolize_keys)
|
14
|
+
def deep_symbolize_keys
|
15
|
+
each_with_object({}) do |(key, value), result|
|
16
|
+
result[symbolize_key(key)] = deep_symbolize_keys_in_object(value)
|
17
|
+
result
|
18
|
+
end
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
# deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
|
22
|
+
def deep_merge!(data)
|
23
|
+
merger = lambda do |_key, v1, v2|
|
24
|
+
Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
|
25
|
+
end
|
26
|
+
merge!(data, &merger)
|
27
|
+
end
|
28
|
+
|
29
|
+
def symbolize_key(key)
|
30
|
+
key.respond_to?(:to_sym) ? key.to_sym : key
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def deep_symbolize_keys_in_object(value)
|
36
|
+
case value
|
37
|
+
when Hash
|
38
|
+
value.deep_symbolize_keys
|
39
|
+
when Array
|
40
|
+
value.map { |e| deep_symbolize_keys_in_object(e) }
|
41
|
+
else
|
42
|
+
value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
23
46
|
end
|
24
|
-
|
25
|
-
def deep_merge!(data)
|
26
|
-
merge!(data, &MERGER)
|
27
|
-
end unless Hash.method_defined?(:deep_merge!)
|
28
47
|
end
|
29
|
-
|
data/lib/i18n/exceptions.rb
CHANGED
@@ -1,27 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cgi'
|
2
4
|
|
3
5
|
module I18n
|
4
|
-
# Handles exceptions raised in the backend. All exceptions except for
|
5
|
-
# MissingTranslationData exceptions are re-thrown. When a MissingTranslationData
|
6
|
-
# was caught the handler returns an error message string containing the key/scope.
|
7
|
-
# Note that the exception handler is not called when the option :throw was given.
|
8
6
|
class ExceptionHandler
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
when Exception
|
15
|
-
raise exception
|
16
|
-
else
|
17
|
-
throw :exception, exception
|
18
|
-
end
|
7
|
+
def call(exception, _locale, _key, _options)
|
8
|
+
if exception.is_a?(MissingTranslation)
|
9
|
+
exception.message
|
10
|
+
else
|
11
|
+
raise exception
|
19
12
|
end
|
20
|
-
|
13
|
+
end
|
21
14
|
end
|
22
15
|
|
23
16
|
class ArgumentError < ::ArgumentError; end
|
24
17
|
|
18
|
+
class Disabled < ArgumentError
|
19
|
+
def initialize(method)
|
20
|
+
super(<<~MESSAGE)
|
21
|
+
I18n.#{method} is currently disabled, likely because your application is still in its loading phase.
|
22
|
+
|
23
|
+
This method is meant to display text in the user locale, so calling it before the user locale has
|
24
|
+
been set is likely to display text from the wrong locale to some users.
|
25
|
+
|
26
|
+
If you have a legitimate reason to access i18n data outside of the user flow, you can do so by passing
|
27
|
+
the desired locale explictly with the `locale` argument, e.g. `I18n.#{method}(..., locale: :en)`
|
28
|
+
MESSAGE
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
25
32
|
class InvalidLocale < ArgumentError
|
26
33
|
attr_reader :locale
|
27
34
|
def initialize(locale)
|
@@ -42,7 +49,7 @@ module I18n
|
|
42
49
|
module Base
|
43
50
|
attr_reader :locale, :key, :options
|
44
51
|
|
45
|
-
def initialize(locale, key, options =
|
52
|
+
def initialize(locale, key, options = EMPTY_HASH)
|
46
53
|
@key, @locale, @options = key, locale, options.dup
|
47
54
|
options.each { |k, v| self.options[k] = v.inspect if v.is_a?(Proc) }
|
48
55
|
end
|
data/lib/i18n/gettext/helpers.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'i18n/gettext'
|
2
4
|
|
3
5
|
module I18n
|
@@ -16,7 +18,7 @@ module I18n
|
|
16
18
|
msgsid
|
17
19
|
end
|
18
20
|
|
19
|
-
def gettext(msgid, options =
|
21
|
+
def gettext(msgid, options = EMPTY_HASH)
|
20
22
|
I18n.t(msgid, { :default => msgid, :separator => '|' }.merge(options))
|
21
23
|
end
|
22
24
|
alias _ gettext
|
@@ -28,7 +28,7 @@ module_eval <<'..end src/poparser.ry modeval..id7a99570e05', 'src/poparser.ry',
|
|
28
28
|
ret.gsub!(/\\"/, "\"")
|
29
29
|
ret
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def parse(str, data, ignore_fuzzy = true)
|
33
33
|
@comments = []
|
34
34
|
@data = data
|
@@ -64,7 +64,7 @@ module_eval <<'..end src/poparser.ry modeval..id7a99570e05', 'src/poparser.ry',
|
|
64
64
|
str = $'
|
65
65
|
when /\A\#(.*)/
|
66
66
|
@q.push [:COMMENT, $&]
|
67
|
-
str = $'
|
67
|
+
str = $'
|
68
68
|
when /\A\"(.*)\"/
|
69
69
|
@q.push [:STRING, $1]
|
70
70
|
str = $'
|
@@ -73,7 +73,7 @@ module_eval <<'..end src/poparser.ry modeval..id7a99570e05', 'src/poparser.ry',
|
|
73
73
|
#@q.push [:STRING, c]
|
74
74
|
str = str[1..-1]
|
75
75
|
end
|
76
|
-
end
|
76
|
+
end
|
77
77
|
@q.push [false, '$end']
|
78
78
|
if $DEBUG
|
79
79
|
@q.each do |a,b|
|
@@ -88,7 +88,7 @@ module_eval <<'..end src/poparser.ry modeval..id7a99570e05', 'src/poparser.ry',
|
|
88
88
|
end
|
89
89
|
@data
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def next_token
|
93
93
|
@q.shift
|
94
94
|
end
|
@@ -101,11 +101,11 @@ module_eval <<'..end src/poparser.ry modeval..id7a99570e05', 'src/poparser.ry',
|
|
101
101
|
@comments.clear
|
102
102
|
@msgctxt = ""
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def on_comment(comment)
|
106
106
|
@fuzzy = true if (/fuzzy/ =~ comment)
|
107
107
|
@comments << comment
|
108
|
-
end
|
108
|
+
end
|
109
109
|
|
110
110
|
|
111
111
|
..end src/poparser.ry modeval..id7a99570e05
|
@@ -245,7 +245,7 @@ module_eval <<'.,.,', 'src/poparser.ry', 25
|
|
245
245
|
|
246
246
|
module_eval <<'.,.,', 'src/poparser.ry', 48
|
247
247
|
def _reduce_8( val, _values, result )
|
248
|
-
if @fuzzy and $ignore_fuzzy
|
248
|
+
if @fuzzy and $ignore_fuzzy
|
249
249
|
if val[1] != ""
|
250
250
|
$stderr.print _("Warning: fuzzy message was ignored.\n")
|
251
251
|
$stderr.print " msgid '#{val[1]}'\n"
|
data/lib/i18n/gettext.rb
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
# http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
|
3
3
|
|
4
4
|
module I18n
|
5
|
-
|
5
|
+
DEFAULT_INTERPOLATION_PATTERNS = [
|
6
6
|
/%%/,
|
7
7
|
/%\{(\w+)\}/, # matches placeholders like "%{foo}"
|
8
8
|
/%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
|
9
|
-
|
9
|
+
].freeze
|
10
|
+
INTERPOLATION_PATTERN = Regexp.union(DEFAULT_INTERPOLATION_PATTERNS)
|
11
|
+
deprecate_constant :INTERPOLATION_PATTERN if method_defined? :INTERPOLATION_PATTERN
|
10
12
|
|
11
13
|
class << self
|
12
14
|
# Return String or raises MissingInterpolationArgument exception.
|
@@ -18,7 +20,7 @@ module I18n
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def interpolate_hash(string, values)
|
21
|
-
string.gsub(
|
23
|
+
string.gsub(Regexp.union(config.interpolation_patterns)) do |match|
|
22
24
|
if match == '%%'
|
23
25
|
'%'
|
24
26
|
else
|
@@ -56,7 +56,7 @@ module I18n
|
|
56
56
|
def initialize(*mappings)
|
57
57
|
@map = {}
|
58
58
|
map(mappings.pop) if mappings.last.is_a?(Hash)
|
59
|
-
self.defaults = mappings.empty? ? [
|
59
|
+
self.defaults = mappings.empty? ? [] : mappings
|
60
60
|
end
|
61
61
|
|
62
62
|
def defaults=(defaults)
|
data/lib/i18n/locale.rb
CHANGED
data/lib/i18n/middleware.rb
CHANGED
@@ -43,7 +43,7 @@ module I18n
|
|
43
43
|
end
|
44
44
|
|
45
45
|
test "interpolation: it does not raise I18n::MissingInterpolationArgument for escaped variables" do
|
46
|
-
assert_nothing_raised
|
46
|
+
assert_nothing_raised do
|
47
47
|
assert_equal 'Barr %{foo}', interpolate(:default => '%{bar} %%{foo}', :bar => 'Barr')
|
48
48
|
end
|
49
49
|
end
|
@@ -104,9 +104,10 @@ module I18n
|
|
104
104
|
end
|
105
105
|
|
106
106
|
test "interpolation: given a translations containing a reserved key it raises I18n::ReservedInterpolationKey" do
|
107
|
-
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{
|
108
|
-
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{
|
109
|
-
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{separator}'
|
107
|
+
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{exception_handler}') }
|
108
|
+
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{default}') }
|
109
|
+
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{separator}') }
|
110
|
+
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{scope}') }
|
110
111
|
end
|
111
112
|
|
112
113
|
test "interpolation: deep interpolation for default string" do
|
@@ -11,8 +11,7 @@ module I18n
|
|
11
11
|
end
|
12
12
|
|
13
13
|
test "localize Date: given the short format it uses it" do
|
14
|
-
|
15
|
-
assert_equal '01. Mar', I18n.l(@date, :format => :short, :locale => :de)
|
14
|
+
assert_equal '01. Mär', I18n.l(@date, :format => :short, :locale => :de)
|
16
15
|
end
|
17
16
|
|
18
17
|
test "localize Date: given the long format it uses it" do
|
@@ -27,17 +26,40 @@ module I18n
|
|
27
26
|
assert_equal 'Samstag', I18n.l(@date, :format => '%A', :locale => :de)
|
28
27
|
end
|
29
28
|
|
29
|
+
test "localize Date: given a uppercased day name format it returns the correct day name in upcase" do
|
30
|
+
assert_equal 'samstag'.upcase, I18n.l(@date, :format => '%^A', :locale => :de)
|
31
|
+
end
|
32
|
+
|
30
33
|
test "localize Date: given an abbreviated day name format it returns the correct abbreviated day name" do
|
31
34
|
assert_equal 'Sa', I18n.l(@date, :format => '%a', :locale => :de)
|
32
35
|
end
|
33
36
|
|
37
|
+
test "localize Date: given an abbreviated and uppercased day name format it returns the correct abbreviated day name in upcase" do
|
38
|
+
assert_equal 'sa'.upcase, I18n.l(@date, :format => '%^a', :locale => :de)
|
39
|
+
end
|
40
|
+
|
34
41
|
test "localize Date: given a month name format it returns the correct month name" do
|
35
42
|
assert_equal 'März', I18n.l(@date, :format => '%B', :locale => :de)
|
36
43
|
end
|
37
44
|
|
45
|
+
test "localize Date: given a uppercased month name format it returns the correct month name in upcase" do
|
46
|
+
assert_equal 'märz'.upcase, I18n.l(@date, :format => '%^B', :locale => :de)
|
47
|
+
end
|
48
|
+
|
38
49
|
test "localize Date: given an abbreviated month name format it returns the correct abbreviated month name" do
|
39
|
-
|
40
|
-
|
50
|
+
assert_equal 'Mär', I18n.l(@date, :format => '%b', :locale => :de)
|
51
|
+
end
|
52
|
+
|
53
|
+
test "localize Date: given an abbreviated and uppercased month name format it returns the correct abbreviated month name in upcase" do
|
54
|
+
assert_equal 'mär'.upcase, I18n.l(@date, :format => '%^b', :locale => :de)
|
55
|
+
end
|
56
|
+
|
57
|
+
test "localize Date: given a date format with the month name upcased it returns the correct value" do
|
58
|
+
assert_equal '1. FEBRUAR 2008', I18n.l(::Date.new(2008, 2, 1), :format => "%-d. %^B %Y", :locale => :de)
|
59
|
+
end
|
60
|
+
|
61
|
+
test "localize Date: given missing translations it returns the correct error message" do
|
62
|
+
assert_equal 'translation missing: fr.date.abbr_month_names', I18n.l(@date, :format => '%b', :locale => :fr)
|
41
63
|
end
|
42
64
|
|
43
65
|
test "localize Date: given an unknown format it does not fail" do
|
@@ -46,7 +68,7 @@ module I18n
|
|
46
68
|
|
47
69
|
test "localize Date: does not modify the options hash" do
|
48
70
|
options = { :format => '%b', :locale => :de }
|
49
|
-
assert_equal '
|
71
|
+
assert_equal 'Mär', I18n.l(@date, options)
|
50
72
|
assert_equal({ :format => '%b', :locale => :de }, options)
|
51
73
|
assert_nothing_raised { I18n.l(@date, options.freeze) }
|
52
74
|
end
|
@@ -85,7 +107,7 @@ module I18n
|
|
85
107
|
:day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
|
86
108
|
:abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
|
87
109
|
:month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
|
88
|
-
:abbr_month_names => %w(Jan Feb
|
110
|
+
:abbr_month_names => %w(Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil)
|
89
111
|
}
|
90
112
|
}
|
91
113
|
end
|
@@ -12,8 +12,7 @@ module I18n
|
|
12
12
|
end
|
13
13
|
|
14
14
|
test "localize DateTime: given the short format it uses it" do
|
15
|
-
|
16
|
-
assert_equal '01. Mar 06:00', I18n.l(@datetime, :format => :short, :locale => :de)
|
15
|
+
assert_equal '01. Mär 06:00', I18n.l(@datetime, :format => :short, :locale => :de)
|
17
16
|
end
|
18
17
|
|
19
18
|
test "localize DateTime: given the long format it uses it" do
|
@@ -21,25 +20,47 @@ module I18n
|
|
21
20
|
end
|
22
21
|
|
23
22
|
test "localize DateTime: given the default format it uses it" do
|
24
|
-
|
25
|
-
assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@datetime, :format => :default, :locale => :de)
|
23
|
+
assert_equal 'Sa, 01. Mär 2008 06:00:00 +0000', I18n.l(@datetime, :format => :default, :locale => :de)
|
26
24
|
end
|
27
25
|
|
28
26
|
test "localize DateTime: given a day name format it returns the correct day name" do
|
29
27
|
assert_equal 'Samstag', I18n.l(@datetime, :format => '%A', :locale => :de)
|
30
28
|
end
|
31
29
|
|
30
|
+
test "localize DateTime: given a uppercased day name format it returns the correct day name in upcase" do
|
31
|
+
assert_equal 'samstag'.upcase, I18n.l(@datetime, :format => '%^A', :locale => :de)
|
32
|
+
end
|
33
|
+
|
32
34
|
test "localize DateTime: given an abbreviated day name format it returns the correct abbreviated day name" do
|
33
35
|
assert_equal 'Sa', I18n.l(@datetime, :format => '%a', :locale => :de)
|
34
36
|
end
|
35
37
|
|
38
|
+
test "localize DateTime: given an abbreviated and uppercased day name format it returns the correct abbreviated day name in upcase" do
|
39
|
+
assert_equal 'sa'.upcase, I18n.l(@datetime, :format => '%^a', :locale => :de)
|
40
|
+
end
|
41
|
+
|
36
42
|
test "localize DateTime: given a month name format it returns the correct month name" do
|
37
43
|
assert_equal 'März', I18n.l(@datetime, :format => '%B', :locale => :de)
|
38
44
|
end
|
39
45
|
|
46
|
+
test "localize DateTime: given a uppercased month name format it returns the correct month name in upcase" do
|
47
|
+
assert_equal 'märz'.upcase, I18n.l(@datetime, :format => '%^B', :locale => :de)
|
48
|
+
end
|
49
|
+
|
40
50
|
test "localize DateTime: given an abbreviated month name format it returns the correct abbreviated month name" do
|
41
|
-
|
42
|
-
|
51
|
+
assert_equal 'Mär', I18n.l(@datetime, :format => '%b', :locale => :de)
|
52
|
+
end
|
53
|
+
|
54
|
+
test "localize DateTime: given an abbreviated and uppercased month name format it returns the correct abbreviated month name in upcase" do
|
55
|
+
assert_equal 'mär'.upcase, I18n.l(@datetime, :format => '%^b', :locale => :de)
|
56
|
+
end
|
57
|
+
|
58
|
+
test "localize DateTime: given a date format with the month name upcased it returns the correct value" do
|
59
|
+
assert_equal '1. FEBRUAR 2008', I18n.l(::DateTime.new(2008, 2, 1, 6), :format => "%-d. %^B %Y", :locale => :de)
|
60
|
+
end
|
61
|
+
|
62
|
+
test "localize DateTime: given missing translations it returns the correct error message" do
|
63
|
+
assert_equal 'translation missing: fr.date.abbr_month_names', I18n.l(@datetime, :format => '%b', :locale => :fr)
|
43
64
|
end
|
44
65
|
|
45
66
|
test "localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
|
@@ -12,8 +12,7 @@ module I18n
|
|
12
12
|
end
|
13
13
|
|
14
14
|
test "localize Time: given the short format it uses it" do
|
15
|
-
|
16
|
-
assert_equal '01. Mar 06:00', I18n.l(@time, :format => :short, :locale => :de)
|
15
|
+
assert_equal '01. Mär 06:00', I18n.l(@time, :format => :short, :locale => :de)
|
17
16
|
end
|
18
17
|
|
19
18
|
test "localize Time: given the long format it uses it" do
|
@@ -29,17 +28,40 @@ module I18n
|
|
29
28
|
assert_equal 'Samstag', I18n.l(@time, :format => '%A', :locale => :de)
|
30
29
|
end
|
31
30
|
|
31
|
+
test "localize Time: given a uppercased day name format it returns the correct day name in upcase" do
|
32
|
+
assert_equal 'samstag'.upcase, I18n.l(@time, :format => '%^A', :locale => :de)
|
33
|
+
end
|
34
|
+
|
32
35
|
test "localize Time: given an abbreviated day name format it returns the correct abbreviated day name" do
|
33
36
|
assert_equal 'Sa', I18n.l(@time, :format => '%a', :locale => :de)
|
34
37
|
end
|
35
38
|
|
39
|
+
test "localize Time: given an abbreviated and uppercased day name format it returns the correct abbreviated day name in upcase" do
|
40
|
+
assert_equal 'sa'.upcase, I18n.l(@time, :format => '%^a', :locale => :de)
|
41
|
+
end
|
42
|
+
|
36
43
|
test "localize Time: given a month name format it returns the correct month name" do
|
37
44
|
assert_equal 'März', I18n.l(@time, :format => '%B', :locale => :de)
|
38
45
|
end
|
39
46
|
|
47
|
+
test "localize Time: given a uppercased month name format it returns the correct month name in upcase" do
|
48
|
+
assert_equal 'märz'.upcase, I18n.l(@time, :format => '%^B', :locale => :de)
|
49
|
+
end
|
50
|
+
|
40
51
|
test "localize Time: given an abbreviated month name format it returns the correct abbreviated month name" do
|
41
|
-
|
42
|
-
|
52
|
+
assert_equal 'Mär', I18n.l(@time, :format => '%b', :locale => :de)
|
53
|
+
end
|
54
|
+
|
55
|
+
test "localize Time: given an abbreviated and uppercased month name format it returns the correct abbreviated month name in upcase" do
|
56
|
+
assert_equal 'mär'.upcase, I18n.l(@time, :format => '%^b', :locale => :de)
|
57
|
+
end
|
58
|
+
|
59
|
+
test "localize Time: given a date format with the month name upcased it returns the correct value" do
|
60
|
+
assert_equal '1. FEBRUAR 2008', I18n.l(::Time.utc(2008, 2, 1, 6, 0), :format => "%-d. %^B %Y", :locale => :de)
|
61
|
+
end
|
62
|
+
|
63
|
+
test "localize Time: given missing translations it returns the correct error message" do
|
64
|
+
assert_equal 'translation missing: fr.date.abbr_month_names', I18n.l(@time, :format => '%b', :locale => :fr)
|
43
65
|
end
|
44
66
|
|
45
67
|
test "localize Time: given a meridian indicator format it returns the correct meridian indicator" do
|
data/lib/i18n/tests.rb
CHANGED
data/lib/i18n/version.rb
CHANGED