r18n-core 3.1.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/base/cy.yml +34 -0
- data/lib/r18n-core/i18n.rb +2 -5
- data/lib/r18n-core/locale.rb +18 -10
- data/lib/r18n-core/translated_string.rb +15 -1
- data/lib/r18n-core/translation.rb +1 -1
- data/lib/r18n-core/unsupported_locale.rb +6 -1
- data/lib/r18n-core/untranslated.rb +13 -3
- data/lib/r18n-core/utils.rb +17 -8
- data/lib/r18n-core/version.rb +1 -1
- data/lib/r18n-core/yaml_loader.rb +7 -3
- data/locales/af.rb +1 -1
- data/locales/az.rb +1 -1
- data/locales/cs.rb +4 -4
- data/locales/cy.rb +50 -0
- data/locales/de.rb +1 -1
- data/locales/en-us.rb +1 -1
- data/locales/en.rb +10 -10
- data/locales/eo.rb +1 -1
- data/locales/fa.rb +1 -1
- data/locales/fi.rb +1 -1
- data/locales/fr.rb +2 -2
- data/locales/hr.rb +5 -5
- data/locales/hu.rb +2 -2
- data/locales/it.rb +2 -2
- data/locales/ja.rb +1 -1
- data/locales/kk.rb +1 -1
- data/locales/lv.rb +4 -4
- data/locales/nb.rb +1 -1
- data/locales/nl.rb +1 -1
- data/locales/pl.rb +5 -5
- data/locales/ru.rb +4 -4
- data/locales/sk.rb +3 -3
- data/locales/sr-latn.rb +5 -5
- data/locales/sv-se.rb +1 -1
- data/locales/th.rb +2 -2
- data/locales/tr.rb +2 -2
- data/locales/vi.rb +2 -2
- data/locales/zh.rb +1 -1
- data/spec/i18n_spec.rb +1 -1
- data/spec/locale_spec.rb +83 -47
- data/spec/locales/fr_spec.rb +1 -1
- data/spec/locales/hu_spec.rb +1 -1
- data/spec/locales/it_spec.rb +1 -1
- data/spec/r18n_spec.rb +6 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/translated_spec.rb +7 -1
- data/spec/translation_spec.rb +15 -0
- data/spec/translations/yaml/en.yaml +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea9e0df5d7d9a6465ecbb70590f24b69578fe9bcf703a825f7f861dae17ab8d5
|
4
|
+
data.tar.gz: ce67040d879d2edd3e14bb17d5b3cebff9a4824a25ace0d4caf15d5c4292a6e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed567f238f886118551f5243c409fea38722c3508733943731489840bb69507613edb9f5d46031bfbe230d1f339d1c7f757d3cdc5adb102d92559df07b3c18d4
|
7
|
+
data.tar.gz: 825933ccff178daf0648cf78f1f8b9378149cb151bfcddf2835165c66c7dec0bb785368910b6ec0435ccfb39331d953de6d9029b8e5f916ee7420e53fa0b6cab
|
data/README.md
CHANGED
data/base/cy.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
ok: 'Iawn'
|
2
|
+
save: 'Cadw'
|
3
|
+
cancel: 'Canslo'
|
4
|
+
'yes': 'Ie'
|
5
|
+
'no': 'Na'
|
6
|
+
exit: 'Gadael'
|
7
|
+
delete: 'Dileu'
|
8
|
+
|
9
|
+
human_time:
|
10
|
+
after_days: !!pl
|
11
|
+
1: 'ar ôl %1 diwrnod'
|
12
|
+
2: 'ar ôl %1 ddiwrnod'
|
13
|
+
n: 'ar ôl %1 diwrnod'
|
14
|
+
tomorrow: 'yfory'
|
15
|
+
after_hours: !!pl
|
16
|
+
1: 'ar ôl %1 awr'
|
17
|
+
n: 'ar ôl %1 awr'
|
18
|
+
after_minutes: !!pl
|
19
|
+
1: 'ar ôl %1 munud'
|
20
|
+
n: 'ar ôl %1 munud'
|
21
|
+
now: 'nawr'
|
22
|
+
today: 'heddiw'
|
23
|
+
minutes_ago: !!pl
|
24
|
+
1: '%1 munud yn ôl'
|
25
|
+
2: '%1 funud yn ôl'
|
26
|
+
n: '%1 munud yn ôl'
|
27
|
+
hours_ago: !!pl
|
28
|
+
1: '%1 awr yn ôl'
|
29
|
+
n: '%1 awr yn ôl'
|
30
|
+
yesterday: 'ddoe'
|
31
|
+
days_ago: !!pl
|
32
|
+
1: '%1 diwrnod yn ôl'
|
33
|
+
2: '%1 ddiwrnod yn ôl'
|
34
|
+
n: '%1 diwrnod yn ôl'
|
data/lib/r18n-core/i18n.rb
CHANGED
@@ -199,7 +199,7 @@ module R18n
|
|
199
199
|
|
200
200
|
# Reload translations.
|
201
201
|
def reload!
|
202
|
-
@
|
202
|
+
@available_locales = @available_codes = nil
|
203
203
|
@translation_places = self.class.convert_places(@original_places)
|
204
204
|
|
205
205
|
available_in_places = @translation_places.map { |i| [i, i.available] }
|
@@ -207,8 +207,6 @@ module R18n
|
|
207
207
|
R18n.extension_places.map { |i| [i, i.available] }
|
208
208
|
|
209
209
|
unless defined? @locale
|
210
|
-
# It's array!
|
211
|
-
# rubocop:disable Perfomance/HashEachMethods
|
212
210
|
available_in_places.each do |_place, available|
|
213
211
|
@locales.each do |locale|
|
214
212
|
if available.include? locale
|
@@ -218,7 +216,6 @@ module R18n
|
|
218
216
|
end
|
219
217
|
break if defined? @locale
|
220
218
|
end
|
221
|
-
# rubocop:enable Perfomance/HashEachMethods
|
222
219
|
end
|
223
220
|
@locale ||= @locales.first
|
224
221
|
unless @locale.supported?
|
@@ -255,7 +252,7 @@ module R18n
|
|
255
252
|
|
256
253
|
# Return Array of locales with available translations.
|
257
254
|
def available_locales
|
258
|
-
@
|
255
|
+
@available_locales ||= R18n.available_locales(@translation_places)
|
259
256
|
end
|
260
257
|
|
261
258
|
# Convert +object+ to String, according to the rules of the current locale.
|
data/lib/r18n-core/locale.rb
CHANGED
@@ -70,10 +70,13 @@ module R18n
|
|
70
70
|
File.exist?(File.join(LOCALES_DIR, "#{locale}.rb"))
|
71
71
|
end
|
72
72
|
|
73
|
+
def self.sanitize_code(code)
|
74
|
+
code.to_s.gsub(/[^-_a-zA-Z]/, '').tr('_', '-').downcase
|
75
|
+
end
|
76
|
+
|
73
77
|
# Load locale by RFC 3066 +code+.
|
74
78
|
def self.load(code)
|
75
|
-
|
76
|
-
code = original.tr('_', '-').downcase
|
79
|
+
code = sanitize_code code
|
77
80
|
|
78
81
|
@@loaded[code] ||= begin
|
79
82
|
if exists? code
|
@@ -81,7 +84,7 @@ module R18n
|
|
81
84
|
name = code.gsub(/\w+/, &:capitalize).delete('-')
|
82
85
|
R18n::Locales.const_get(name).new
|
83
86
|
else
|
84
|
-
UnsupportedLocale.new(
|
87
|
+
UnsupportedLocale.new(code)
|
85
88
|
end
|
86
89
|
end
|
87
90
|
end
|
@@ -115,7 +118,7 @@ module R18n
|
|
115
118
|
time_am: 'AM',
|
116
119
|
time_pm: 'PM',
|
117
120
|
time_format: '_ %H:%M',
|
118
|
-
full_format: '
|
121
|
+
full_format: '%-d %B',
|
119
122
|
year_format: '_ %Y'
|
120
123
|
|
121
124
|
def month_standalone
|
@@ -178,7 +181,12 @@ module R18n
|
|
178
181
|
|
179
182
|
send format_method_name, obj, *params
|
180
183
|
else
|
181
|
-
|
184
|
+
format_method_name =
|
185
|
+
"format_#{Utils.underscore(obj.class.name)}_#{format}"
|
186
|
+
|
187
|
+
return obj.to_s unless respond_to? format_method_name
|
188
|
+
|
189
|
+
send format_method_name, obj, *params
|
182
190
|
end
|
183
191
|
end
|
184
192
|
|
@@ -234,7 +242,7 @@ module R18n
|
|
234
242
|
# Format +time+ in human usable form. For example “5 minutes ago” or
|
235
243
|
# “yesterday”. In +now+ you can set base time, which be used to get relative
|
236
244
|
# time. For special cases you can replace it in locale’s class.
|
237
|
-
def format_time_human(time, i18n, now =
|
245
|
+
def format_time_human(time, i18n, now = time.class.now, *_params)
|
238
246
|
diff = time - now
|
239
247
|
minutes = time.is_a?(DateTime) ? diff * 24 * 60.0 : diff / 60.0
|
240
248
|
diff = minutes.abs
|
@@ -299,10 +307,10 @@ module R18n
|
|
299
307
|
strftime(date, format)
|
300
308
|
end
|
301
309
|
|
302
|
-
# Return pluralization type for +
|
303
|
-
# cases you can replace it in locale’s class.
|
304
|
-
def pluralize(
|
305
|
-
case
|
310
|
+
# Return pluralization type for +number+ of items. This is simple form.
|
311
|
+
# For special cases you can replace it in locale’s class.
|
312
|
+
def pluralize(number)
|
313
|
+
case number
|
306
314
|
when 0
|
307
315
|
0
|
308
316
|
when 1
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'untranslated'
|
4
|
+
|
3
5
|
# Translation string for i18n support.
|
4
6
|
#
|
5
7
|
# Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
@@ -52,7 +54,7 @@ module R18n
|
|
52
54
|
|
53
55
|
# Override to_s to make string html safe if `html_safe` method is defined.
|
54
56
|
def to_s
|
55
|
-
if
|
57
|
+
if html_safe?
|
56
58
|
super.html_safe
|
57
59
|
else
|
58
60
|
String.new(super)
|
@@ -82,9 +84,21 @@ module R18n
|
|
82
84
|
Untranslated.new(translated, key, @locale, @filters)
|
83
85
|
end
|
84
86
|
|
87
|
+
NON_KEYS_METHODS = [
|
88
|
+
*Untranslated::NON_KEYS_METHODS,
|
89
|
+
:html_safe,
|
90
|
+
:to_text
|
91
|
+
].freeze
|
92
|
+
|
85
93
|
# Return untranslated, when user try to go deeper in translation.
|
86
94
|
def method_missing(name, *_params)
|
95
|
+
return super if NON_KEYS_METHODS.include?(name)
|
87
96
|
get_untranslated(name.to_s)
|
88
97
|
end
|
98
|
+
|
99
|
+
def respond_to_missing?(name, *args)
|
100
|
+
return super if NON_KEYS_METHODS.include?(name)
|
101
|
+
true
|
102
|
+
end
|
89
103
|
end
|
90
104
|
end
|
@@ -56,7 +56,12 @@ module R18n
|
|
56
56
|
|
57
57
|
# Proxy to default locale object.
|
58
58
|
def method_missing(name, *params)
|
59
|
-
@base.
|
59
|
+
return super unless @base.respond_to? name
|
60
|
+
@base.public_send(name, *params)
|
61
|
+
end
|
62
|
+
|
63
|
+
def respond_to_missing?(name, *args)
|
64
|
+
@base.send __method__, name, *args
|
60
65
|
end
|
61
66
|
end
|
62
67
|
end
|
@@ -73,15 +73,25 @@ module R18n
|
|
73
73
|
new arr[1], arr[2], R18n.locale(arr[0]), GlobalFilterList.instance
|
74
74
|
end
|
75
75
|
|
76
|
+
NON_KEYS_METHODS = %i[
|
77
|
+
to_ary
|
78
|
+
to_hash
|
79
|
+
marshal_dump
|
80
|
+
marshal_load
|
81
|
+
].freeze
|
82
|
+
|
76
83
|
def method_missing(name, *_params)
|
77
84
|
# It is need to fix some hack in specs
|
78
|
-
if name
|
79
|
-
raise NoMethodError, "undefined method `to_ary' for #{self}"
|
80
|
-
end
|
85
|
+
return super if NON_KEYS_METHODS.include?(name)
|
81
86
|
|
82
87
|
self[name]
|
83
88
|
end
|
84
89
|
|
90
|
+
def respond_to_missing?(name, *args)
|
91
|
+
return super if NON_KEYS_METHODS.include?(name)
|
92
|
+
true
|
93
|
+
end
|
94
|
+
|
85
95
|
def [](*params)
|
86
96
|
Untranslated.new(translated_path, "#{@untranslated_path}.#{params.first}",
|
87
97
|
@locale, @filters)
|
data/lib/r18n-core/utils.rb
CHANGED
@@ -43,17 +43,26 @@ module R18n
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# Recursively hash merge.
|
46
|
-
def self.deep_merge!(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if
|
51
|
-
deep_merge!(
|
46
|
+
def self.deep_merge!(one, another)
|
47
|
+
another.each_pair do |key, another_value|
|
48
|
+
value = one[key]
|
49
|
+
one[key] =
|
50
|
+
if value.is_a?(Hash) && another_value.is_a?(Hash)
|
51
|
+
deep_merge!(value, another_value)
|
52
52
|
else
|
53
|
-
|
53
|
+
another_value
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
one
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.underscore(string)
|
60
|
+
string
|
61
|
+
.gsub(/::/, '/')
|
62
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
63
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
64
|
+
.tr('-', '_')
|
65
|
+
.downcase
|
57
66
|
end
|
58
67
|
end
|
59
68
|
end
|
data/lib/r18n-core/version.rb
CHANGED
@@ -32,6 +32,8 @@ module R18n
|
|
32
32
|
class YAML
|
33
33
|
include ::R18n::YamlMethods
|
34
34
|
|
35
|
+
FILE_EXT = 'y{,a}ml'.freeze
|
36
|
+
|
35
37
|
# Dir with translations.
|
36
38
|
attr_reader :dir
|
37
39
|
|
@@ -43,8 +45,8 @@ module R18n
|
|
43
45
|
|
44
46
|
# Array of locales, which has translations in +dir+.
|
45
47
|
def available
|
46
|
-
Dir.glob(File.join(@dir,
|
47
|
-
.map { |i| File.basename(i, '
|
48
|
+
Dir.glob(File.join(@dir, "**/*.#{FILE_EXT}"))
|
49
|
+
.map { |i| File.basename(i, '.*') }.uniq
|
48
50
|
.map { |i| R18n.locale(i) }
|
49
51
|
end
|
50
52
|
|
@@ -53,7 +55,9 @@ module R18n
|
|
53
55
|
initialize_types
|
54
56
|
|
55
57
|
translations = {}
|
56
|
-
Dir.glob(
|
58
|
+
Dir.glob(
|
59
|
+
File.join(@dir, "**/#{locale.code.downcase}.#{FILE_EXT}")
|
60
|
+
).each do |i|
|
57
61
|
Utils.deep_merge!(translations, ::YAML.load_file(i) || {})
|
58
62
|
end
|
59
63
|
transform(translations)
|
data/locales/af.rb
CHANGED
data/locales/az.rb
CHANGED
data/locales/cs.rb
CHANGED
@@ -19,15 +19,15 @@ module R18n
|
|
19
19
|
|
20
20
|
time_am: 'dop.',
|
21
21
|
time_pm: 'odp.',
|
22
|
-
date_format: '
|
23
|
-
full_format: '
|
22
|
+
date_format: '%-d. %m. %Y',
|
23
|
+
full_format: '%-d. %B',
|
24
24
|
|
25
25
|
number_decimal: ',',
|
26
26
|
number_group: ' '
|
27
27
|
)
|
28
28
|
|
29
|
-
def pluralize(
|
30
|
-
case
|
29
|
+
def pluralize(number)
|
30
|
+
case number
|
31
31
|
when 0
|
32
32
|
0
|
33
33
|
when 1
|
data/locales/cy.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module R18n
|
4
|
+
module Locales
|
5
|
+
# Welsh locale
|
6
|
+
class Cy < Locale
|
7
|
+
set(
|
8
|
+
title: 'Welsh',
|
9
|
+
sublocales: [],
|
10
|
+
|
11
|
+
week_start: :sunday,
|
12
|
+
wday_names: ["Dydd Sul", "Dydd Llun", "Dydd Mawrth", "Dydd Mercher", "Dydd Iau", "Dydd Gwener", "Dydd Sadwrn"],
|
13
|
+
wday_abbrs: %w[Sul Llu Maw Mer Iau Gwe Sad],
|
14
|
+
|
15
|
+
month_names: %w[Ionawr Chwefror Mawrth Ebrill Mai Mehefin Gorffennaf Awst Medi Hydref Tachwedd Rhagfyr],
|
16
|
+
month_abbrs: %w[Ion Chw Maw Ebr Mai Meh Gor Aws Med Hyd Tac Rha],
|
17
|
+
|
18
|
+
date_format: '%Y-%m-%d',
|
19
|
+
full_format: '%e o %B',
|
20
|
+
year_format: '_, %Y',
|
21
|
+
|
22
|
+
number_decimal: '.',
|
23
|
+
number_group: ','
|
24
|
+
)
|
25
|
+
|
26
|
+
def ordinalize(n)
|
27
|
+
case n % 10
|
28
|
+
when 1 then "#{n}af"
|
29
|
+
when 2 then "#{n}il"
|
30
|
+
when 3 then "#{n}ydd"
|
31
|
+
when 4 then "#{n}ydd"
|
32
|
+
when 11 then "#{n}eg"
|
33
|
+
when 13 then "#{n}eg"
|
34
|
+
when 14 then "#{n}eg"
|
35
|
+
when 16 then "#{n}eg"
|
36
|
+
when 17 then "#{n}eg"
|
37
|
+
when 19 then "#{n}eg"
|
38
|
+
when 21..31 then "#{n}ain"
|
39
|
+
else "#{n}ed"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def format_date_full(date, year = true, *_params)
|
44
|
+
format = full_format
|
45
|
+
format = year_format.sub('_', format) if year
|
46
|
+
strftime(date, format.sub('%e', ordinalize(date.mday)))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/locales/de.rb
CHANGED
data/locales/en-us.rb
CHANGED
data/locales/en.rb
CHANGED
@@ -18,22 +18,22 @@ module R18n
|
|
18
18
|
month_abbrs: %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec],
|
19
19
|
|
20
20
|
date_format: '%Y-%m-%d',
|
21
|
-
full_format: '
|
21
|
+
full_format: '%-d of %B',
|
22
22
|
year_format: '_, %Y',
|
23
23
|
|
24
24
|
number_decimal: '.',
|
25
25
|
number_group: ','
|
26
26
|
)
|
27
27
|
|
28
|
-
def ordinalize(
|
29
|
-
if (11..13).cover?(
|
30
|
-
"#{
|
28
|
+
def ordinalize(number)
|
29
|
+
if (11..13).cover?(number % 100)
|
30
|
+
"#{number}th"
|
31
31
|
else
|
32
|
-
case
|
33
|
-
when 1 then "#{
|
34
|
-
when 2 then "#{
|
35
|
-
when 3 then "#{
|
36
|
-
else "#{
|
32
|
+
case number % 10
|
33
|
+
when 1 then "#{number}st"
|
34
|
+
when 2 then "#{number}nd"
|
35
|
+
when 3 then "#{number}rd"
|
36
|
+
else "#{number}th"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -41,7 +41,7 @@ module R18n
|
|
41
41
|
def format_date_full(date, year = true, *_params)
|
42
42
|
format = full_format
|
43
43
|
format = year_format.sub('_', format) if year
|
44
|
-
strftime(date, format.sub('
|
44
|
+
strftime(date, format.sub('%-d', ordinalize(date.mday)))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/locales/eo.rb
CHANGED
data/locales/fa.rb
CHANGED
data/locales/fi.rb
CHANGED
data/locales/fr.rb
CHANGED
data/locales/hr.rb
CHANGED
@@ -17,18 +17,18 @@ module R18n
|
|
17
17
|
month_abbrs: %w[Sij Velj Ožu Tra Svi Lip Srp Kol Ruj Lis Stu Pro],
|
18
18
|
|
19
19
|
date_format: '%d.%m.%Y',
|
20
|
-
full_format: '
|
20
|
+
full_format: '%-d. %B',
|
21
21
|
|
22
22
|
number_decimal: ',',
|
23
23
|
number_group: '.'
|
24
24
|
)
|
25
25
|
|
26
|
-
def pluralize(
|
27
|
-
if
|
26
|
+
def pluralize(number)
|
27
|
+
if number.zero?
|
28
28
|
0
|
29
|
-
elsif
|
29
|
+
elsif number == 1
|
30
30
|
1
|
31
|
-
elsif
|
31
|
+
elsif number >= 2 && number <= 4
|
32
32
|
2
|
33
33
|
else
|
34
34
|
'n'
|
data/locales/hu.rb
CHANGED
@@ -16,7 +16,7 @@ module R18n
|
|
16
16
|
month_abbrs: %w[jan feb már ápr máj jún júl aug sze okt nov dec],
|
17
17
|
|
18
18
|
date_format: '%Y. %m. %d.',
|
19
|
-
full_format: '%B
|
19
|
+
full_format: '%B %-d.',
|
20
20
|
year_format: '%Y. _',
|
21
21
|
time_format: '_, %H:%M',
|
22
22
|
|
@@ -24,7 +24,7 @@ module R18n
|
|
24
24
|
number_group: ' '
|
25
25
|
)
|
26
26
|
|
27
|
-
def pluralize(
|
27
|
+
def pluralize(_number)
|
28
28
|
'n'
|
29
29
|
end
|
30
30
|
|
data/locales/it.rb
CHANGED
data/locales/ja.rb
CHANGED
data/locales/kk.rb
CHANGED
data/locales/lv.rb
CHANGED
@@ -20,17 +20,17 @@ module R18n
|
|
20
20
|
decembris],
|
21
21
|
|
22
22
|
date_format: '%d.%m.%Y.',
|
23
|
-
full_format: '
|
23
|
+
full_format: '%-d.%B',
|
24
24
|
year_format: '%Y.gada _',
|
25
25
|
|
26
26
|
number_decimal: ',',
|
27
27
|
number_group: ' '
|
28
28
|
)
|
29
29
|
|
30
|
-
def pluralize(
|
31
|
-
if
|
30
|
+
def pluralize(number)
|
31
|
+
if number.zero?
|
32
32
|
0
|
33
|
-
elsif
|
33
|
+
elsif number % 10 == 1 && number % 100 != 11
|
34
34
|
1
|
35
35
|
else
|
36
36
|
'n'
|
data/locales/nb.rb
CHANGED
data/locales/nl.rb
CHANGED
data/locales/pl.rb
CHANGED
@@ -24,13 +24,13 @@ module R18n
|
|
24
24
|
number_group: ' '
|
25
25
|
)
|
26
26
|
|
27
|
-
def pluralize(
|
28
|
-
return 0 if
|
29
|
-
case
|
27
|
+
def pluralize(number)
|
28
|
+
return 0 if number.zero?
|
29
|
+
case number % 10
|
30
30
|
when 1
|
31
|
-
|
31
|
+
number > 10 ? 'n' : 1
|
32
32
|
when 2..4
|
33
|
-
(11..19).cover?(
|
33
|
+
(11..19).cover?(number % 100) ? 'n' : 2
|
34
34
|
else
|
35
35
|
'n'
|
36
36
|
end
|
data/locales/ru.rb
CHANGED
@@ -25,12 +25,12 @@ module R18n
|
|
25
25
|
number_group: ' '
|
26
26
|
)
|
27
27
|
|
28
|
-
def pluralize(
|
29
|
-
if
|
28
|
+
def pluralize(number)
|
29
|
+
if number.zero?
|
30
30
|
0
|
31
|
-
elsif
|
31
|
+
elsif number % 10 == 1 && number % 100 != 11
|
32
32
|
1
|
33
|
-
elsif (2..4).cover?(
|
33
|
+
elsif (2..4).cover?(number % 10) && !(10..19).cover?(number % 100)
|
34
34
|
2
|
35
35
|
else
|
36
36
|
'n'
|
data/locales/sk.rb
CHANGED
@@ -20,14 +20,14 @@ module R18n
|
|
20
20
|
time_am: 'dop.',
|
21
21
|
time_pm: 'odp.',
|
22
22
|
date_format: '%d.%m.%Y',
|
23
|
-
full_format: '
|
23
|
+
full_format: '%-d. %B',
|
24
24
|
|
25
25
|
number_decimal: ',',
|
26
26
|
number_group: ' '
|
27
27
|
)
|
28
28
|
|
29
|
-
def pluralize(
|
30
|
-
case
|
29
|
+
def pluralize(number)
|
30
|
+
case number
|
31
31
|
when 0
|
32
32
|
0
|
33
33
|
when 1
|
data/locales/sr-latn.rb
CHANGED
@@ -16,17 +16,17 @@ module R18n
|
|
16
16
|
month_abbrs: %w[jan feb mar apr maj jun jul avg sep okt nov dec],
|
17
17
|
|
18
18
|
date_format: '%d.%m.%Y',
|
19
|
-
full_format: '
|
19
|
+
full_format: '%-d. %B',
|
20
20
|
|
21
21
|
number_decimal: ',',
|
22
22
|
number_group: '.'
|
23
23
|
|
24
|
-
def pluralize(
|
25
|
-
if
|
24
|
+
def pluralize(number)
|
25
|
+
if number.zero?
|
26
26
|
0
|
27
|
-
elsif
|
27
|
+
elsif number == 1
|
28
28
|
1
|
29
|
-
elsif
|
29
|
+
elsif number >= 2 && number <= 4
|
30
30
|
2
|
31
31
|
else
|
32
32
|
'n'
|
data/locales/sv-se.rb
CHANGED
data/locales/th.rb
CHANGED
@@ -17,14 +17,14 @@ module R18n
|
|
17
17
|
พ.ย. ธ.ค.],
|
18
18
|
|
19
19
|
date_format: '%d/%m/%Y',
|
20
|
-
full_format: '
|
20
|
+
full_format: '%-d %B',
|
21
21
|
year_format: '_, %Y',
|
22
22
|
|
23
23
|
number_decimal: '.',
|
24
24
|
number_group: ','
|
25
25
|
)
|
26
26
|
|
27
|
-
def pluralize(
|
27
|
+
def pluralize(_number)
|
28
28
|
'n'
|
29
29
|
end
|
30
30
|
|
data/locales/tr.rb
CHANGED
@@ -15,7 +15,7 @@ module R18n
|
|
15
15
|
month_abbrs: %w[Oca Şub Mar Nis May Haz Tem Ağu Eyl Eki Kas Ara],
|
16
16
|
|
17
17
|
date_format: '%d.%m.%Y',
|
18
|
-
full_format: '%B
|
18
|
+
full_format: '%B %-d.',
|
19
19
|
year_format: '%Y. _',
|
20
20
|
time_format: '_%H:%M',
|
21
21
|
|
@@ -23,7 +23,7 @@ module R18n
|
|
23
23
|
number_group: ','
|
24
24
|
)
|
25
25
|
|
26
|
-
def pluralize(
|
26
|
+
def pluralize(_number)
|
27
27
|
'n'
|
28
28
|
end
|
29
29
|
end
|
data/locales/vi.rb
CHANGED
@@ -17,7 +17,7 @@ module R18n
|
|
17
17
|
month_abbrs: %w[th1 th2 th3 th4 th5 th6 th7 th8 th9 th10 th11 th12],
|
18
18
|
|
19
19
|
date_format: '%d/%m/%Y',
|
20
|
-
full_format: 'ngày
|
20
|
+
full_format: 'ngày %-d %B',
|
21
21
|
year_format: '_ năm %Y',
|
22
22
|
time_format: '%H:%M, _',
|
23
23
|
|
@@ -25,7 +25,7 @@ module R18n
|
|
25
25
|
number_group: ','
|
26
26
|
)
|
27
27
|
|
28
|
-
def pluralize(
|
28
|
+
def pluralize(_number)
|
29
29
|
'n'
|
30
30
|
end
|
31
31
|
end
|
data/locales/zh.rb
CHANGED
data/spec/i18n_spec.rb
CHANGED
@@ -240,7 +240,7 @@ describe R18n::I18n do
|
|
240
240
|
expect(i18n.l(time, '%A')).to eq('Четверг')
|
241
241
|
expect(i18n.l(time, :month)).to eq('Январь')
|
242
242
|
expect(i18n.l(time, :standard)).to eq('01.01.1970 00:00')
|
243
|
-
expect(i18n.l(time, :full)).to eq('
|
243
|
+
expect(i18n.l(time, :full)).to eq('1 января 1970 00:00')
|
244
244
|
|
245
245
|
expect(i18n.l(Date.new(0))).to eq('01.01.0000')
|
246
246
|
end
|
data/spec/locale_spec.rb
CHANGED
@@ -60,7 +60,7 @@ describe R18n::Locale do
|
|
60
60
|
expect(unsupported).not_to be_supported
|
61
61
|
expect(unsupported).to be_kind_of(R18n::UnsupportedLocale)
|
62
62
|
|
63
|
-
expect(unsupported.code
|
63
|
+
expect(unsupported.code).to eq('nolocale-dl')
|
64
64
|
expect(unsupported.title.downcase).to eq('nolocale-dl')
|
65
65
|
expect(unsupported.ltr?).to be true
|
66
66
|
|
@@ -74,7 +74,7 @@ describe R18n::Locale do
|
|
74
74
|
|
75
75
|
it 'formats float in local traditions' do
|
76
76
|
expect(@en.localize(-12_345.67)).to eq('−12,345.67')
|
77
|
-
expect(@en.localize(BigDecimal
|
77
|
+
expect(@en.localize(BigDecimal('-12345.67'))).to eq('−12,345.67')
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'translates month, week days and am/pm names in strftime' do
|
@@ -110,28 +110,36 @@ describe R18n::Locale do
|
|
110
110
|
hour = 60 * minute
|
111
111
|
day = 24 * hour
|
112
112
|
zero = Time.at(0).utc
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
expect(@en.localize(
|
118
|
-
expect(@en.localize(
|
119
|
-
expect(@en.localize(
|
120
|
-
|
121
|
-
expect(@en.localize(
|
122
|
-
expect(@en.localize(
|
123
|
-
expect(@en.localize(
|
124
|
-
expect(@en.localize(
|
125
|
-
|
126
|
-
expect(@en.localize(
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
expect(@en.localize(zero
|
133
|
-
'
|
134
|
-
)
|
113
|
+
now = Time.now
|
114
|
+
now_params = [:human, R18n::I18n.new('en')]
|
115
|
+
zero_params = [*now_params, zero]
|
116
|
+
|
117
|
+
expect(@en.localize(now + 70 * minute, *now_params)).to eq('after 1 hour')
|
118
|
+
expect(@en.localize(now + hour + minute, *now_params)).to eq('after 1 hour')
|
119
|
+
expect(@en.localize(now + 38 * minute, *now_params))
|
120
|
+
.to eq('after 38 minutes')
|
121
|
+
expect(@en.localize(now + 5, *now_params)).to eq('now')
|
122
|
+
expect(@en.localize(now - 15, *now_params)).to eq('now')
|
123
|
+
expect(@en.localize(now - minute, *now_params)).to eq('1 minute ago')
|
124
|
+
expect(@en.localize(now - hour + 59, *now_params))
|
125
|
+
.to eq('59 minutes ago')
|
126
|
+
expect(@en.localize(now - 2 * hour, *now_params)).to eq('2 hours ago')
|
127
|
+
|
128
|
+
expect(@en.localize(zero + 7 * day, *zero_params))
|
129
|
+
.to eq('8th of January 00:00')
|
130
|
+
expect(@en.localize(zero + 50 * hour, *zero_params))
|
131
|
+
.to eq('after 2 days 02:00')
|
132
|
+
expect(@en.localize(zero + 25 * hour, *zero_params))
|
133
|
+
.to eq('tomorrow 01:00')
|
134
|
+
expect(@en.localize(zero - 13 * hour, *zero_params))
|
135
|
+
.to eq('yesterday 11:00')
|
136
|
+
expect(@en.localize(zero - 50 * hour, *zero_params))
|
137
|
+
.to eq('3 days ago 22:00')
|
138
|
+
|
139
|
+
expect(@en.localize(zero - 9 * day, *zero_params))
|
140
|
+
.to eq('23rd of December, 1969 00:00')
|
141
|
+
expect(@en.localize(zero - 365 * day, *zero_params))
|
142
|
+
.to eq('1st of January, 1969 00:00')
|
135
143
|
end
|
136
144
|
|
137
145
|
it 'localizes date-times for human' do
|
@@ -140,28 +148,38 @@ describe R18n::Locale do
|
|
140
148
|
minute = hour / 60
|
141
149
|
second = minute / 60
|
142
150
|
zero = DateTime.new(1970)
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
expect(@en.localize(
|
148
|
-
expect(@en.localize(
|
149
|
-
expect(@en.localize(
|
150
|
-
|
151
|
-
expect(@en.localize(
|
152
|
-
expect(@en.localize(
|
153
|
-
expect(@en.localize(
|
154
|
-
|
155
|
-
expect(@en.localize(
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
expect(@en.localize(zero
|
163
|
-
'
|
164
|
-
)
|
151
|
+
now = DateTime.now
|
152
|
+
now_params = [:human, R18n::I18n.new('en')]
|
153
|
+
zero_params = [*now_params, zero]
|
154
|
+
|
155
|
+
expect(@en.localize(now + 70 * minute, *now_params)).to eq('after 1 hour')
|
156
|
+
expect(@en.localize(now + hour + minute, *now_params)).to eq('after 1 hour')
|
157
|
+
expect(@en.localize(now + 38 * minute, *now_params))
|
158
|
+
.to eq('after 38 minutes')
|
159
|
+
expect(@en.localize(now + 5 * second, *now_params)).to eq('now')
|
160
|
+
expect(@en.localize(now - 15 * second, *now_params)).to eq('now')
|
161
|
+
expect(@en.localize(now - minute, *now_params)).to eq('1 minute ago')
|
162
|
+
|
163
|
+
expect(@en.localize(now - hour + 59 * second, *now_params))
|
164
|
+
.to eq('59 minutes ago')
|
165
|
+
|
166
|
+
expect(@en.localize(now - 2 * hour, *now_params)).to eq('2 hours ago')
|
167
|
+
|
168
|
+
expect(@en.localize(zero + 7 * day, *zero_params))
|
169
|
+
.to eq('8th of January 00:00')
|
170
|
+
expect(@en.localize(zero + 50 * hour, *zero_params))
|
171
|
+
.to eq('after 2 days 02:00')
|
172
|
+
expect(@en.localize(zero + 25 * hour, *zero_params))
|
173
|
+
.to eq('tomorrow 01:00')
|
174
|
+
expect(@en.localize(zero - 13 * hour, *zero_params))
|
175
|
+
.to eq('yesterday 11:00')
|
176
|
+
expect(@en.localize(zero - 50 * hour, *zero_params))
|
177
|
+
.to eq('3 days ago 22:00')
|
178
|
+
|
179
|
+
expect(@en.localize(zero - 9 * day, *zero_params))
|
180
|
+
.to eq('23rd of December, 1969 00:00')
|
181
|
+
expect(@en.localize(zero - 365 * day, *zero_params))
|
182
|
+
.to eq('1st of January, 1969 00:00')
|
165
183
|
end
|
166
184
|
|
167
185
|
it 'uses standard formatter by default' do
|
@@ -185,6 +203,24 @@ describe R18n::Locale do
|
|
185
203
|
expect(@en.localize(Date.today - 1, :my_own_way)).to eq('Just another day')
|
186
204
|
end
|
187
205
|
|
206
|
+
it 'localizes custom classes if formatter exists' do
|
207
|
+
stub_const(
|
208
|
+
'FooBar', Class.new do
|
209
|
+
attr_reader :value
|
210
|
+
|
211
|
+
def initialize(value)
|
212
|
+
@value = value
|
213
|
+
end
|
214
|
+
end
|
215
|
+
)
|
216
|
+
|
217
|
+
foo_bar = FooBar.new 'something'
|
218
|
+
|
219
|
+
allow(@en).to receive(:format_foo_bar_human, &:value)
|
220
|
+
|
221
|
+
expect(@en.localize(foo_bar, :human)).to eq('something')
|
222
|
+
end
|
223
|
+
|
188
224
|
it 'raises error on unknown formatter' do
|
189
225
|
expect do
|
190
226
|
@ru.localize(Time.at(0).utc, R18n::I18n.new('ru'), :unknown)
|
@@ -211,6 +247,6 @@ describe R18n::Locale do
|
|
211
247
|
end
|
212
248
|
|
213
249
|
it 'loads locale with underscore' do
|
214
|
-
expect(R18n.locale('
|
250
|
+
expect(R18n.locale('nolocale_DL').code).to eq('nolocale-dl')
|
215
251
|
end
|
216
252
|
end
|
data/spec/locales/fr_spec.rb
CHANGED
@@ -4,6 +4,6 @@ describe R18n::Locales::Fr do
|
|
4
4
|
it 'formats French date' do
|
5
5
|
fr = R18n::I18n.new('fr')
|
6
6
|
expect(fr.l(Date.parse('2009-07-01'), :full)).to eq('1er juillet 2009')
|
7
|
-
expect(fr.l(Date.parse('2009-07-02'), :full)).to eq('
|
7
|
+
expect(fr.l(Date.parse('2009-07-02'), :full)).to eq('2 juillet 2009')
|
8
8
|
end
|
9
9
|
end
|
data/spec/locales/hu_spec.rb
CHANGED
@@ -12,6 +12,6 @@ describe R18n::Locales::Hu do
|
|
12
12
|
it 'uses Hungarian time format' do
|
13
13
|
hu = R18n::I18n.new('hu')
|
14
14
|
expect(hu.l(Time.at(0).utc)).to eq('1970. 01. 01., 00:00')
|
15
|
-
expect(hu.l(Time.at(0).utc, :full)).to eq('1970. január
|
15
|
+
expect(hu.l(Time.at(0).utc, :full)).to eq('1970. január 1., 00:00')
|
16
16
|
end
|
17
17
|
end
|
data/spec/locales/it_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe R18n::Locales::It do
|
|
4
4
|
it 'formats Italian date' do
|
5
5
|
italian = R18n::I18n.new('it')
|
6
6
|
expect(italian.l(Date.parse('2009-07-01'), :full)).to eq('1º luglio 2009')
|
7
|
-
expect(italian.l(Date.parse('2009-07-02'), :full)).to eq('
|
7
|
+
expect(italian.l(Date.parse('2009-07-02'), :full)).to eq('2 luglio 2009')
|
8
8
|
expect(italian.l(Date.parse('2009-07-12'), :full)).to eq('12 luglio 2009')
|
9
9
|
end
|
10
10
|
end
|
data/spec/r18n_spec.rb
CHANGED
@@ -169,4 +169,10 @@ describe R18n do
|
|
169
169
|
i18n = R18n::I18n.new('en', nil)
|
170
170
|
expect(i18n.one).not_to be_translated
|
171
171
|
end
|
172
|
+
|
173
|
+
it 'allows to load files with `.yaml` extension' do
|
174
|
+
R18n.default_places = File.join(TRANSLATIONS, 'yaml')
|
175
|
+
R18n.set('en')
|
176
|
+
expect(t.one).to eq('One')
|
177
|
+
end
|
172
178
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/translated_spec.rb
CHANGED
@@ -114,7 +114,13 @@ describe R18n::Translated do
|
|
114
114
|
translation :no_method, methods: { en: :no_method_en }
|
115
115
|
|
116
116
|
def method_missing(name, *_params)
|
117
|
-
name.to_s
|
117
|
+
return name.to_s if name.to_s =~ /^no_method*/
|
118
|
+
super
|
119
|
+
end
|
120
|
+
|
121
|
+
def respond_to_missing?(name, *_params)
|
122
|
+
return true if name.to_s =~ /^no_method*/
|
123
|
+
super
|
118
124
|
end
|
119
125
|
end
|
120
126
|
virtual = @virtual_class.new
|
data/spec/translation_spec.rb
CHANGED
@@ -168,4 +168,19 @@ describe R18n::Translation do
|
|
168
168
|
it { is_expected.to be_translated }
|
169
169
|
it { is_expected.to eq 'Not found' }
|
170
170
|
end
|
171
|
+
|
172
|
+
it 'handles #to_ary' do
|
173
|
+
i18n = R18n::I18n.new('en', DIR)
|
174
|
+
expect([i18n.one, i18n.two].flatten).to eq [i18n.one, i18n.two]
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'handles #to_hash' do
|
178
|
+
i18n = R18n::I18n.new('en', DIR)
|
179
|
+
|
180
|
+
def foo(*args, **opts)
|
181
|
+
[args, opts]
|
182
|
+
end
|
183
|
+
|
184
|
+
expect(foo(i18n.one)).to eq [[i18n.one], {}]
|
185
|
+
end
|
171
186
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
one: One
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Sitnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
R18n is a i18n tool to translate your Ruby application.
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- base/bg.yml
|
33
33
|
- base/ca.yml
|
34
34
|
- base/cs.yml
|
35
|
+
- base/cy.yml
|
35
36
|
- base/da.yml
|
36
37
|
- base/de.yml
|
37
38
|
- base/en.yml
|
@@ -83,6 +84,7 @@ files:
|
|
83
84
|
- locales/bg.rb
|
84
85
|
- locales/ca.rb
|
85
86
|
- locales/cs.rb
|
87
|
+
- locales/cy.rb
|
86
88
|
- locales/da.rb
|
87
89
|
- locales/de.rb
|
88
90
|
- locales/en-au.rb
|
@@ -151,6 +153,7 @@ files:
|
|
151
153
|
- spec/translations/general/ru.yml
|
152
154
|
- spec/translations/two/en.yml
|
153
155
|
- spec/translations/two/fr.yml
|
156
|
+
- spec/translations/yaml/en.yaml
|
154
157
|
- spec/yaml_loader_spec.rb
|
155
158
|
homepage: https://github.com/ai/r18n
|
156
159
|
licenses:
|
@@ -205,4 +208,5 @@ test_files:
|
|
205
208
|
- spec/translations/general/ru.yml
|
206
209
|
- spec/translations/two/en.yml
|
207
210
|
- spec/translations/two/fr.yml
|
211
|
+
- spec/translations/yaml/en.yaml
|
208
212
|
- spec/yaml_loader_spec.rb
|