r18n-core 2.2.0 → 3.0.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.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/.rspec +1 -1
  3. data/ChangeLog.md +6 -1
  4. data/README.md +1 -20
  5. data/Rakefile +5 -3
  6. data/lib/r18n-core.rb +55 -55
  7. data/lib/r18n-core/filter_list.rb +34 -36
  8. data/lib/r18n-core/filters.rb +68 -51
  9. data/lib/r18n-core/helpers.rb +17 -17
  10. data/lib/r18n-core/i18n.rb +46 -39
  11. data/lib/r18n-core/locale.rb +79 -70
  12. data/lib/r18n-core/translated.rb +65 -66
  13. data/lib/r18n-core/translated_string.rb +24 -24
  14. data/lib/r18n-core/translation.rb +31 -30
  15. data/lib/r18n-core/unsupported_locale.rb +22 -24
  16. data/lib/r18n-core/untranslated.rb +35 -33
  17. data/lib/r18n-core/utils.rb +26 -25
  18. data/lib/r18n-core/version.rb +4 -1
  19. data/lib/r18n-core/yaml_loader.rb +26 -25
  20. data/lib/r18n-core/yaml_methods.rb +25 -28
  21. data/locales/af.rb +15 -8
  22. data/locales/az.rb +19 -12
  23. data/locales/bg.rb +16 -9
  24. data/locales/ca.rb +16 -9
  25. data/locales/cs.rb +27 -20
  26. data/locales/da.rb +15 -8
  27. data/locales/de.rb +16 -9
  28. data/locales/en-au.rb +10 -5
  29. data/locales/en-gb.rb +12 -5
  30. data/locales/en-us.rb +12 -5
  31. data/locales/en.rb +29 -22
  32. data/locales/eo.rb +14 -7
  33. data/locales/es-us.rb +12 -5
  34. data/locales/es.rb +14 -7
  35. data/locales/fa.rb +48 -32
  36. data/locales/fi.rb +19 -12
  37. data/locales/fr.rb +22 -15
  38. data/locales/gl.rb +15 -8
  39. data/locales/hr.rb +24 -17
  40. data/locales/hu.rb +28 -21
  41. data/locales/id.rb +14 -7
  42. data/locales/it.rb +21 -14
  43. data/locales/ja.rb +15 -8
  44. data/locales/kk.rb +17 -10
  45. data/locales/ko.rb +15 -9
  46. data/locales/lv.rb +24 -17
  47. data/locales/mn.rb +10 -3
  48. data/locales/nb.rb +15 -8
  49. data/locales/nl.rb +15 -8
  50. data/locales/no.rb +11 -16
  51. data/locales/pl.rb +26 -19
  52. data/locales/pt-br.rb +12 -5
  53. data/locales/pt.rb +17 -10
  54. data/locales/ru.rb +26 -19
  55. data/locales/sk.rb +27 -20
  56. data/locales/sr-latn.rb +27 -22
  57. data/locales/sv-se.rb +15 -8
  58. data/locales/th.rb +27 -20
  59. data/locales/tr.rb +16 -9
  60. data/locales/uk.rb +19 -12
  61. data/locales/vi.rb +14 -7
  62. data/locales/zh-cn.rb +12 -5
  63. data/locales/zh-tw.rb +15 -8
  64. data/locales/zh.rb +14 -7
  65. data/r18n-core.gemspec +5 -3
  66. data/spec/filters_spec.rb +71 -67
  67. data/spec/i18n_spec.rb +73 -51
  68. data/spec/locale_spec.rb +73 -68
  69. data/spec/locales/cs_spec.rb +2 -2
  70. data/spec/locales/en-us_spec.rb +9 -9
  71. data/spec/locales/en_spec.rb +2 -2
  72. data/spec/locales/fa_spec.rb +3 -3
  73. data/spec/locales/fr_spec.rb +2 -2
  74. data/spec/locales/hu_spec.rb +7 -7
  75. data/spec/locales/it_spec.rb +3 -3
  76. data/spec/locales/no_spec.rb +9 -0
  77. data/spec/locales/pl_spec.rb +2 -2
  78. data/spec/locales/ru_spec.rb +2 -2
  79. data/spec/locales/sk_spec.rb +2 -2
  80. data/spec/locales/th_spec.rb +2 -2
  81. data/spec/locales/vi_spec.rb +2 -2
  82. data/spec/r18n_spec.rb +44 -38
  83. data/spec/spec_helper.rb +13 -9
  84. data/spec/translated_spec.rb +48 -31
  85. data/spec/translation_spec.rb +29 -27
  86. data/spec/translations/general/en.yml +0 -2
  87. data/spec/yaml_loader_spec.rb +22 -18
  88. metadata +5 -3
@@ -1,30 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module R18n
2
- class Locales::Th < Locale
3
- set title: 'ภาษาไทย',
4
+ module Locales
5
+ # Thai locale
6
+ class Th < Locale
7
+ set(
8
+ title: 'ภาษาไทย',
4
9
 
5
- wday_names: %w{วันอาทิตย์ วันจันทร์ วันอังคาร วันพุธ วันพฤหัสบดี
6
- วันศุกร์ วันเสาร์},
7
- wday_abbrs: %w{อาทิตย์ จันทร์ อังคาร พุธ พฤหัสบดี ศุกร์ เสาร์},
10
+ wday_names: %w[วันอาทิตย์ วันจันทร์ วันอังคาร วันพุธ วันพฤหัสบดี
11
+ วันศุกร์ วันเสาร์],
12
+ wday_abbrs: %w[อาทิตย์ จันทร์ อังคาร พุธ พฤหัสบดี ศุกร์ เสาร์],
8
13
 
9
- month_names: %w{มกราคม กุมภาพันธ์ มีนาคม เมษายน พฤษภาคม มิถุนายน
10
- กรกฎาคม สิงหาคม กันยายน ตุลาคม พฤศจิกายน ธันวาคม},
11
- month_abbrs: %w{ม.ค. ก.พ. มี.ค. เม.ย. พ.ค. มิ.ย. ก.ค. ส.ค. ก.ย. ต.ค.
12
- พ.ย. ธ.ค.},
14
+ month_names: %w[มกราคม กุมภาพันธ์ มีนาคม เมษายน พฤษภาคม มิถุนายน
15
+ กรกฎาคม สิงหาคม กันยายน ตุลาคม พฤศจิกายน ธันวาคม],
16
+ month_abbrs: %w[ม.ค. ก.พ. มี.ค. เม.ย. พ.ค. มิ.ย. ก.ค. ส.ค. ก.ย. ต.ค.
17
+ พ.ย. ธ.ค.],
13
18
 
14
- date_format: '%d/%m/%Y',
15
- full_format: '%e %B',
16
- year_format: '_, %Y',
19
+ date_format: '%d/%m/%Y',
20
+ full_format: '%e %B',
21
+ year_format: '_, %Y',
17
22
 
18
- number_decimal: '.',
19
- number_group: ','
23
+ number_decimal: '.',
24
+ number_group: ','
25
+ )
20
26
 
21
- def pluralize(n)
22
- 'n'
23
- end
27
+ def pluralize(_n)
28
+ 'n'
29
+ end
24
30
 
25
- def strftime(time, format)
26
- year = (time.year + 543).to_s
27
- super(time, format.gsub('%Y', year).gsub('%y', year[-2..-1]))
31
+ def strftime(time, format)
32
+ year = (time.year + 543).to_s
33
+ super(time, format.gsub('%Y', year).gsub('%y', year[-2..-1]))
34
+ end
28
35
  end
29
36
  end
30
37
  end
@@ -1,13 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module R18n
2
- class Locales::Tr < Locale
3
- set title: 'Türkçe',
4
+ module Locales
5
+ # Turkish locale
6
+ class Tr < Locale
7
+ set(
8
+ title: 'Türkçe',
4
9
 
5
- wday_names: %w{Pazar Pazartesi Salı Çarşamba Perşembe Cuma Cumartesi},
6
- wday_abbrs: %w{Paz Pzt Sal Çar Per Cum Cmt},
10
+ wday_names: %w[Pazar Pazartesi Salı Çarşamba Perşembe Cuma Cumartesi],
11
+ wday_abbrs: %w[Paz Pzt Sal Çar Per Cum Cmt],
7
12
 
8
- month_names: %w{Ocak Şubat Mart Nisan Mayıs Haziran Temmuz Ağustos Eylül
9
- Ekim Kasım Aralık},
10
- month_abbrs: %w{Oca Şub Mar Nis May Haz Tem Ağu Eyl Eki Kas Ara},
13
+ month_names: %w[Ocak Şubat Mart Nisan Mayıs Haziran Temmuz Ağustos Eylül
14
+ Ekim Kasım Aralık],
15
+ month_abbrs: %w[Oca Şub Mar Nis May Haz Tem Ağu Eyl Eki Kas Ara],
11
16
 
12
17
  date_format: '%d.%m.%Y',
13
18
  full_format: '%B %e.',
@@ -16,9 +21,11 @@ module R18n
16
21
 
17
22
  number_decimal: '.',
18
23
  number_group: ','
24
+ )
19
25
 
20
- def pluralize(n)
21
- 'n'
26
+ def pluralize(_n)
27
+ 'n'
28
+ end
22
29
  end
23
30
  end
24
31
  end
@@ -1,20 +1,27 @@
1
- require File.join(File.dirname(__FILE__), 'ru')
1
+ # frozen_string_literal: true
2
2
 
3
- module R18n::Locales
4
- class Uk < Ru
5
- set title: 'Українська',
6
- sublocales: %w{ru en},
3
+ require_relative 'ru'
7
4
 
8
- wday_names: %w{Неділя Понеділок Вівторок Середа Четвер П'ятниця Субота},
9
- wday_abbrs: %w{Ндл Пнд Втр Срд Чтв Птн Сбт},
5
+ module R18n
6
+ module Locales
7
+ # Ukrainian locale
8
+ class Uk < Ru
9
+ set(
10
+ title: 'Українська',
11
+ sublocales: %w[ru en],
10
12
 
11
- month_names: %w{січня лютого березня квітня травня червня липня
12
- серпня вересня жовтня листопада грудня},
13
- month_abbrs: %w{січ лют бер кві тра чер лип сер вер жов лис гру},
14
- month_standalone: %w{Січень Лютий Березень Квітень Травень Червень
15
- Липень Серпень Вересень Жовтень Листопад Грудень},
13
+ wday_names: %w[Неділя Понеділок Вівторок Середа Четвер П'ятниця Субота],
14
+ wday_abbrs: %w[Ндл Пнд Втр Срд Чтв Птн Сбт],
15
+
16
+ month_names: %w[січня лютого березня квітня травня червня липня
17
+ серпня вересня жовтня листопада грудня],
18
+ month_abbrs: %w[січ лют бер кві тра чер лип сер вер жов лис гру],
19
+ month_standalone: %w[Січень Лютий Березень Квітень Травень Червень
20
+ Липень Серпень Вересень Жовтень Листопад Грудень],
16
21
 
17
22
  time_am: ' ранку',
18
23
  time_pm: ' вечора'
24
+ )
25
+ end
19
26
  end
20
27
  end
@@ -1,15 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module R18n
2
- class Locales::Vi < Locale
3
- set title: 'Tiếng Việt',
4
+ module Locales
5
+ # Vietnamese locale
6
+ class Vi < Locale
7
+ set(
8
+ title: 'Tiếng Việt',
4
9
 
5
10
  wday_names: ['Chủ nhật', 'Thứ Hai', 'Thứ Ba', 'Thứ Tư', 'Thứ Năm',
6
11
  'Thứ Sáu', 'Thứ Bảy'],
7
- wday_abbrs: %w{CN T2 T3 T4 T5 T6 T7},
12
+ wday_abbrs: %w[CN T2 T3 T4 T5 T6 T7],
8
13
 
9
14
  month_names: ['tháng 1', 'tháng 2', 'tháng 3', 'tháng 4', 'tháng 5',
10
- 'tháng 6', 'tháng 7', 'tháng 8',' tháng 9', 'tháng 10',
15
+ 'tháng 6', 'tháng 7', 'tháng 8', 'tháng 9', 'tháng 10',
11
16
  'tháng 11', 'tháng 12'],
12
- month_abbrs: %w{th1 th2 th3 th4 th5 th6 th7 th8 th9 th10 th11 th12},
17
+ month_abbrs: %w[th1 th2 th3 th4 th5 th6 th7 th8 th9 th10 th11 th12],
13
18
 
14
19
  date_format: '%d/%m/%Y',
15
20
  full_format: 'ngày %e %B',
@@ -18,9 +23,11 @@ module R18n
18
23
 
19
24
  number_decimal: '.',
20
25
  number_group: ','
26
+ )
21
27
 
22
- def pluralize(n)
23
- 'n'
28
+ def pluralize(_n)
29
+ 'n'
30
+ end
24
31
  end
25
32
  end
26
33
  end
@@ -1,8 +1,15 @@
1
- require File.join(File.dirname(__FILE__), 'zh')
1
+ # frozen_string_literal: true
2
2
 
3
- module R18n::Locales
4
- class ZhCn < Zh
5
- set title: '简体中文',
6
- sublocales: %w{zh en}
3
+ require_relative 'zh'
4
+
5
+ module R18n
6
+ module Locales
7
+ # Chinese (S) locale
8
+ class ZhCn < Zh
9
+ set(
10
+ title: '简体中文',
11
+ sublocales: %w[zh en]
12
+ )
13
+ end
7
14
  end
8
15
  end
@@ -1,12 +1,19 @@
1
- require File.join(File.dirname(__FILE__), 'zh')
1
+ # frozen_string_literal: true
2
2
 
3
- module R18n::Locales
4
- class ZhTw < Zh
5
- set title: '繁體中文',
6
- sublocales: %w{zh en},
3
+ require_relative 'zh'
7
4
 
8
- wday_names: %w{星期日 星期壹 星期二 星期三 星期四 星期五 星期六},
9
- wday_abbrs: %w{周日 周壹 周二 周三 周四 周五 周六},
10
- month_names: %w{壹月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十壹月 十二月}
5
+ module R18n
6
+ module Locales
7
+ # Chinese (T) locale
8
+ class ZhTw < Zh
9
+ set(
10
+ title: '繁體中文',
11
+ sublocales: %w[zh en],
12
+
13
+ wday_names: %w[星期日 星期壹 星期二 星期三 星期四 星期五 星期六],
14
+ wday_abbrs: %w[周日 周壹 周二 周三 周四 周五 周六],
15
+ month_names: %w[壹月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十壹月 十二月]
16
+ )
17
+ end
11
18
  end
12
19
  end
@@ -1,12 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module R18n
2
- class Locales::Zh < Locale
3
- set title: '中文',
4
+ module Locales
5
+ # Chinese locale
6
+ class Zh < Locale
7
+ set(
8
+ title: '中文',
4
9
 
5
- wday_names: %w{星期日 星期一 星期二 星期三 星期四 星期五 星期六},
6
- wday_abbrs: %w{周日 周一 周二 周三 周四 周五 周六},
10
+ wday_names: %w[星期日 星期一 星期二 星期三 星期四 星期五 星期六],
11
+ wday_abbrs: %w[周日 周一 周二 周三 周四 周五 周六],
7
12
 
8
- month_names: %w{一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月
9
- 十二月},
13
+ month_names: %w[一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月
14
+ 十二月],
10
15
 
11
16
  date_format: '%Y年%m月%d日',
12
17
  full_format: '%m月%d日',
@@ -14,9 +19,11 @@ module R18n
14
19
 
15
20
  number_decimal: '.',
16
21
  number_group: ' '
22
+ )
17
23
 
18
- def pluralize(n)
24
+ def pluralize(_n)
19
25
  'n'
20
26
  end
27
+ end
21
28
  end
22
29
  end
@@ -1,4 +1,6 @@
1
- require File.expand_path('../lib/r18n-core/version', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/r18n-core/version'
2
4
 
3
5
  Gem::Specification.new do |s|
4
6
  s.platform = Gem::Platform::RUBY
@@ -7,13 +9,13 @@ Gem::Specification.new do |s|
7
9
  s.date = Time.now.strftime('%Y-%m-%d')
8
10
 
9
11
  s.summary = 'I18n tool to translate your Ruby application.'
10
- s.description = <<-EOF
12
+ s.description = <<-DESC
11
13
  R18n is a i18n tool to translate your Ruby application.
12
14
  It has nice Ruby-style syntax, filters, flexible locales, custom loaders,
13
15
  translation support for any classes, time and number localization, several
14
16
  user language support, agnostic core package with out-of-box support for
15
17
  Rails, Sinatra and desktop applications.
16
- EOF
18
+ DESC
17
19
 
18
20
  s.files = `git ls-files`.split("\n")
19
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,15 +1,15 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Filters do
4
4
  before do
5
5
  @system = R18n::Filters.defined.values
6
- @enabled = R18n::Filters.defined.values.reject { |i| !i.enabled? }
6
+ @enabled = R18n::Filters.defined.values.select(&:enabled?)
7
7
  @i18n = R18n::I18n.new('en', DIR)
8
8
  @i18n.reload!
9
9
  end
10
10
 
11
11
  after do
12
- R18n::Filters.defined.values.each do |filter|
12
+ R18n::Filters.defined.each_value do |filter|
13
13
  next if @system.include? filter
14
14
  R18n::Filters.delete(filter)
15
15
  end
@@ -18,8 +18,8 @@ describe R18n::Filters do
18
18
  (@system - @enabled).each { |i| R18n::Filters.off(i) if i.enabled? }
19
19
  end
20
20
 
21
- it "adds new filter" do
22
- filter = R18n::Filters.add('my', :my_filter) { |i, config| i }
21
+ it 'adds new filter' do
22
+ filter = R18n::Filters.add('my', :my_filter) { |i, _config| i }
23
23
 
24
24
  expect(filter).to be_kind_of(R18n::Filters::Filter)
25
25
  expect(filter.name).to eq(:my_filter)
@@ -30,18 +30,18 @@ describe R18n::Filters do
30
30
 
31
31
  @i18n.reload!
32
32
  expect(@i18n.my_filter).to eq('value')
33
- expect(@i18n.my_tree_filter).to eq({'name' => 'value'})
33
+ expect(@i18n.my_tree_filter).to eq('name' => 'value')
34
34
  end
35
35
 
36
- it "adds filter for several types" do
37
- filter = R18n::Filters.add(['my', 'your']) { |i, config| i + '1' }
36
+ it 'adds filter for several types' do
37
+ R18n::Filters.add(%w[my your]) { |i, _config| i + '1' }
38
38
  @i18n.reload!
39
39
  expect(@i18n.my_filter).to eq('value1')
40
40
  expect(@i18n.your_filter).to eq('another1')
41
41
  end
42
42
 
43
- it "uses passive filters" do
44
- filter = double()
43
+ it 'uses passive filters' do
44
+ filter = double
45
45
  expect(filter).to receive(:process).twice.and_return(1)
46
46
 
47
47
  R18n::Filters.add('my', :passive, passive: true) { filter.process }
@@ -54,14 +54,14 @@ describe R18n::Filters do
54
54
  expect(@i18n.my_filter).to eq(1)
55
55
  end
56
56
 
57
- it "uses cascade filters" do
58
- filter = R18n::Filters.add('my', :one) { |i, config| i + '1' }
59
- filter = R18n::Filters.add('my', :two) { |i, config| i + '2' }
60
- filter = R18n::Filters.add('my', :three, position: 0) { |i, c| i + '3' }
57
+ it 'uses cascade filters' do
58
+ R18n::Filters.add('my', :one) { |i, _config| i + '1' }
59
+ R18n::Filters.add('my', :two) { |i, _config| i + '2' }
60
+ R18n::Filters.add('my', :three, position: 0) { |i, _c| i + '3' }
61
61
  expect(@i18n.my_filter).to eq('value312')
62
62
  end
63
63
 
64
- it "returns name for nameless filter" do
64
+ it 'returns name for nameless filter' do
65
65
  R18n::Filters.instance_variable_set(:@last_auto_name, 0)
66
66
 
67
67
  expect(R18n::Filters.add('some').name).to eq(1)
@@ -71,7 +71,7 @@ describe R18n::Filters do
71
71
  expect(R18n::Filters.add('some').name).to eq(4)
72
72
  end
73
73
 
74
- it "deletes filter by name" do
74
+ it 'deletes filter by name' do
75
75
  R18n::Filters.add('my', :my_filter) { '1' }
76
76
  expect(@i18n.my_filter).to eq('1')
77
77
 
@@ -80,7 +80,7 @@ describe R18n::Filters do
80
80
  expect(@i18n.my_filter).to eq('value')
81
81
  end
82
82
 
83
- it "deletes filter by object" do
83
+ it 'deletes filter by object' do
84
84
  filter = R18n::Filters.add('my') { '1' }
85
85
  expect(@i18n.my_filter).to eq('1')
86
86
 
@@ -89,16 +89,16 @@ describe R18n::Filters do
89
89
  expect(@i18n.my_filter).to eq('value')
90
90
  end
91
91
 
92
- it "uses global filters" do
93
- R18n::Filters.add(String) { |result, config, a, b| result + a + b }
94
- R18n::Filters.add(String) { |result, config| result + '!' }
92
+ it 'uses global filters' do
93
+ R18n::Filters.add(String) { |result, _config, a, b| result + a + b }
94
+ R18n::Filters.add(String) { |result, _config| result + '!' }
95
95
 
96
96
  expect(@i18n.one('1', '2')).to eq('One12!')
97
97
  end
98
98
 
99
- it "turns off filter" do
100
- filter = R18n::Filters.add('my', :one) { |i, config| i + '1' }
101
- filter = R18n::Filters.add('my', :two) { |i, config| i + '2' }
99
+ it 'turns off filter' do
100
+ R18n::Filters.add('my', :one) { |i, _config| i + '1' }
101
+ R18n::Filters.add('my', :two) { |i, _config| i + '2' }
102
102
 
103
103
  R18n::Filters.off(:one)
104
104
  expect(R18n::Filters.defined[:one]).not_to be_enabled
@@ -109,8 +109,8 @@ describe R18n::Filters do
109
109
  expect(@i18n.my_filter).to eq('value12')
110
110
  end
111
111
 
112
- it "sends config to filter" do
113
- R18n::Filters.add('my') do |i, config|
112
+ it 'sends config to filter' do
113
+ R18n::Filters.add('my') do |_i, config|
114
114
  config[:secret_value] = 1
115
115
  config
116
116
  end
@@ -120,24 +120,24 @@ describe R18n::Filters do
120
120
  expect(@i18n.my_filter[:unknown_value]).to be_nil
121
121
  end
122
122
 
123
- it "sets path in config" do
124
- R18n::Filters.add(String) do |i, config|
123
+ it 'sets path in config' do
124
+ R18n::Filters.add(String) do |_i, config|
125
125
  config[:path]
126
126
  end
127
127
 
128
128
  expect(@i18n.in.another.level).to eq('in.another.level')
129
129
  end
130
130
 
131
- it "returns translated string after filters" do
132
- R18n::Filters.add(String) { |i, config| i + '1' }
131
+ it 'returns translated string after filters' do
132
+ R18n::Filters.add(String) { |i, _config| i + '1' }
133
133
 
134
134
  expect(@i18n.one).to be_kind_of(R18n::TranslatedString)
135
135
  expect(@i18n.one.path).to eq('one')
136
136
  expect(@i18n.one.locale).to eq(R18n.locale('en'))
137
137
  end
138
138
 
139
- it "uses one config for cascade filters" do
140
- R18n::Filters.add('my') { |content, config| config[:new_secret] ? 2 : 1 }
139
+ it 'uses one config for cascade filters' do
140
+ R18n::Filters.add('my') { |_content, config| config[:new_secret] ? 2 : 1 }
141
141
  expect(@i18n.my_filter).to eq(1)
142
142
 
143
143
  R18n::Filters.add('my', :second, position: 0) do |content, config|
@@ -147,17 +147,13 @@ describe R18n::Filters do
147
147
  expect(@i18n.my_filter).to eq(2)
148
148
  end
149
149
 
150
- it "sends parameters to filter" do
151
- R18n::Filters.add('my') { |i, config, a, b| "#{i}#{a}#{b}" }
150
+ it 'sends parameters to filter' do
151
+ R18n::Filters.add('my') { |i, _config, a, b| "#{i}#{a}#{b}" }
152
152
  expect(@i18n['my_filter', 1, 2]).to eq('value12')
153
153
  expect(@i18n.my_filter(1, 2)).to eq('value12')
154
154
  end
155
155
 
156
- it "calls proc from translation" do
157
- expect(@i18n.sum(2, 3)).to eq(5)
158
- end
159
-
160
- it "pluralizes translation" do
156
+ it 'pluralizes translation' do
161
157
  expect(@i18n.comments(0, 'article')).to eq('no comments for article')
162
158
  expect(@i18n.comments(1, 'article')).to eq('one comment for article')
163
159
  expect(@i18n.comments(5, 'article')).to eq('5 comments for article')
@@ -174,17 +170,17 @@ describe R18n::Filters do
174
170
  expect(@i18n.files.n(5)).to eq('5 files')
175
171
  end
176
172
 
177
- it "converts first float parameter to number" do
173
+ it 'converts first float parameter to number' do
178
174
  expect(@i18n.files(1.2)).to eq('1 file')
179
175
  end
180
176
 
181
- it "pluralizes translation without locale" do
177
+ it 'pluralizes translation without locale' do
182
178
  i18n = R18n::I18n.new('nolocale', DIR)
183
179
  expect(i18n.entries(1)).to eq('ONE')
184
180
  expect(i18n.entries(5)).to eq('N')
185
181
  end
186
182
 
187
- it "cans use params in translation" do
183
+ it 'cans use params in translation' do
188
184
  expect(@i18n.params(-1, 2)).to eq('Is −1 between −1 and 2?')
189
185
  end
190
186
 
@@ -194,63 +190,69 @@ describe R18n::Filters do
194
190
  )
195
191
  end
196
192
 
197
- it "formats untranslated" do
193
+ it 'formats untranslated' do
198
194
  expect(@i18n.in.not.to_s).to eq('in.[not]')
199
195
  expect(@i18n.in.not.to_str).to eq('in.[not]')
200
196
 
201
197
  R18n::Filters.off(:untranslated)
202
198
  expect(@i18n.in.not.to_s).to eq('in.not')
203
199
 
204
- R18n::Filters.add(R18n::Untranslated) do |v, c, trans, untrans, path|
200
+ R18n::Filters.add(R18n::Untranslated) do |_v, _c, trans, untrans, path|
205
201
  "#{path} #{trans}[#{untrans}]"
206
202
  end
207
203
  expect(@i18n.in.not.to_s).to eq('in.not in.[not]')
208
204
  end
209
205
 
210
- it "formats translation path" do
206
+ it 'formats translation path' do
211
207
  expect(@i18n.in.another.to_s).to eq('in.another[]')
212
208
 
213
209
  R18n::Filters.off(:untranslated)
214
210
  expect(@i18n.in.another.to_s).to eq('in.another')
215
211
 
216
- R18n::Filters.add(R18n::Untranslated) do |v, c, trans, untrans, path|
212
+ R18n::Filters.add(R18n::Untranslated) do |_v, _c, trans, untrans, path|
217
213
  "#{path} #{trans}[#{untrans}]"
218
214
  end
219
215
  expect(@i18n.in.another.to_s).to eq('in.another in.another[]')
220
216
  end
221
217
 
222
- it "formats untranslated for web" do
218
+ it 'formats untranslated for web' do
223
219
  R18n::Filters.off(:untranslated)
224
220
  R18n::Filters.on(:untranslated_html)
225
221
  expect(@i18n.in.not.to_s).to eq('in.<span style="color: red">[not]</span>')
226
- expect(@i18n['<b>'].to_s).to eq('<span style="color: red">[&lt;b&gt;]</span>')
222
+ expect(@i18n['<b>'].to_s).to eq(
223
+ '<span style="color: red">[&lt;b&gt;]</span>'
224
+ )
227
225
  end
228
226
 
229
- it "allows to set custom filters" do
230
- R18n::Filters.add(R18n::Untranslated, :a) { |v, c| "a #{v}" }
227
+ it 'allows to set custom filters' do
228
+ R18n::Filters.add(R18n::Untranslated, :a) { |v, _c| "a #{v}" }
231
229
  R18n::Filters.off(:a)
232
230
 
233
- html = R18n::I18n.new('en', DIR, off_filters: :untranslated,
234
- on_filters: [:untranslated_html, :a])
231
+ html = R18n::I18n.new(
232
+ 'en', DIR,
233
+ off_filters: :untranslated, on_filters: %i[untranslated_html a]
234
+ )
235
235
  expect(html.in.not.to_s).to eq('a in.<span style="color: red">[not]</span>')
236
236
  end
237
237
 
238
- it "has filter for escape HTML" do
238
+ it 'has filter for escape HTML' do
239
239
  expect(@i18n.html).to eq(
240
- '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;')
240
+ '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;'
241
+ )
241
242
  end
242
243
 
243
- it "has disabled global filter for escape HTML" do
244
+ it 'has disabled global filter for escape HTML' do
244
245
  expect(@i18n.greater('true')).to eq('1 < 2 is true')
245
246
 
246
247
  R18n::Filters.on(:global_escape_html)
247
248
  @i18n.reload!
248
249
  expect(@i18n.greater('true')).to eq('1 &lt; 2 is true')
249
250
  expect(@i18n.html).to eq(
250
- '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;')
251
+ '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;'
252
+ )
251
253
  end
252
254
 
253
- it "has filter to disable global HTML escape" do
255
+ it 'has filter to disable global HTML escape' do
254
256
  expect(@i18n.no_escape).to eq('<b>Warning</b>')
255
257
 
256
258
  R18n::Filters.on(:global_escape_html)
@@ -258,39 +260,41 @@ describe R18n::Filters do
258
260
  expect(@i18n.no_escape).to eq('<b>Warning</b>')
259
261
  end
260
262
 
261
- it "has Markdown filter" do
263
+ it 'has Markdown filter' do
262
264
  expect(@i18n.markdown.simple).to eq("<p><strong>Hi!</strong></p>\n")
263
265
  end
264
266
 
265
- it "has Textile filter" do
267
+ it 'has Textile filter' do
266
268
  expect(@i18n.textile.simple).to eq('<p><em>Hi!</em></p>')
267
269
  end
268
270
 
269
- it "HTML escapes before Markdown and Textile filters" do
271
+ it 'HTML escapes before Markdown and Textile filters' do
270
272
  expect(@i18n.markdown.html).to eq("<p><strong>Hi!</strong> <br /></p>\n")
271
273
  expect(@i18n.textile.html).to eq('<p><em>Hi!</em><br /></p>')
272
274
 
273
275
  R18n::Filters.on(:global_escape_html)
274
276
  @i18n.reload!
275
277
  expect(@i18n.markdown.html).to eq(
276
- "<p><strong>Hi!</strong> &lt;br /&gt;</p>\n")
278
+ "<p><strong>Hi!</strong> &lt;br /&gt;</p>\n"
279
+ )
277
280
  expect(@i18n.textile.html).to eq(
278
- '<p><em>Hi!</em>&lt;br /&gt;</p>')
281
+ '<p><em>Hi!</em>&lt;br /&gt;</p>'
282
+ )
279
283
  end
280
284
 
281
- it "allows to listen filters adding" do
282
- expect(R18n::Filters.listen {
283
- R18n::Filters.add(String, :a) { }
284
- }).to eq([R18n::Filters.defined[:a]])
285
+ it 'allows to listen filters adding' do
286
+ expect(R18n::Filters.listen do
287
+ R18n::Filters.add(String, :a) {}
288
+ end).to eq([R18n::Filters.defined[:a]])
285
289
  end
286
290
 
287
- it "escapes variables if ActiveSupport is loaded" do
291
+ it 'escapes variables if ActiveSupport is loaded' do
288
292
  expect(@i18n.escape_params('<br>')).to eq('<b><br></b>')
289
293
  require 'active_support'
290
294
  expect(@i18n.escape_params('<br>')).to eq('<b>&lt;br&gt;</b>')
291
295
  end
292
296
 
293
- it "uses SafeBuffer if it is loaded" do
297
+ it 'uses SafeBuffer if it is loaded' do
294
298
  require 'active_support'
295
299
 
296
300
  R18n::Filters.on(:global_escape_html)