r18n-core 3.1.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/base/cy.yml +34 -0
  4. data/lib/r18n-core/i18n.rb +2 -5
  5. data/lib/r18n-core/locale.rb +18 -10
  6. data/lib/r18n-core/translated_string.rb +15 -1
  7. data/lib/r18n-core/translation.rb +1 -1
  8. data/lib/r18n-core/unsupported_locale.rb +6 -1
  9. data/lib/r18n-core/untranslated.rb +13 -3
  10. data/lib/r18n-core/utils.rb +17 -8
  11. data/lib/r18n-core/version.rb +1 -1
  12. data/lib/r18n-core/yaml_loader.rb +7 -3
  13. data/locales/af.rb +1 -1
  14. data/locales/az.rb +1 -1
  15. data/locales/cs.rb +4 -4
  16. data/locales/cy.rb +50 -0
  17. data/locales/de.rb +1 -1
  18. data/locales/en-us.rb +1 -1
  19. data/locales/en.rb +10 -10
  20. data/locales/eo.rb +1 -1
  21. data/locales/fa.rb +1 -1
  22. data/locales/fi.rb +1 -1
  23. data/locales/fr.rb +2 -2
  24. data/locales/hr.rb +5 -5
  25. data/locales/hu.rb +2 -2
  26. data/locales/it.rb +2 -2
  27. data/locales/ja.rb +1 -1
  28. data/locales/kk.rb +1 -1
  29. data/locales/lv.rb +4 -4
  30. data/locales/nb.rb +1 -1
  31. data/locales/nl.rb +1 -1
  32. data/locales/pl.rb +5 -5
  33. data/locales/ru.rb +4 -4
  34. data/locales/sk.rb +3 -3
  35. data/locales/sr-latn.rb +5 -5
  36. data/locales/sv-se.rb +1 -1
  37. data/locales/th.rb +2 -2
  38. data/locales/tr.rb +2 -2
  39. data/locales/vi.rb +2 -2
  40. data/locales/zh.rb +1 -1
  41. data/spec/i18n_spec.rb +1 -1
  42. data/spec/locale_spec.rb +83 -47
  43. data/spec/locales/fr_spec.rb +1 -1
  44. data/spec/locales/hu_spec.rb +1 -1
  45. data/spec/locales/it_spec.rb +1 -1
  46. data/spec/r18n_spec.rb +6 -0
  47. data/spec/spec_helper.rb +4 -0
  48. data/spec/translated_spec.rb +7 -1
  49. data/spec/translation_spec.rb +15 -0
  50. data/spec/translations/yaml/en.yaml +1 -0
  51. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 489041ceb7db5e8cf6b743a024fb28208a2b8aa8bb259b33fc1b5c83af27adcc
4
- data.tar.gz: 2a8bba59036684b3c5ea7e3c5794adc87d10fe67e9970ed6f43fe519a5c9eef7
3
+ metadata.gz: ea9e0df5d7d9a6465ecbb70590f24b69578fe9bcf703a825f7f861dae17ab8d5
4
+ data.tar.gz: ce67040d879d2edd3e14bb17d5b3cebff9a4824a25ace0d4caf15d5c4292a6e2
5
5
  SHA512:
6
- metadata.gz: 6e307a9fac93250e9616ddac0b375ae23817dcc09179beb851bdc6e81c41bd5b14f55b1dc0705ff0bcc0d513197c967adf79f0727d72ee225504d6fedac0cdf3
7
- data.tar.gz: 0bb8acf70cb671e5e43b31795c9e930e508223d0f3504d383c92e2dd33c3356f71461fe536e2586adc725acf5c7c8f7680ef94ee5181eb8ed72787bd577dc239
6
+ metadata.gz: ed567f238f886118551f5243c409fea38722c3508733943731489840bb69507613edb9f5d46031bfbe230d1f339d1c7f757d3cdc5adb102d92559df07b3c18d4
7
+ data.tar.gz: 825933ccff178daf0648cf78f1f8b9378149cb151bfcddf2835165c66c7dec0bb785368910b6ec0435ccfb39331d953de6d9029b8e5f916ee7420e53fa0b6cab
data/README.md CHANGED
@@ -71,7 +71,7 @@ In your translation files you can use:
71
71
  robots: !!pl
72
72
  0: No robots
73
73
  1: One robot
74
- n: %1 robots
74
+ n: '%1 robots'
75
75
  ```
76
76
 
77
77
  * Filters
@@ -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'
@@ -199,7 +199,7 @@ module R18n
199
199
 
200
200
  # Reload translations.
201
201
  def reload!
202
- @available = @available_codes = nil
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
- @available ||= R18n.available_locales(@translation_places)
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.
@@ -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
- original = code.to_s.gsub(/[^-_a-zA-Z]/, '')
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(original)
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: '%e %B',
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
- obj.to_s
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 = Time.now, *_params)
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 +n+ items. This is simple form. For special
303
- # cases you can replace it in locale’s class.
304
- def pluralize(n)
305
- case n
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 respond_to? :html_safe
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
@@ -51,7 +51,7 @@ module R18n
51
51
  # comments: !!pl
52
52
  # 0: no comments
53
53
  # 1: one comment
54
- # n: %1 comments
54
+ # n: '%1 comments'
55
55
  #
56
56
  # example.rb
57
57
  #
@@ -56,7 +56,12 @@ module R18n
56
56
 
57
57
  # Proxy to default locale object.
58
58
  def method_missing(name, *params)
59
- @base.send(name, *params)
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 == :to_ary
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)
@@ -43,17 +43,26 @@ module R18n
43
43
  end
44
44
 
45
45
  # Recursively hash merge.
46
- def self.deep_merge!(a, b)
47
- b.each_pair do |key, value|
48
- another = a[key]
49
- a[key] =
50
- if another.is_a?(Hash) && value.is_a?(Hash)
51
- deep_merge!(another, value)
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
- value
53
+ another_value
54
54
  end
55
55
  end
56
- a
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Version of R18n Core
4
4
  module R18n
5
- VERSION = '3.1.2'.freeze unless defined? R18n::VERSION
5
+ VERSION = '3.2.0'.freeze unless defined? R18n::VERSION
6
6
  end
@@ -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, '**/*.yml'))
47
- .map { |i| File.basename(i, '.yml') }.uniq
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(File.join(@dir, "**/#{locale.code.downcase}.yml")).each do |i|
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)
@@ -20,7 +20,7 @@ module R18n
20
20
  time_pm: "'s namiddag",
21
21
 
22
22
  date_format: '%d/%m/%Y',
23
- full_format: '%e %B',
23
+ full_format: '%-d %B',
24
24
  year_format: '_, %Y',
25
25
  time_format: '_, %H:%M',
26
26
 
@@ -26,7 +26,7 @@ module R18n
26
26
  number_group: ' '
27
27
  )
28
28
 
29
- def pluralize(_n)
29
+ def pluralize(_number)
30
30
  'n'
31
31
  end
32
32
  end
@@ -19,15 +19,15 @@ module R18n
19
19
 
20
20
  time_am: 'dop.',
21
21
  time_pm: 'odp.',
22
- date_format: '%e. %m. %Y',
23
- full_format: '%e. %B',
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(n)
30
- case n
29
+ def pluralize(number)
30
+ case number
31
31
  when 0
32
32
  0
33
33
  when 1
@@ -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
@@ -19,7 +19,7 @@ module R18n
19
19
  time_am: 'vormittags',
20
20
  time_pm: 'nachmittags',
21
21
  date_format: '%d.%m.%Y',
22
- full_format: '%e. %B',
22
+ full_format: '%-d. %B',
23
23
 
24
24
  number_decimal: ',',
25
25
  number_group: '.'
@@ -12,7 +12,7 @@ module R18n
12
12
 
13
13
  time_format: '_ %I:%M %p',
14
14
  date_format: '%m/%d/%Y',
15
- full_format: '%B %e'
15
+ full_format: '%B %-d'
16
16
  )
17
17
  end
18
18
  end
@@ -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: '%e of %B',
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(n)
29
- if (11..13).cover?(n % 100)
30
- "#{n}th"
28
+ def ordinalize(number)
29
+ if (11..13).cover?(number % 100)
30
+ "#{number}th"
31
31
  else
32
- case n % 10
33
- when 1 then "#{n}st"
34
- when 2 then "#{n}nd"
35
- when 3 then "#{n}rd"
36
- else "#{n}th"
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('%e', ordinalize(date.mday)))
44
+ strftime(date, format.sub('%-d', ordinalize(date.mday)))
45
45
  end
46
46
  end
47
47
  end
@@ -15,7 +15,7 @@ module R18n
15
15
  month_abbrs: %w[jan feb mar apr maj jun jul aŭg sep okt nov dec],
16
16
 
17
17
  date_format: '%Y-%m-%d',
18
- full_format: 'la %e-a de %B',
18
+ full_format: 'la %-d-a de %B',
19
19
  year_format: '_ de %Y',
20
20
 
21
21
  number_decimal: '.',
@@ -20,7 +20,7 @@ module R18n
20
20
  ],
21
21
 
22
22
  date_format: '%Y/%m/%d',
23
- full_format: '%e %B',
23
+ full_format: '%-d %B',
24
24
  year_format: '_ %Y',
25
25
 
26
26
  number_decimal: '٫',
@@ -20,7 +20,7 @@ module R18n
20
20
  marraskuu joulukuu],
21
21
 
22
22
  date_format: '%d.%m.%Y',
23
- full_format: '%e. %B',
23
+ full_format: '%-d. %B',
24
24
  time_format: '_ %H.%M',
25
25
 
26
26
  number_decimal: ',',
@@ -24,8 +24,8 @@ module R18n
24
24
 
25
25
  def format_date_full(date, year = true, *_params)
26
26
  full = super(date, year)
27
- if full[0..1] == ' 1'
28
- '1er' + full[2..-1]
27
+ if full[0..1] == '1 '
28
+ '1er' + full[1..-1]
29
29
  else
30
30
  full
31
31
  end
@@ -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: '%e. %B',
20
+ full_format: '%-d. %B',
21
21
 
22
22
  number_decimal: ',',
23
23
  number_group: '.'
24
24
  )
25
25
 
26
- def pluralize(n)
27
- if n.zero?
26
+ def pluralize(number)
27
+ if number.zero?
28
28
  0
29
- elsif n == 1
29
+ elsif number == 1
30
30
  1
31
- elsif n >= 2 && n <= 4
31
+ elsif number >= 2 && number <= 4
32
32
  2
33
33
  else
34
34
  'n'
@@ -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 %e.',
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(_n)
27
+ def pluralize(_number)
28
28
  'n'
29
29
  end
30
30
 
@@ -23,8 +23,8 @@ module R18n
23
23
 
24
24
  def format_date_full(date, year = true, *_params)
25
25
  full = super(date, year)
26
- if full[0..1] == ' 1'
27
- '1º' + full[2..-1]
26
+ if full[0..1] == '1 '
27
+ '1º' + full[1..-1]
28
28
  else
29
29
  full
30
30
  end
@@ -22,7 +22,7 @@ module R18n
22
22
  number_group: ','
23
23
  )
24
24
 
25
- def pluralize(_n)
25
+ def pluralize(_number)
26
26
  'n'
27
27
  end
28
28
  end
@@ -20,7 +20,7 @@ module R18n
20
20
  time_am: ' ертеңің',
21
21
  time_pm: ' кештің',
22
22
  date_format: '%Y-%m-%d',
23
- full_format: '%B %e-і',
23
+ full_format: '%B %-d-і',
24
24
  year_format: '%Y жылы _',
25
25
 
26
26
  number_decimal: ',',
@@ -20,17 +20,17 @@ module R18n
20
20
  decembris],
21
21
 
22
22
  date_format: '%d.%m.%Y.',
23
- full_format: '%e.%B',
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(n)
31
- if n.zero?
30
+ def pluralize(number)
31
+ if number.zero?
32
32
  0
33
- elsif n % 10 == 1 && n % 100 != 11
33
+ elsif number % 10 == 1 && number % 100 != 11
34
34
  1
35
35
  else
36
36
  'n'
@@ -17,7 +17,7 @@ module R18n
17
17
  month_abbrs: %w[jan feb mar apr mai jun jul aug sep okt nov des],
18
18
 
19
19
  date_format: '%d.%m.%Y',
20
- full_format: '%e. %B %Y',
20
+ full_format: '%-d. %B %Y',
21
21
 
22
22
  number_decimal: ',',
23
23
  number_group: ' '
@@ -18,7 +18,7 @@ module R18n
18
18
  time_am: "'s ochtends",
19
19
  time_pm: "'s middags",
20
20
  date_format: '%d-%m-%Y',
21
- full_format: '%e %B',
21
+ full_format: '%-d %B',
22
22
 
23
23
  number_decimal: ',',
24
24
  number_group: '.'
@@ -24,13 +24,13 @@ module R18n
24
24
  number_group: ' '
25
25
  )
26
26
 
27
- def pluralize(n)
28
- return 0 if n.zero?
29
- case n % 10
27
+ def pluralize(number)
28
+ return 0 if number.zero?
29
+ case number % 10
30
30
  when 1
31
- n > 10 ? 'n' : 1
31
+ number > 10 ? 'n' : 1
32
32
  when 2..4
33
- (11..19).cover?(n % 100) ? 'n' : 2
33
+ (11..19).cover?(number % 100) ? 'n' : 2
34
34
  else
35
35
  'n'
36
36
  end
@@ -25,12 +25,12 @@ module R18n
25
25
  number_group: ' '
26
26
  )
27
27
 
28
- def pluralize(n)
29
- if n.zero?
28
+ def pluralize(number)
29
+ if number.zero?
30
30
  0
31
- elsif n % 10 == 1 && n % 100 != 11
31
+ elsif number % 10 == 1 && number % 100 != 11
32
32
  1
33
- elsif (2..4).cover?(n % 10) && !(10..19).cover?(n % 100)
33
+ elsif (2..4).cover?(number % 10) && !(10..19).cover?(number % 100)
34
34
  2
35
35
  else
36
36
  'n'
@@ -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: '%e. %B',
23
+ full_format: '%-d. %B',
24
24
 
25
25
  number_decimal: ',',
26
26
  number_group: ' '
27
27
  )
28
28
 
29
- def pluralize(n)
30
- case n
29
+ def pluralize(number)
30
+ case number
31
31
  when 0
32
32
  0
33
33
  when 1
@@ -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: '%e. %B',
19
+ full_format: '%-d. %B',
20
20
 
21
21
  number_decimal: ',',
22
22
  number_group: '.'
23
23
 
24
- def pluralize(n)
25
- if n.zero?
24
+ def pluralize(number)
25
+ if number.zero?
26
26
  0
27
- elsif n == 1
27
+ elsif number == 1
28
28
  1
29
- elsif n >= 2 && n <= 4
29
+ elsif number >= 2 && number <= 4
30
30
  2
31
31
  else
32
32
  'n'
@@ -16,7 +16,7 @@ module R18n
16
16
  month_abbrs: %w[jan feb mar apr maj jun jul aug okt nov dec],
17
17
 
18
18
  date_format: '%Y-%m-%d',
19
- full_format: '%e %B %Y',
19
+ full_format: '%-d %B %Y',
20
20
 
21
21
  number_decimal: ',',
22
22
  number_group: '.'
@@ -17,14 +17,14 @@ module R18n
17
17
  พ.ย. ธ.ค.],
18
18
 
19
19
  date_format: '%d/%m/%Y',
20
- full_format: '%e %B',
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(_n)
27
+ def pluralize(_number)
28
28
  'n'
29
29
  end
30
30
 
@@ -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 %e.',
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(_n)
26
+ def pluralize(_number)
27
27
  'n'
28
28
  end
29
29
  end
@@ -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 %e %B',
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(_n)
28
+ def pluralize(_number)
29
29
  'n'
30
30
  end
31
31
  end
@@ -21,7 +21,7 @@ module R18n
21
21
  number_group: ' '
22
22
  )
23
23
 
24
- def pluralize(_n)
24
+ def pluralize(_number)
25
25
  'n'
26
26
  end
27
27
  end
@@ -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(' 1 января 1970 00:00')
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
@@ -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.downcase).to eq('nolocale-dl')
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.new('-12345.67'))).to eq('−12,345.67')
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
- p = [:human, R18n::I18n.new('en'), zero]
114
-
115
- expect(@en.localize(zero + 7 * day, *p)).to eq('8th of January 00:00')
116
- expect(@en.localize(zero + 50 * hour, *p)).to eq('after 2 days 02:00')
117
- expect(@en.localize(zero + 25 * hour, *p)).to eq('tomorrow 01:00')
118
- expect(@en.localize(zero + 70 * minute, *p)).to eq('after 1 hour')
119
- expect(@en.localize(zero + hour, *p)).to eq('after 1 hour')
120
- expect(@en.localize(zero + 38 * minute, *p)).to eq('after 38 minutes')
121
- expect(@en.localize(zero + 5, *p)).to eq('now')
122
- expect(@en.localize(zero - 15, *p)).to eq('now')
123
- expect(@en.localize(zero - minute, *p)).to eq('1 minute ago')
124
- expect(@en.localize(zero - hour + 59, *p)).to eq('59 minutes ago')
125
- expect(@en.localize(zero - 2 * hour, *p)).to eq('2 hours ago')
126
- expect(@en.localize(zero - 13 * hour, *p)).to eq('yesterday 11:00')
127
- expect(@en.localize(zero - 50 * hour, *p)).to eq('3 days ago 22:00')
128
-
129
- expect(@en.localize(zero - 9 * day, *p)).to eq(
130
- '23rd of December, 1969 00:00'
131
- )
132
- expect(@en.localize(zero - 365 * day, *p)).to eq(
133
- '1st of January, 1969 00:00'
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
- p = [:human, R18n::I18n.new('en'), zero]
144
-
145
- expect(@en.localize(zero + 7 * day, *p)).to eq('8th of January 00:00')
146
- expect(@en.localize(zero + 50 * hour, *p)).to eq('after 2 days 02:00')
147
- expect(@en.localize(zero + 25 * hour, *p)).to eq('tomorrow 01:00')
148
- expect(@en.localize(zero + 70 * minute, *p)).to eq('after 1 hour')
149
- expect(@en.localize(zero + hour, *p)).to eq('after 1 hour')
150
- expect(@en.localize(zero + 38 * minute, *p)).to eq('after 38 minutes')
151
- expect(@en.localize(zero + 5 * second, *p)).to eq('now')
152
- expect(@en.localize(zero - 15 * second, *p)).to eq('now')
153
- expect(@en.localize(zero - minute, *p)).to eq('1 minute ago')
154
- expect(@en.localize(zero - hour + 59 * second, *p)).to eq('59 minutes ago')
155
- expect(@en.localize(zero - 2 * hour, *p)).to eq('2 hours ago')
156
- expect(@en.localize(zero - 13 * hour, *p)).to eq('yesterday 11:00')
157
- expect(@en.localize(zero - 50 * hour, *p)).to eq('3 days ago 22:00')
158
-
159
- expect(@en.localize(zero - 9 * day, *p)).to eq(
160
- '23rd of December, 1969 00:00'
161
- )
162
- expect(@en.localize(zero - 365 * day, *p)).to eq(
163
- '1st of January, 1969 00:00'
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('nolocale-DL').code).to eq('nolocale-dl')
250
+ expect(R18n.locale('nolocale_DL').code).to eq('nolocale-dl')
215
251
  end
216
252
  end
@@ -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(' 2 juillet 2009')
7
+ expect(fr.l(Date.parse('2009-07-02'), :full)).to eq('2 juillet 2009')
8
8
  end
9
9
  end
@@ -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 1., 00:00')
15
+ expect(hu.l(Time.at(0).utc, :full)).to eq('1970. január 1., 00:00')
16
16
  end
17
17
  end
@@ -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(' 2 luglio 2009')
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
@@ -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
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ## https://github.com/stevekinney/pizza/issues/103#issuecomment-136052789
4
+ ## https://github.com/docker-library/ruby/issues/45
5
+ Encoding.default_external = 'UTF-8'
6
+
3
7
  require 'pp'
4
8
 
5
9
  require_relative '../lib/r18n-core'
@@ -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
@@ -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.1.2
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-09-03 00:00:00.000000000 Z
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