r18n-core 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -1
- data/ChangeLog.md +6 -1
- data/README.md +1 -20
- data/Rakefile +5 -3
- data/lib/r18n-core.rb +55 -55
- data/lib/r18n-core/filter_list.rb +34 -36
- data/lib/r18n-core/filters.rb +68 -51
- data/lib/r18n-core/helpers.rb +17 -17
- data/lib/r18n-core/i18n.rb +46 -39
- data/lib/r18n-core/locale.rb +79 -70
- data/lib/r18n-core/translated.rb +65 -66
- data/lib/r18n-core/translated_string.rb +24 -24
- data/lib/r18n-core/translation.rb +31 -30
- data/lib/r18n-core/unsupported_locale.rb +22 -24
- data/lib/r18n-core/untranslated.rb +35 -33
- data/lib/r18n-core/utils.rb +26 -25
- data/lib/r18n-core/version.rb +4 -1
- data/lib/r18n-core/yaml_loader.rb +26 -25
- data/lib/r18n-core/yaml_methods.rb +25 -28
- data/locales/af.rb +15 -8
- data/locales/az.rb +19 -12
- data/locales/bg.rb +16 -9
- data/locales/ca.rb +16 -9
- data/locales/cs.rb +27 -20
- data/locales/da.rb +15 -8
- data/locales/de.rb +16 -9
- data/locales/en-au.rb +10 -5
- data/locales/en-gb.rb +12 -5
- data/locales/en-us.rb +12 -5
- data/locales/en.rb +29 -22
- data/locales/eo.rb +14 -7
- data/locales/es-us.rb +12 -5
- data/locales/es.rb +14 -7
- data/locales/fa.rb +48 -32
- data/locales/fi.rb +19 -12
- data/locales/fr.rb +22 -15
- data/locales/gl.rb +15 -8
- data/locales/hr.rb +24 -17
- data/locales/hu.rb +28 -21
- data/locales/id.rb +14 -7
- data/locales/it.rb +21 -14
- data/locales/ja.rb +15 -8
- data/locales/kk.rb +17 -10
- data/locales/ko.rb +15 -9
- data/locales/lv.rb +24 -17
- data/locales/mn.rb +10 -3
- data/locales/nb.rb +15 -8
- data/locales/nl.rb +15 -8
- data/locales/no.rb +11 -16
- data/locales/pl.rb +26 -19
- data/locales/pt-br.rb +12 -5
- data/locales/pt.rb +17 -10
- data/locales/ru.rb +26 -19
- data/locales/sk.rb +27 -20
- data/locales/sr-latn.rb +27 -22
- data/locales/sv-se.rb +15 -8
- data/locales/th.rb +27 -20
- data/locales/tr.rb +16 -9
- data/locales/uk.rb +19 -12
- data/locales/vi.rb +14 -7
- data/locales/zh-cn.rb +12 -5
- data/locales/zh-tw.rb +15 -8
- data/locales/zh.rb +14 -7
- data/r18n-core.gemspec +5 -3
- data/spec/filters_spec.rb +71 -67
- data/spec/i18n_spec.rb +73 -51
- data/spec/locale_spec.rb +73 -68
- data/spec/locales/cs_spec.rb +2 -2
- data/spec/locales/en-us_spec.rb +9 -9
- data/spec/locales/en_spec.rb +2 -2
- data/spec/locales/fa_spec.rb +3 -3
- data/spec/locales/fr_spec.rb +2 -2
- data/spec/locales/hu_spec.rb +7 -7
- data/spec/locales/it_spec.rb +3 -3
- data/spec/locales/no_spec.rb +9 -0
- data/spec/locales/pl_spec.rb +2 -2
- data/spec/locales/ru_spec.rb +2 -2
- data/spec/locales/sk_spec.rb +2 -2
- data/spec/locales/th_spec.rb +2 -2
- data/spec/locales/vi_spec.rb +2 -2
- data/spec/r18n_spec.rb +44 -38
- data/spec/spec_helper.rb +13 -9
- data/spec/translated_spec.rb +48 -31
- data/spec/translation_spec.rb +29 -27
- data/spec/translations/general/en.yml +0 -2
- data/spec/yaml_loader_spec.rb +22 -18
- metadata +5 -3
data/locales/th.rb
CHANGED
@@ -1,30 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module R18n
|
2
|
-
|
3
|
-
|
4
|
+
module Locales
|
5
|
+
# Thai locale
|
6
|
+
class Th < Locale
|
7
|
+
set(
|
8
|
+
title: 'ภาษาไทย',
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
10
|
+
wday_names: %w[วันอาทิตย์ วันจันทร์ วันอังคาร วันพุธ วันพฤหัสบดี
|
11
|
+
วันศุกร์ วันเสาร์],
|
12
|
+
wday_abbrs: %w[อาทิตย์ จันทร์ อังคาร พุธ พฤหัสบดี ศุกร์ เสาร์],
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
month_names: %w[มกราคม กุมภาพันธ์ มีนาคม เมษายน พฤษภาคม มิถุนายน
|
15
|
+
กรกฎาคม สิงหาคม กันยายน ตุลาคม พฤศจิกายน ธันวาคม],
|
16
|
+
month_abbrs: %w[ม.ค. ก.พ. มี.ค. เม.ย. พ.ค. มิ.ย. ก.ค. ส.ค. ก.ย. ต.ค.
|
17
|
+
พ.ย. ธ.ค.],
|
13
18
|
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
date_format: '%d/%m/%Y',
|
20
|
+
full_format: '%e %B',
|
21
|
+
year_format: '_, %Y',
|
17
22
|
|
18
|
-
|
19
|
-
|
23
|
+
number_decimal: '.',
|
24
|
+
number_group: ','
|
25
|
+
)
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
def pluralize(_n)
|
28
|
+
'n'
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
data/locales/tr.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module R18n
|
2
|
-
|
3
|
-
|
4
|
+
module Locales
|
5
|
+
# Turkish locale
|
6
|
+
class Tr < Locale
|
7
|
+
set(
|
8
|
+
title: 'Türkçe',
|
4
9
|
|
5
|
-
wday_names: %w
|
6
|
-
wday_abbrs: %w
|
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
|
9
|
-
Ekim Kasım Aralık
|
10
|
-
month_abbrs: %w
|
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
|
-
|
21
|
-
|
26
|
+
def pluralize(_n)
|
27
|
+
'n'
|
28
|
+
end
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
data/locales/uk.rb
CHANGED
@@ -1,20 +1,27 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
class Uk < Ru
|
5
|
-
set title: 'Українська',
|
6
|
-
sublocales: %w{ru en},
|
3
|
+
require_relative 'ru'
|
7
4
|
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
data/locales/vi.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module R18n
|
2
|
-
|
3
|
-
|
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
|
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','
|
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
|
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
|
-
|
23
|
-
|
28
|
+
def pluralize(_n)
|
29
|
+
'n'
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|
data/locales/zh-cn.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
data/locales/zh-tw.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
class ZhTw < Zh
|
5
|
-
set title: '繁體中文',
|
6
|
-
sublocales: %w{zh en},
|
3
|
+
require_relative 'zh'
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
data/locales/zh.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module R18n
|
2
|
-
|
3
|
-
|
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(
|
24
|
+
def pluralize(_n)
|
19
25
|
'n'
|
20
26
|
end
|
27
|
+
end
|
21
28
|
end
|
22
29
|
end
|
data/r18n-core.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
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 = <<-
|
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
|
-
|
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")
|
data/spec/filters_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
|
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.
|
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.
|
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
|
22
|
-
filter = R18n::Filters.add('my', :my_filter) { |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(
|
33
|
+
expect(@i18n.my_tree_filter).to eq('name' => 'value')
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
|
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
|
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
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
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
|
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
|
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
|
93
|
-
R18n::Filters.add(String) { |result,
|
94
|
-
R18n::Filters.add(String) { |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
|
100
|
-
|
101
|
-
|
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
|
113
|
-
R18n::Filters.add('my') do |
|
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
|
124
|
-
R18n::Filters.add(String) do |
|
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
|
132
|
-
R18n::Filters.add(String) { |i,
|
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
|
140
|
-
R18n::Filters.add('my') { |
|
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
|
151
|
-
R18n::Filters.add('my') { |i,
|
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
|
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
|
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
|
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
|
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
|
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 |
|
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
|
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 |
|
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
|
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(
|
222
|
+
expect(@i18n['<b>'].to_s).to eq(
|
223
|
+
'<span style="color: red">[<b>]</span>'
|
224
|
+
)
|
227
225
|
end
|
228
226
|
|
229
|
-
it
|
230
|
-
R18n::Filters.add(R18n::Untranslated, :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(
|
234
|
-
|
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
|
238
|
+
it 'has filter for escape HTML' do
|
239
239
|
expect(@i18n.html).to eq(
|
240
|
-
'<script>true && false</script>'
|
240
|
+
'<script>true && false</script>'
|
241
|
+
)
|
241
242
|
end
|
242
243
|
|
243
|
-
it
|
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 < 2 is true')
|
249
250
|
expect(@i18n.html).to eq(
|
250
|
-
'<script>true && false</script>'
|
251
|
+
'<script>true && false</script>'
|
252
|
+
)
|
251
253
|
end
|
252
254
|
|
253
|
-
it
|
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
|
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
|
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
|
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> <br /></p>\n"
|
278
|
+
"<p><strong>Hi!</strong> <br /></p>\n"
|
279
|
+
)
|
277
280
|
expect(@i18n.textile.html).to eq(
|
278
|
-
'<p><em>Hi!</em><br /></p>'
|
281
|
+
'<p><em>Hi!</em><br /></p>'
|
282
|
+
)
|
279
283
|
end
|
280
284
|
|
281
|
-
it
|
282
|
-
expect(R18n::Filters.listen
|
283
|
-
R18n::Filters.add(String, :a) {
|
284
|
-
|
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
|
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><br></b>')
|
291
295
|
end
|
292
296
|
|
293
|
-
it
|
297
|
+
it 'uses SafeBuffer if it is loaded' do
|
294
298
|
require 'active_support'
|
295
299
|
|
296
300
|
R18n::Filters.on(:global_escape_html)
|