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.
- 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/lib/r18n-core/utils.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
the
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Common methods for i18n support.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
# Common methods for another R18n code.
|
21
21
|
module R18n
|
22
22
|
module Utils
|
23
|
-
HTML_ENTRIES = { '&' => '&', '<' => '<', '>' => '>' }
|
23
|
+
HTML_ENTRIES = { '&' => '&', '<' => '<', '>' => '>' }.freeze
|
24
24
|
|
25
25
|
# Escape HTML entries (<, >, &). Copy from HAML helper.
|
26
26
|
def self.escape_html(content)
|
@@ -39,18 +39,19 @@ module R18n
|
|
39
39
|
new_key, new_value = block.call(key, val)
|
40
40
|
result[new_key] = new_value
|
41
41
|
end
|
42
|
-
|
42
|
+
result
|
43
43
|
end
|
44
44
|
|
45
45
|
# Recursively hash merge.
|
46
46
|
def self.deep_merge!(a, b)
|
47
47
|
b.each_pair do |key, value|
|
48
48
|
another = a[key]
|
49
|
-
a[key] =
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
a[key] =
|
50
|
+
if another.is_a?(Hash) && value.is_a?(Hash)
|
51
|
+
deep_merge!(another, value)
|
52
|
+
else
|
53
|
+
value
|
54
|
+
end
|
54
55
|
end
|
55
56
|
a
|
56
57
|
end
|
data/lib/r18n-core/version.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
|
2
|
-
Loader for YAML translations.
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
# Loader for YAML translations.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
module R18n
|
21
21
|
module Loader
|
@@ -43,9 +43,9 @@ module R18n
|
|
43
43
|
|
44
44
|
# Array of locales, which has translations in +dir+.
|
45
45
|
def available
|
46
|
-
Dir.glob(File.join(@dir, '**/*.yml'))
|
47
|
-
map { |i| File.basename(i, '.yml') }.uniq
|
48
|
-
map { |i| R18n.locale(i) }
|
46
|
+
Dir.glob(File.join(@dir, '**/*.yml'))
|
47
|
+
.map { |i| File.basename(i, '.yml') }.uniq
|
48
|
+
.map { |i| R18n.locale(i) }
|
49
49
|
end
|
50
50
|
|
51
51
|
# Return Hash with translations for +locale+.
|
@@ -54,7 +54,7 @@ module R18n
|
|
54
54
|
|
55
55
|
translations = {}
|
56
56
|
Dir.glob(File.join(@dir, "**/#{locale.code.downcase}.yml")).each do |i|
|
57
|
-
Utils.deep_merge!(translations, ::YAML
|
57
|
+
Utils.deep_merge!(translations, ::YAML.load_file(i) || {})
|
58
58
|
end
|
59
59
|
transform(translations)
|
60
60
|
end
|
@@ -65,8 +65,8 @@ module R18n
|
|
65
65
|
end
|
66
66
|
|
67
67
|
# Is another +loader+ load YAML translations from same +dir+.
|
68
|
-
def ==(
|
69
|
-
self.class ==
|
68
|
+
def ==(other)
|
69
|
+
self.class == other.class && dir == other.dir
|
70
70
|
end
|
71
71
|
|
72
72
|
# Wrap YAML private types to Typed.
|
@@ -74,9 +74,10 @@ module R18n
|
|
74
74
|
R18n::Utils.hash_map(a_hash) do |key, value|
|
75
75
|
if value.is_a? Hash
|
76
76
|
value = transform(value)
|
77
|
-
elsif @private_type_class
|
77
|
+
elsif defined?(@private_type_class) &&
|
78
|
+
value.is_a?(@private_type_class)
|
78
79
|
v = value.value
|
79
|
-
if v.respond_to?(:force_encoding)
|
80
|
+
if v.respond_to?(:force_encoding) && v.encoding != __ENCODING__
|
80
81
|
v = v.force_encoding(__ENCODING__)
|
81
82
|
end
|
82
83
|
value = Typed.new(value.type_id, v)
|
@@ -1,21 +1,21 @@
|
|
1
|
-
|
2
|
-
Base methods to load translations for YAML.
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
# Base methods to load translations for YAML.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
require 'yaml'
|
21
21
|
|
@@ -25,21 +25,18 @@ module R18n
|
|
25
25
|
module YamlMethods
|
26
26
|
# Detect class for private type depend on YAML parser.
|
27
27
|
def detect_yaml_private_type
|
28
|
-
@private_type_class = if defined?(Syck)
|
29
|
-
::Syck::PrivateType
|
30
|
-
end
|
28
|
+
@private_type_class = ::Syck::PrivateType if defined?(Syck)
|
31
29
|
end
|
32
30
|
|
33
31
|
# Register global types in Psych
|
34
32
|
def initialize_types
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
33
|
+
return unless defined?(Psych)
|
34
|
+
Filters.by_type.each_key do |type|
|
35
|
+
next unless type.is_a? String
|
36
|
+
# Yeah, I add R18n’s types to global, send me patch if you really
|
37
|
+
# use YAML types too ;).
|
38
|
+
Psych.add_domain_type('yaml.org,2002', type) do |_full_type, value|
|
39
|
+
Typed.new(type, value)
|
43
40
|
end
|
44
41
|
end
|
45
42
|
end
|
data/locales/af.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module R18n
|
2
|
-
|
3
|
-
|
4
|
+
module Locales
|
5
|
+
# Afrikaans locale
|
6
|
+
class Af < Locale
|
7
|
+
set(
|
8
|
+
title: 'Afrikaans',
|
4
9
|
|
5
10
|
week_start: :sondag,
|
6
|
-
wday_names: %w
|
7
|
-
Saterdag
|
8
|
-
wday_abbrs: %w
|
11
|
+
wday_names: %w[Sondag Maandag Dinsdag Woensdag Donderdag Vrydag
|
12
|
+
Saterdag],
|
13
|
+
wday_abbrs: %w[So Ma Di Wo Do Vr Sa],
|
9
14
|
|
10
|
-
month_names: %w
|
11
|
-
September Oktober November Desember
|
12
|
-
month_abbrs: %w
|
15
|
+
month_names: %w[Januarie Februarie Maart April Mei Junie Julie Augustus
|
16
|
+
September Oktober November Desember],
|
17
|
+
month_abbrs: %w[Jan Feb Mrt Apr Mei Jun Jul Aug Sep Okt Nov Des],
|
13
18
|
|
14
19
|
time_am: "'s voormiddag",
|
15
20
|
time_pm: "'s namiddag",
|
@@ -21,5 +26,7 @@ module R18n
|
|
21
26
|
|
22
27
|
number_decimal: '.',
|
23
28
|
number_group: ','
|
29
|
+
)
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|
data/locales/az.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module R18n
|
2
|
-
|
3
|
-
|
4
|
+
module Locales
|
5
|
+
# Azerbaijani locale
|
6
|
+
class Az < Locale
|
7
|
+
set(
|
8
|
+
title: 'Azərbaycanca',
|
4
9
|
|
5
|
-
wday_names: %w
|
6
|
-
Şənbə
|
7
|
-
wday_abbrs: %w
|
10
|
+
wday_names: %w[Bazar BazarErtəsi ÇərşənbəAxşamı Çərşənbə CüməAxşamı Cümə
|
11
|
+
Şənbə],
|
12
|
+
wday_abbrs: %w[B. B.e Ç.a Ç. C.a C. Ş.],
|
8
13
|
|
9
|
-
month_names: %w
|
10
|
-
sentyabr oktyabr noyabr dekabr
|
11
|
-
month_abbrs: %w
|
12
|
-
month_standalone: %w
|
13
|
-
Sentyabr Oktyabr Noyabr Dekabr
|
14
|
+
month_names: %w[yanvar fevral mart aprel may iyun iyul avqust
|
15
|
+
sentyabr oktyabr noyabr dekabr],
|
16
|
+
month_abbrs: %w[yan fev mar apr may iyn iyl avq sen okt noy dek],
|
17
|
+
month_standalone: %w[Yanvar Fevral Mart Aprel May İyun İyul Avqust
|
18
|
+
Sentyabr Oktyabr Noyabr Dekabr],
|
14
19
|
|
15
20
|
time_am: ' gündüz',
|
16
21
|
time_pm: ' axşam',
|
@@ -19,9 +24,11 @@ module R18n
|
|
19
24
|
|
20
25
|
number_decimal: ',',
|
21
26
|
number_group: ' '
|
27
|
+
)
|
22
28
|
|
23
|
-
|
24
|
-
|
29
|
+
def pluralize(_n)
|
30
|
+
'n'
|
31
|
+
end
|
25
32
|
end
|
26
33
|
end
|
27
34
|
end
|
data/locales/bg.rb
CHANGED
@@ -1,18 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module R18n
|
2
|
-
|
3
|
-
|
4
|
+
module Locales
|
5
|
+
# Bulgarian locale
|
6
|
+
class Bg < 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
|
-
Септември Октомври Ноември Декември
|
10
|
-
month_abbrs: %w
|
11
|
-
month_standalone: %w
|
12
|
-
Септември Октомври Ноември Декември
|
13
|
+
month_names: %w[Януари Февруари Март Април Май Юни Юли Август
|
14
|
+
Септември Октомври Ноември Декември],
|
15
|
+
month_abbrs: %w[Яну Фев Мар Апр Май Юни Юли Авг Сеп Окт Ное Дек],
|
16
|
+
month_standalone: %w[Януари Февруари Март Април Май Юни Юли Август
|
17
|
+
Септември Октомври Ноември Декември],
|
13
18
|
date_format: '%d.%m.%Y',
|
14
19
|
|
15
20
|
number_decimal: ',',
|
16
21
|
number_group: ' '
|
22
|
+
)
|
23
|
+
end
|
17
24
|
end
|
18
25
|
end
|
data/locales/ca.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module R18n
|
2
|
-
|
3
|
-
|
4
|
-
|
4
|
+
module Locales
|
5
|
+
# Catalan locale
|
6
|
+
class Ca < Locale
|
7
|
+
set(
|
8
|
+
title: 'Català',
|
9
|
+
sublocales: %w[es en],
|
5
10
|
|
6
|
-
wday_names: %w
|
7
|
-
dissabte
|
8
|
-
wday_abbrs: %w
|
11
|
+
wday_names: %w[diumenge dilluns dimarts dimecres dijous divendres
|
12
|
+
dissabte],
|
13
|
+
wday_abbrs: %w[dg dl dm dc dj dv ds],
|
9
14
|
|
10
|
-
month_names: %w
|
11
|
-
Setembre Octubre Novembre Desembre
|
12
|
-
month_abbrs: %w
|
15
|
+
month_names: %w[Gener Febrer Març Abril Maig Juny Juliol Agost
|
16
|
+
Setembre Octubre Novembre Desembre],
|
17
|
+
month_abbrs: %w[gen feb mar abr mai jun jul ago set oct nov des],
|
13
18
|
|
14
19
|
date_format: '%d/%m/%Y',
|
15
20
|
full_format: '%d de %B',
|
@@ -17,5 +22,7 @@ module R18n
|
|
17
22
|
|
18
23
|
number_decimal: ',',
|
19
24
|
number_group: '.'
|
25
|
+
)
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
data/locales/cs.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module R18n
|
2
|
-
|
3
|
-
|
4
|
-
|
4
|
+
module Locales
|
5
|
+
# Czech locale
|
6
|
+
class Cs < Locale
|
7
|
+
set(
|
8
|
+
title: 'Český',
|
9
|
+
sublocales: %w[cz sk en],
|
5
10
|
|
6
|
-
wday_names: %w
|
7
|
-
wday_abbrs: %w
|
11
|
+
wday_names: %w[Neděle Pondělí Úterý Středa Čtvrtek Pátek Sobota],
|
12
|
+
wday_abbrs: %w[Ne Po Út St Čt Pá So],
|
8
13
|
|
9
|
-
month_names: %w
|
10
|
-
září října listopadu prosince
|
11
|
-
month_abbrs: %w
|
12
|
-
month_standalone: %w
|
13
|
-
Srpen Září Říjen Listopad Prosinec
|
14
|
+
month_names: %w[ledna února března dubna května června července srpna
|
15
|
+
září října listopadu prosince],
|
16
|
+
month_abbrs: %w[led úno bře dub kvě čer čvc srp zář říj lis pro],
|
17
|
+
month_standalone: %w[Leden Únor Březen Duben Květen Červen Červenec
|
18
|
+
Srpen Září Říjen Listopad Prosinec],
|
14
19
|
|
15
20
|
time_am: 'dop.',
|
16
21
|
time_pm: 'odp.',
|
@@ -19,17 +24,19 @@ module R18n
|
|
19
24
|
|
20
25
|
number_decimal: ',',
|
21
26
|
number_group: ' '
|
27
|
+
)
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def pluralize(n)
|
30
|
+
case n
|
31
|
+
when 0
|
32
|
+
0
|
33
|
+
when 1
|
34
|
+
1
|
35
|
+
when 2..4
|
36
|
+
2
|
37
|
+
else
|
38
|
+
'n'
|
39
|
+
end
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|