r18n-core 3.1.1 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +398 -0
  3. data/README.md +63 -47
  4. data/base/cy.yml +34 -0
  5. data/lib/r18n-core.rb +37 -38
  6. data/lib/r18n-core/filter_list.rb +21 -13
  7. data/lib/r18n-core/filters.rb +43 -48
  8. data/lib/r18n-core/helpers.rb +2 -2
  9. data/lib/r18n-core/i18n.rb +70 -78
  10. data/lib/r18n-core/locale.rb +137 -107
  11. data/lib/r18n-core/locales/af.rb +36 -0
  12. data/lib/r18n-core/locales/az.rb +38 -0
  13. data/lib/r18n-core/locales/bg.rb +29 -0
  14. data/{locales → lib/r18n-core/locales}/ca.rb +9 -6
  15. data/{locales → lib/r18n-core/locales}/cs.rb +15 -11
  16. data/lib/r18n-core/locales/cy.rb +50 -0
  17. data/{locales → lib/r18n-core/locales}/da.rb +10 -7
  18. data/lib/r18n-core/locales/de.rb +33 -0
  19. data/{locales → lib/r18n-core/locales}/en-au.rb +2 -2
  20. data/{locales → lib/r18n-core/locales}/en-gb.rb +2 -2
  21. data/{locales → lib/r18n-core/locales}/en-us.rb +4 -3
  22. data/lib/r18n-core/locales/en.rb +51 -0
  23. data/{locales → lib/r18n-core/locales}/eo.rb +6 -4
  24. data/lib/r18n-core/locales/es-cl.rb +16 -0
  25. data/{locales → lib/r18n-core/locales}/es-us.rb +5 -4
  26. data/{locales → lib/r18n-core/locales}/es.rb +7 -3
  27. data/{locales → lib/r18n-core/locales}/fa.rb +2 -2
  28. data/lib/r18n-core/locales/fi.rb +39 -0
  29. data/lib/r18n-core/locales/fr.rb +39 -0
  30. data/{locales → lib/r18n-core/locales}/gl.rb +5 -3
  31. data/{locales → lib/r18n-core/locales}/hr.rb +13 -10
  32. data/{locales → lib/r18n-core/locales}/hu.rb +10 -7
  33. data/{locales → lib/r18n-core/locales}/id.rb +8 -4
  34. data/lib/r18n-core/locales/it.rb +37 -0
  35. data/{locales → lib/r18n-core/locales}/ja.rb +5 -4
  36. data/{locales → lib/r18n-core/locales}/kk.rb +12 -8
  37. data/{locales → lib/r18n-core/locales}/ko.rb +0 -0
  38. data/lib/r18n-core/locales/lv.rb +46 -0
  39. data/lib/r18n-core/locales/mn.rb +30 -0
  40. data/{locales → lib/r18n-core/locales}/nb.rb +6 -4
  41. data/lib/r18n-core/locales/nl.rb +31 -0
  42. data/{locales → lib/r18n-core/locales}/no.rb +0 -0
  43. data/lib/r18n-core/locales/pl.rb +45 -0
  44. data/{locales → lib/r18n-core/locales}/pt-br.rb +1 -1
  45. data/lib/r18n-core/locales/pt.rb +37 -0
  46. data/lib/r18n-core/locales/ru.rb +46 -0
  47. data/{locales → lib/r18n-core/locales}/sk.rb +13 -9
  48. data/{locales → lib/r18n-core/locales}/sr-latn.rb +10 -8
  49. data/{locales → lib/r18n-core/locales}/sv-se.rb +7 -5
  50. data/lib/r18n-core/locales/th.rb +41 -0
  51. data/{locales → lib/r18n-core/locales}/tr.rb +7 -6
  52. data/lib/r18n-core/locales/uk.rb +31 -0
  53. data/lib/r18n-core/locales/vi.rb +37 -0
  54. data/{locales → lib/r18n-core/locales}/zh-cn.rb +2 -2
  55. data/{locales → lib/r18n-core/locales}/zh-tw.rb +4 -4
  56. data/{locales → lib/r18n-core/locales}/zh.rb +7 -4
  57. data/lib/r18n-core/translated.rb +38 -37
  58. data/lib/r18n-core/translated_string.rb +19 -8
  59. data/lib/r18n-core/translation.rb +24 -19
  60. data/lib/r18n-core/unsupported_locale.rb +14 -6
  61. data/lib/r18n-core/untranslated.rb +23 -7
  62. data/lib/r18n-core/utils.rb +19 -23
  63. data/lib/r18n-core/version.rb +1 -1
  64. data/lib/r18n-core/yaml_loader.rb +17 -13
  65. data/lib/r18n-core/yaml_methods.rb +3 -1
  66. metadata +245 -118
  67. data/.rspec +0 -1
  68. data/Rakefile +0 -13
  69. data/locales/af.rb +0 -32
  70. data/locales/az.rb +0 -34
  71. data/locales/bg.rb +0 -25
  72. data/locales/de.rb +0 -29
  73. data/locales/en.rb +0 -48
  74. data/locales/fi.rb +0 -35
  75. data/locales/fr.rb +0 -35
  76. data/locales/it.rb +0 -34
  77. data/locales/lv.rb +0 -41
  78. data/locales/mn.rb +0 -27
  79. data/locales/nl.rb +0 -28
  80. data/locales/pl.rb +0 -40
  81. data/locales/pt.rb +0 -29
  82. data/locales/ru.rb +0 -41
  83. data/locales/th.rb +0 -37
  84. data/locales/uk.rb +0 -27
  85. data/locales/vi.rb +0 -33
  86. data/r18n-core.gemspec +0 -29
  87. data/spec/filters_spec.rb +0 -324
  88. data/spec/i18n_spec.rb +0 -260
  89. data/spec/locale_spec.rb +0 -216
  90. data/spec/locales/cs_spec.rb +0 -23
  91. data/spec/locales/en-us_spec.rb +0 -13
  92. data/spec/locales/en_spec.rb +0 -13
  93. data/spec/locales/fa_spec.rb +0 -10
  94. data/spec/locales/fr_spec.rb +0 -9
  95. data/spec/locales/hu_spec.rb +0 -17
  96. data/spec/locales/it_spec.rb +0 -10
  97. data/spec/locales/no_spec.rb +0 -9
  98. data/spec/locales/pl_spec.rb +0 -23
  99. data/spec/locales/ru_spec.rb +0 -23
  100. data/spec/locales/sk_spec.rb +0 -23
  101. data/spec/locales/th_spec.rb +0 -9
  102. data/spec/locales/vi_spec.rb +0 -8
  103. data/spec/r18n_spec.rb +0 -172
  104. data/spec/spec_helper.rb +0 -41
  105. data/spec/translated_spec.rb +0 -163
  106. data/spec/translation_spec.rb +0 -164
  107. data/spec/translations/extension/deep/en.yml +0 -1
  108. data/spec/translations/extension/en.yml +0 -2
  109. data/spec/translations/extension/notransl.yml +0 -1
  110. data/spec/translations/general/en.yml +0 -47
  111. data/spec/translations/general/nolocale.yml +0 -6
  112. data/spec/translations/general/ru.yml +0 -7
  113. data/spec/translations/two/en.yml +0 -2
  114. data/spec/translations/two/fr.yml +0 -0
  115. data/spec/yaml_loader_spec.rb +0 -61
data/locales/pt.rb DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module R18n
4
- module Locales
5
- # Portuguese locale
6
- class Pt < Locale
7
- set(
8
- title: 'Português',
9
-
10
- wday_names: %w[domingo segunda-feira terça-feira quarta-feira
11
- quinta-feira sexta-feira sábado],
12
- wday_abbrs: %w[dom seg ter qua qui sex sab],
13
-
14
- month_names: %w[janeiro fevereiro março abril maio junho julho
15
- agosto setembro outubro novembro dezembro],
16
- month_abbrs: %w[jan fev mar abr mai jun jul ago set out nov dez],
17
- month_standalone: %w[Janeiro Fevereiro Março Abril Maio Junho Julho
18
- Agosto Setembro Outubro Novembro Dezembro],
19
-
20
- date_format: '%d/%m/%Y',
21
- full_format: '%d de %B',
22
- year_format: '_ de %Y',
23
-
24
- number_decimal: ',',
25
- number_group: '.'
26
- )
27
- end
28
- end
29
- end
data/locales/ru.rb DELETED
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module R18n
4
- module Locales
5
- # Russian locale
6
- class Ru < Locale
7
- set(
8
- title: 'Русский',
9
-
10
- wday_names: %w[Воскресенье Понедельник Вторник Среда Четверг Пятница
11
- Суббота],
12
- wday_abbrs: %w[Вск Пнд Втр Срд Чтв Птн Сбт],
13
-
14
- month_names: %w[января февраля марта апреля мая июня июля августа
15
- сентября октября ноября декабря],
16
- month_abbrs: %w[янв фев мар апр май июн июл авг сен окт ноя дек],
17
- month_standalone: %w[Январь Февраль Март Апрель Май Июнь Июль Август
18
- Сентябрь Октябрь Ноябрь Декабрь],
19
-
20
- time_am: ' утра',
21
- time_pm: ' вечера',
22
- date_format: '%d.%m.%Y',
23
-
24
- number_decimal: ',',
25
- number_group: ' '
26
- )
27
-
28
- def pluralize(n)
29
- if n.zero?
30
- 0
31
- elsif n % 10 == 1 && n % 100 != 11
32
- 1
33
- elsif (2..4).cover?(n % 10) && !(10..19).cover?(n % 100)
34
- 2
35
- else
36
- 'n'
37
- end
38
- end
39
- end
40
- end
41
- end
data/locales/th.rb DELETED
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module R18n
4
- module Locales
5
- # Thai locale
6
- class Th < Locale
7
- set(
8
- title: 'ภาษาไทย',
9
-
10
- wday_names: %w[วันอาทิตย์ วันจันทร์ วันอังคาร วันพุธ วันพฤหัสบดี
11
- วันศุกร์ วันเสาร์],
12
- wday_abbrs: %w[อาทิตย์ จันทร์ อังคาร พุธ พฤหัสบดี ศุกร์ เสาร์],
13
-
14
- month_names: %w[มกราคม กุมภาพันธ์ มีนาคม เมษายน พฤษภาคม มิถุนายน
15
- กรกฎาคม สิงหาคม กันยายน ตุลาคม พฤศจิกายน ธันวาคม],
16
- month_abbrs: %w[ม.ค. ก.พ. มี.ค. เม.ย. พ.ค. มิ.ย. ก.ค. ส.ค. ก.ย. ต.ค.
17
- พ.ย. ธ.ค.],
18
-
19
- date_format: '%d/%m/%Y',
20
- full_format: '%e %B',
21
- year_format: '_, %Y',
22
-
23
- number_decimal: '.',
24
- number_group: ','
25
- )
26
-
27
- def pluralize(_n)
28
- 'n'
29
- end
30
-
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
35
- end
36
- end
37
- end
data/locales/uk.rb DELETED
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'ru'
4
-
5
- module R18n
6
- module Locales
7
- # Ukrainian locale
8
- class Uk < Ru
9
- set(
10
- title: 'Українська',
11
- sublocales: %w[ru en],
12
-
13
- wday_names: %w[Неділя Понеділок Вівторок Середа Четвер П'ятниця Субота],
14
- wday_abbrs: %w[Ндл Пнд Втр Срд Чтв Птн Сбт],
15
-
16
- month_names: %w[січня лютого березня квітня травня червня липня
17
- серпня вересня жовтня листопада грудня],
18
- month_abbrs: %w[січ лют бер кві тра чер лип сер вер жов лис гру],
19
- month_standalone: %w[Січень Лютий Березень Квітень Травень Червень
20
- Липень Серпень Вересень Жовтень Листопад Грудень],
21
-
22
- time_am: ' ранку',
23
- time_pm: ' вечора'
24
- )
25
- end
26
- end
27
- end
data/locales/vi.rb DELETED
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module R18n
4
- module Locales
5
- # Vietnamese locale
6
- class Vi < Locale
7
- set(
8
- title: 'Tiếng Việt',
9
-
10
- wday_names: ['Chủ nhật', 'Thứ Hai', 'Thứ Ba', 'Thứ Tư', 'Thứ Năm',
11
- 'Thứ Sáu', 'Thứ Bảy'],
12
- wday_abbrs: %w[CN T2 T3 T4 T5 T6 T7],
13
-
14
- month_names: ['tháng 1', 'tháng 2', 'tháng 3', 'tháng 4', 'tháng 5',
15
- 'tháng 6', 'tháng 7', 'tháng 8', 'tháng 9', 'tháng 10',
16
- 'tháng 11', 'tháng 12'],
17
- month_abbrs: %w[th1 th2 th3 th4 th5 th6 th7 th8 th9 th10 th11 th12],
18
-
19
- date_format: '%d/%m/%Y',
20
- full_format: 'ngày %e %B',
21
- year_format: '_ năm %Y',
22
- time_format: '%H:%M, _',
23
-
24
- number_decimal: '.',
25
- number_group: ','
26
- )
27
-
28
- def pluralize(_n)
29
- 'n'
30
- end
31
- end
32
- end
33
- end
data/r18n-core.gemspec DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/r18n-core/version'
4
-
5
- Gem::Specification.new do |s|
6
- s.platform = Gem::Platform::RUBY
7
- s.name = 'r18n-core'
8
- s.version = R18n::VERSION.dup
9
- s.date = Time.now.strftime('%Y-%m-%d')
10
-
11
- s.summary = 'I18n tool to translate your Ruby application.'
12
- s.description = <<-DESC
13
- R18n is a i18n tool to translate your Ruby application.
14
- It has nice Ruby-style syntax, filters, flexible locales, custom loaders,
15
- translation support for any classes, time and number localization, several
16
- user language support, agnostic core package with out-of-box support for
17
- Rails, Sinatra and desktop applications.
18
- DESC
19
-
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- s.extra_rdoc_files = ['README.md', 'LICENSE']
23
- s.require_path = 'lib'
24
-
25
- s.author = 'Andrey Sitnik'
26
- s.email = 'andrey@sitnik.ru'
27
- s.homepage = 'https://github.com/ai/r18n'
28
- s.license = 'LGPL-3.0'
29
- end
data/spec/filters_spec.rb DELETED
@@ -1,324 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Filters do
4
- before do
5
- @system = R18n::Filters.defined.values
6
- @enabled = R18n::Filters.defined.values.select(&:enabled?)
7
- @i18n = R18n::I18n.new('en', DIR)
8
- @i18n.reload!
9
- end
10
-
11
- after do
12
- R18n::Filters.defined.each_value do |filter|
13
- next if @system.include? filter
14
- R18n::Filters.delete(filter)
15
- end
16
-
17
- @enabled.each { |i| R18n::Filters.on(i) unless i.enabled? }
18
- (@system - @enabled).each { |i| R18n::Filters.off(i) if i.enabled? }
19
- end
20
-
21
- it 'adds new filter' do
22
- filter = R18n::Filters.add('my', :my_filter) { |i, _config| i }
23
-
24
- expect(filter).to be_kind_of(R18n::Filters::Filter)
25
- expect(filter.name).to eq(:my_filter)
26
- expect(filter.types).to eq(['my'])
27
- expect(filter).to be_enabled
28
-
29
- expect(R18n::Filters.defined).to have_key(:my_filter)
30
-
31
- @i18n.reload!
32
- expect(@i18n.my_filter).to eq('value')
33
- expect(@i18n.my_tree_filter).to eq('name' => 'value')
34
- end
35
-
36
- it 'adds filter for several types' do
37
- R18n::Filters.add(%w[my your]) { |i, _config| i + '1' }
38
- @i18n.reload!
39
- expect(@i18n.my_filter).to eq('value1')
40
- expect(@i18n.your_filter).to eq('another1')
41
- end
42
-
43
- it 'uses passive filters' do
44
- filter = double
45
- expect(filter).to receive(:process).twice.and_return(1)
46
-
47
- R18n::Filters.add('my', :passive, passive: true) { filter.process }
48
-
49
- expect(@i18n.my_filter).to eq('value')
50
- @i18n.reload!
51
-
52
- expect(@i18n.my_tree_filter).to eq(1)
53
- expect(@i18n.my_filter).to eq(1)
54
- expect(@i18n.my_filter).to eq(1)
55
- end
56
-
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
- expect(@i18n.my_filter).to eq('value312')
62
- end
63
-
64
- it 'returns name for nameless filter' do
65
- R18n::Filters.instance_variable_set(:@last_auto_name, 0)
66
-
67
- expect(R18n::Filters.add('some').name).to eq(1)
68
- expect(R18n::Filters.add('some', position: 0).name).to eq(2)
69
-
70
- R18n::Filters.add('some', 3)
71
- expect(R18n::Filters.add('some').name).to eq(4)
72
- end
73
-
74
- it 'deletes filter by name' do
75
- R18n::Filters.add('my', :my_filter) { '1' }
76
- expect(@i18n.my_filter).to eq('1')
77
-
78
- R18n::Filters.delete(:my_filter)
79
- expect(R18n::Filters.defined).not_to have_key(:my_filter)
80
- expect(@i18n.my_filter).to eq('value')
81
- end
82
-
83
- it 'deletes filter by object' do
84
- filter = R18n::Filters.add('my') { '1' }
85
- expect(@i18n.my_filter).to eq('1')
86
-
87
- R18n::Filters.delete(filter)
88
- expect(R18n::Filters.defined).not_to have_key(filter.name)
89
- expect(@i18n.my_filter).to eq('value')
90
- end
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 + '!' }
95
-
96
- expect(@i18n.one('1', '2')).to eq('One12!')
97
- end
98
-
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
-
103
- R18n::Filters.off(:one)
104
- expect(R18n::Filters.defined[:one]).not_to be_enabled
105
- expect(@i18n.my_filter).to eq('value2')
106
-
107
- R18n::Filters.on(:one)
108
- expect(R18n::Filters.defined[:one]).to be_enabled
109
- expect(@i18n.my_filter).to eq('value12')
110
- end
111
-
112
- it 'sends config to filter' do
113
- R18n::Filters.add('my') do |_i, config|
114
- config[:secret_value] = 1
115
- config
116
- end
117
- expect(@i18n.my_filter[:locale]).to eq(@i18n.locale)
118
- expect(@i18n.my_filter[:path]).to eq('my_filter')
119
- expect(@i18n.my_filter[:secret_value]).to eq(1)
120
- expect(@i18n.my_filter[:unknown_value]).to be_nil
121
- end
122
-
123
- it 'sets path in config' do
124
- R18n::Filters.add(String) do |_i, config|
125
- config[:path]
126
- end
127
-
128
- expect(@i18n.in.another.level).to eq('in.another.level')
129
- end
130
-
131
- it 'returns translated string after filters' do
132
- R18n::Filters.add(String) { |i, _config| i + '1' }
133
-
134
- expect(@i18n.one).to be_kind_of(R18n::TranslatedString)
135
- expect(@i18n.one.path).to eq('one')
136
- expect(@i18n.one.locale).to eq(R18n.locale('en'))
137
- end
138
-
139
- it 'uses one config for cascade filters' do
140
- R18n::Filters.add('my') { |_content, config| config[:new_secret] ? 2 : 1 }
141
- expect(@i18n.my_filter).to eq(1)
142
-
143
- R18n::Filters.add('my', :second, position: 0) do |content, config|
144
- config[:new_secret] = true
145
- content
146
- end
147
- expect(@i18n.my_filter).to eq(2)
148
- end
149
-
150
- it 'sends parameters to filter' do
151
- R18n::Filters.add('my') { |i, _config, a, b| "#{i}#{a}#{b}" }
152
- expect(@i18n['my_filter', 1, 2]).to eq('value12')
153
- expect(@i18n.my_filter(1, 2)).to eq('value12')
154
- end
155
-
156
- it 'pluralizes translation' do
157
- expect(@i18n.comments(0, 'article')).to eq('no comments for article')
158
- expect(@i18n.comments(1, 'article')).to eq('one comment for article')
159
- expect(@i18n.comments(5, 'article')).to eq('5 comments for article')
160
-
161
- expect(@i18n.files(0)).to eq('0 files')
162
- expect(@i18n.files(-5.5)).to eq('−5.5 files')
163
- expect(@i18n.files(5000)).to eq('5,000 files')
164
- end
165
-
166
- it "doesn't pluralize without first numeric parameter" do
167
- expect(@i18n.files).to be_kind_of(R18n::UnpluralizetedTranslation)
168
- expect(@i18n.files('')).to be_kind_of(R18n::UnpluralizetedTranslation)
169
- expect(@i18n.files[1]).to eq('1 file')
170
- expect(@i18n.files.n(5)).to eq('5 files')
171
- end
172
-
173
- it 'converts first float parameter to number' do
174
- expect(@i18n.files(1.2)).to eq('1 file')
175
- end
176
-
177
- it 'pluralizes translation without locale' do
178
- i18n = R18n::I18n.new('nolocale', DIR)
179
- expect(i18n.entries(1)).to eq('ONE')
180
- expect(i18n.entries(5)).to eq('N')
181
- end
182
-
183
- it 'cans use params in translation' do
184
- expect(@i18n.params(-1, 2)).to eq('Is −1 between −1 and 2?')
185
- end
186
-
187
- it "substitutes '%2' as param but not value of second param" do
188
- expect(@i18n.params('%2 FIRST', 'SECOND')).to eq(
189
- 'Is %2 FIRST between %2 FIRST and SECOND?'
190
- )
191
- end
192
-
193
- it 'interpolates named variables' do
194
- R18n::Filters.off(:named_variables)
195
- expect(@i18n.echo(value: 'R18n')).to eq 'Value is %{value}'
196
-
197
- R18n::Filters.on(:named_variables)
198
- expect(@i18n.echo(value: 'R18n')).to eq 'Value is R18n'
199
- expect(@i18n.echo(value: -5.5)).to eq 'Value is −5.5'
200
- expect(@i18n.echo(value: 5000)).to eq 'Value is 5,000'
201
- expect(@i18n.echo(value: '<b>')).to eq 'Value is <b>'
202
- expect(@i18n.echo).to eq 'Value is %{value}'
203
-
204
- expect(@i18n.echo2(value: 'R18n')).to eq 'Value2 is R18n'
205
- expect(@i18n.echo2).to eq 'Value2 is {{value}}'
206
- end
207
-
208
- it 'formats untranslated' do
209
- expect(@i18n.in.not.to_s).to eq('in.[not]')
210
- expect(@i18n.in.not.to_str).to eq('in.[not]')
211
-
212
- expect(@i18n.one.not_exists.to_s).to eq('one.[not_exists]')
213
-
214
- R18n::Filters.off(:untranslated)
215
- expect(@i18n.in.not.to_s).to eq('in.not')
216
-
217
- R18n::Filters.add(R18n::Untranslated) do |_v, _c, trans, untrans, path|
218
- "#{path} #{trans}[#{untrans}]"
219
- end
220
- expect(@i18n.in.not.to_s).to eq('in.not in.[not]')
221
- end
222
-
223
- it 'formats translation path' do
224
- expect(@i18n.in.another.to_s).to eq('in.another[]')
225
-
226
- R18n::Filters.off(:untranslated)
227
- expect(@i18n.in.another.to_s).to eq('in.another')
228
-
229
- R18n::Filters.add(R18n::Untranslated) do |_v, _c, trans, untrans, path|
230
- "#{path} #{trans}[#{untrans}]"
231
- end
232
- expect(@i18n.in.another.to_s).to eq('in.another in.another[]')
233
- end
234
-
235
- it 'formats untranslated for web' do
236
- R18n::Filters.off(:untranslated)
237
- R18n::Filters.on(:untranslated_html)
238
- expect(@i18n.in.not.to_s).to eq('in.<span style="color: red">[not]</span>')
239
- expect(@i18n['<b>'].to_s).to eq(
240
- '<span style="color: red">[&lt;b&gt;]</span>'
241
- )
242
- end
243
-
244
- it 'allows to set custom filters' do
245
- R18n::Filters.add(R18n::Untranslated, :a) { |v, _c| "a #{v}" }
246
- R18n::Filters.off(:a)
247
-
248
- html = R18n::I18n.new(
249
- 'en', DIR,
250
- off_filters: :untranslated, on_filters: %i[untranslated_html a]
251
- )
252
- expect(html.in.not.to_s).to eq('a in.<span style="color: red">[not]</span>')
253
- end
254
-
255
- it 'has filter for escape HTML' do
256
- expect(@i18n.html).to eq(
257
- '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;'
258
- )
259
- end
260
-
261
- it 'has disabled global filter for escape HTML' do
262
- expect(@i18n.greater('true')).to eq('1 < 2 is true')
263
-
264
- R18n::Filters.on(:global_escape_html)
265
- @i18n.reload!
266
- expect(@i18n.greater('true')).to eq('1 &lt; 2 is true')
267
- expect(@i18n.html).to eq(
268
- '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;'
269
- )
270
- end
271
-
272
- it 'has filter to disable global HTML escape' do
273
- expect(@i18n.no_escape).to eq('<b>Warning</b>')
274
-
275
- R18n::Filters.on(:global_escape_html)
276
- @i18n.reload!
277
- expect(@i18n.no_escape).to eq('<b>Warning</b>')
278
- end
279
-
280
- it 'has Markdown filter' do
281
- expect(@i18n.markdown.simple).to eq("<p><strong>Hi!</strong></p>\n")
282
- end
283
-
284
- it 'has Textile filter' do
285
- expect(@i18n.textile.simple).to eq('<p><em>Hi!</em></p>')
286
- end
287
-
288
- it 'HTML escapes before Markdown and Textile filters' do
289
- expect(@i18n.markdown.html).to eq("<p><strong>Hi!</strong> <br /></p>\n")
290
- expect(@i18n.textile.html).to eq('<p><em>Hi!</em><br /></p>')
291
-
292
- R18n::Filters.on(:global_escape_html)
293
- @i18n.reload!
294
- expect(@i18n.markdown.html).to eq(
295
- "<p><strong>Hi!</strong> &lt;br /&gt;</p>\n"
296
- )
297
- expect(@i18n.textile.html).to eq(
298
- '<p><em>Hi!</em>&lt;br /&gt;</p>'
299
- )
300
- end
301
-
302
- it 'allows to listen filters adding' do
303
- expect(R18n::Filters.listen do
304
- R18n::Filters.add(String, :a) {}
305
- end).to eq([R18n::Filters.defined[:a]])
306
- end
307
-
308
- it 'escapes variables if ActiveSupport is loaded' do
309
- expect(@i18n.escape_params('<br>')).to eq('<b><br></b>')
310
-
311
- require 'active_support'
312
-
313
- expect(@i18n.escape_params('<br>')).to eq('<b>&lt;br&gt;</b>')
314
-
315
- R18n::Filters.on(:global_escape_html)
316
- @i18n.reload!
317
-
318
- expect(@i18n.greater('<b>'.html_safe)).to eq('1 &lt; 2 is <b>')
319
-
320
- R18n::Filters.on(:named_variables)
321
-
322
- expect(@i18n.echo(value: '<b>')).to eq 'Value is &lt;b&gt;'
323
- end
324
- end