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.
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,26 +1,26 @@
1
- =begin
2
- Common methods for i18n support.
3
-
4
- Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
5
-
6
- This program is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- =end
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 = { '&' => '&amp;', '<' => '&lt;', '>' => '&gt;' }
23
+ HTML_ENTRIES = { '&' => '&amp;', '<' => '&lt;', '>' => '&gt;' }.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
- result
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] = if another.is_a?(Hash) && value.is_a?(Hash)
50
- deep_merge!(another, value)
51
- else
52
- value
53
- end
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
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Version of R18n Core
1
4
  module R18n
2
- VERSION = '2.2.0'.freeze unless defined? R18n::VERSION
5
+ VERSION = '3.0.0'.freeze unless defined? R18n::VERSION
3
6
  end
@@ -1,21 +1,21 @@
1
- =begin
2
- Loader for YAML translations.
1
+ # frozen_string_literal: true
3
2
 
4
- Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
5
-
6
- This program is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- =end
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::load_file(i) || {})
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 ==(loader)
69
- self.class == loader.class and self.dir == loader.dir
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 and value.is_a? @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) and v.encoding != __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
- =begin
2
- Base methods to load translations for YAML.
1
+ # frozen_string_literal: true
3
2
 
4
- Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
5
-
6
- This program is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- =end
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
- if defined?(Psych)
36
- Filters.by_type.keys.each do |type|
37
- next unless type.is_a? String
38
- # Yeah, I add R18n’s types to global, send me patch if you really
39
- # use YAML types too ;).
40
- Psych.add_domain_type('yaml.org,2002', type) do |full_type, value|
41
- Typed.new(type, value)
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
@@ -1,15 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module R18n
2
- class Locales::Af < Locale
3
- set title: 'Afrikaans',
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{Sondag Maandag Dinsdag Woensdag Donderdag Vrydag
7
- Saterdag},
8
- wday_abbrs: %w{So Ma Di Wo Do Vr Sa},
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{Januarie Februarie Maart April Mei Junie Julie Augustus
11
- September Oktober November Desember},
12
- month_abbrs: %w{Jan Feb Mrt Apr Mei Jun Jul Aug Sep Okt Nov Des},
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
@@ -1,16 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module R18n
2
- class Locales::Az < Locale
3
- set title: 'Azərbaycanca',
4
+ module Locales
5
+ # Azerbaijani locale
6
+ class Az < Locale
7
+ set(
8
+ title: 'Azərbaycanca',
4
9
 
5
- wday_names: %w{Bazar BazarErtəsi ÇərşənbəAxşamı Çərşənbə CüməAxşamı Cümə
6
- Şənbə},
7
- wday_abbrs: %w{B. B.e Ç.a Ç. C.a C. Ş.},
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{yanvar fevral mart aprel may iyun iyul avqust
10
- sentyabr oktyabr noyabr dekabr},
11
- month_abbrs: %w{yan fev mar apr may iyn iyl avq sen okt noy dek},
12
- month_standalone: %w{Yanvar Fevral Mart Aprel May İyun İyul Avqust
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
- def pluralize(n)
24
- 'n'
29
+ def pluralize(_n)
30
+ 'n'
31
+ end
25
32
  end
26
33
  end
27
34
  end
@@ -1,18 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module R18n
2
- class Locales::Bg < Locale
3
- set title: 'Български',
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
@@ -1,15 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module R18n
2
- class Locales::Ca < Locale
3
- set title: 'Català',
4
- sublocales: %w{es en},
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{diumenge dilluns dimarts dimecres dijous divendres
7
- dissabte},
8
- wday_abbrs: %w{dg dl dm dc dj dv ds},
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{Gener Febrer Març Abril Maig Juny Juliol Agost
11
- Setembre Octubre Novembre Desembre},
12
- month_abbrs: %w{gen feb mar abr mai jun jul ago set oct nov des},
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
@@ -1,16 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module R18n
2
- class Locales::Cs < Locale
3
- set title: 'Český',
4
- sublocales: %w{cz sk en},
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{Neděle Pondělí Úterý Středa Čtvrtek Pátek Sobota},
7
- wday_abbrs: %w{Ne Po Út St Čt Pá So},
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{ledna února března dubna května června července srpna
10
- září října listopadu prosince},
11
- month_abbrs: %w{led úno bře dub kvě čer čvc srp zář říj lis pro},
12
- month_standalone: %w{Leden Únor Březen Duben Květen Červen Červenec
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
- def pluralize(n)
24
- case n
25
- when 0
26
- 0
27
- when 1
28
- 1
29
- when 2..4
30
- 2
31
- else
32
- 'n'
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