r18n-core 0.4.10 → 0.4.11

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 (57) hide show
  1. data/ChangeLog +5 -0
  2. data/Gemfile.lock +1 -1
  3. data/README.rdoc +25 -25
  4. data/Rakefile +0 -1
  5. data/lib/r18n-core.rb +5 -5
  6. data/lib/r18n-core/filters.rb +45 -45
  7. data/lib/r18n-core/helpers.rb +4 -4
  8. data/lib/r18n-core/i18n.rb +30 -30
  9. data/lib/r18n-core/locale.rb +26 -26
  10. data/lib/r18n-core/translated.rb +23 -23
  11. data/lib/r18n-core/translated_string.rb +4 -4
  12. data/lib/r18n-core/translation.rb +10 -10
  13. data/lib/r18n-core/unsupported_locale.rb +6 -6
  14. data/lib/r18n-core/untranslated.rb +13 -13
  15. data/lib/r18n-core/utils.rb +4 -4
  16. data/lib/r18n-core/version.rb +1 -1
  17. data/lib/r18n-core/yaml_loader.rb +13 -11
  18. data/locales/bg.rb +3 -3
  19. data/locales/ca.rb +6 -5
  20. data/locales/cs.rb +5 -5
  21. data/locales/da.rb +4 -4
  22. data/locales/de.rb +4 -4
  23. data/locales/en-us.rb +1 -1
  24. data/locales/en.rb +6 -6
  25. data/locales/eo.rb +4 -4
  26. data/locales/es.rb +4 -4
  27. data/locales/fi.rb +5 -5
  28. data/locales/fr.rb +6 -6
  29. data/locales/hu.rb +1 -1
  30. data/locales/it.rb +5 -5
  31. data/locales/ja.rb +5 -4
  32. data/locales/kk.rb +4 -4
  33. data/locales/lv.rb +5 -5
  34. data/locales/nl.rb +5 -5
  35. data/locales/pl.rb +5 -5
  36. data/locales/pt.rb +4 -4
  37. data/locales/ru.rb +5 -5
  38. data/locales/sk.rb +5 -5
  39. data/locales/sv-se.rb +4 -4
  40. data/locales/th.rb +7 -4
  41. data/locales/zh.rb +6 -5
  42. data/r18n-core.gemspec +0 -1
  43. data/spec/filters_spec.rb +48 -48
  44. data/spec/i18n_spec.rb +32 -32
  45. data/spec/locale_spec.rb +20 -20
  46. data/spec/locales/cs_spec.rb +2 -2
  47. data/spec/locales/hu_spec.rb +1 -1
  48. data/spec/locales/it_spec.rb +1 -1
  49. data/spec/locales/pl_spec.rb +2 -2
  50. data/spec/locales/ru_spec.rb +3 -3
  51. data/spec/locales/sk_spec.rb +2 -2
  52. data/spec/r18n_spec.rb +21 -21
  53. data/spec/spec_helper.rb +3 -3
  54. data/spec/translated_spec.rb +24 -24
  55. data/spec/translation_spec.rb +10 -10
  56. data/spec/yaml_loader_spec.rb +10 -10
  57. metadata +24 -26
@@ -23,10 +23,10 @@ module R18n
23
23
  class TranslatedString < String
24
24
  # String locale
25
25
  attr_reader :locale
26
-
26
+
27
27
  # Path for this translation.
28
28
  attr_reader :path
29
-
29
+
30
30
  # Returns a new string object containing a copy of +str+, which translated
31
31
  # for +path+ to +locale+
32
32
  def initialize(str, locale, path)
@@ -34,12 +34,12 @@ module R18n
34
34
  @locale = locale
35
35
  @path = path
36
36
  end
37
-
37
+
38
38
  # Return self for translated string.
39
39
  def |(default)
40
40
  self
41
41
  end
42
-
42
+
43
43
  # Return true for translated strings.
44
44
  def translated?
45
45
  true
@@ -23,7 +23,7 @@ require 'pathname'
23
23
  module R18n
24
24
  # Struct to containt translation with some type for filter.
25
25
  Typed = Struct.new(:type, :value, :locale, :path)
26
-
26
+
27
27
  # Translation is container of translated messages.
28
28
  #
29
29
  # You can load several locales and if translation willn’t be found in first,
@@ -46,11 +46,11 @@ module R18n
46
46
  #
47
47
  # one: One
48
48
  # two: Two
49
- #
49
+ #
50
50
  # entry:
51
51
  # between: Between %1 and %2
52
52
  # methods: Is %1 method
53
- #
53
+ #
54
54
  # comments: !!pl
55
55
  # 0: no comments
56
56
  # 1: one comment
@@ -60,13 +60,13 @@ module R18n
60
60
  #
61
61
  # i18n.one #=> "Один"
62
62
  # i18n.two #=> "Two"
63
- #
63
+ #
64
64
  # i18n.two.locale.code #=> "en"
65
65
  # i18n.two.locale.ltr? #=> "ltr"
66
66
  #
67
67
  # i18n.entry.between(2, 3) #=> "between 2 and 3"
68
68
  # i18n['methods', 'object'] #=> "Is object method"
69
- #
69
+ #
70
70
  # i18n.comments(0) #=> "no comments"
71
71
  # i18n.comments(10) #=> "10 comments"
72
72
  class Translation
@@ -80,7 +80,7 @@ module R18n
80
80
  @locale = main_locale
81
81
  merge! data, locale unless data.empty?
82
82
  end
83
-
83
+
84
84
  # Add another hash with +translations+ for some +locale+. Current data is
85
85
  # more priority, that new one in +translations+.
86
86
  def merge!(translations, locale)
@@ -108,23 +108,23 @@ module R18n
108
108
  end
109
109
  end
110
110
  end
111
-
111
+
112
112
  # Use untranslated filter to print path.
113
113
  def to_s
114
114
  Filters.process(Filters.enabled, Untranslated, @path, @locale, @path,
115
115
  [@path, '', @path])
116
116
  end
117
-
117
+
118
118
  # Return current translation keys.
119
119
  def _keys
120
120
  @data.keys
121
121
  end
122
-
122
+
123
123
  # Return +default+.
124
124
  def |(default)
125
125
  default
126
126
  end
127
-
127
+
128
128
  # Return translation with special +name+.
129
129
  #
130
130
  # Translation can contain variable part. Just set is as <tt>%1</tt>,
@@ -24,29 +24,29 @@ module R18n
24
24
  class UnsupportedLocale
25
25
  # Locale, to get data and pluralization for unsupported locale.
26
26
  attr_accessor :base
27
-
27
+
28
28
  # Create object for unsupported locale with +code+ and load other locale
29
29
  # data from +base+ locale.
30
30
  def initialize(code, base = nil)
31
31
  @code = code
32
32
  @base = Locale.load(I18n.default) if @code != I18n.default
33
33
  end
34
-
34
+
35
35
  # Is locale has information file. In this class always return false.
36
36
  def supported?
37
37
  false
38
38
  end
39
-
39
+
40
40
  # Human readable locale code and title.
41
41
  def inspect
42
42
  "Unsupported locale #{@code}"
43
43
  end
44
-
44
+
45
45
  # Locale RFC 3066 code.
46
46
  def code
47
47
  @code
48
48
  end
49
-
49
+
50
50
  # Locale code as title.
51
51
  def title
52
52
  @code
@@ -56,7 +56,7 @@ module R18n
56
56
  def ==(locale)
57
57
  @code.downcase == locale.code.downcase
58
58
  end
59
-
59
+
60
60
  # Proxy to default locale object.
61
61
  def method_missing(name, *params)
62
62
  @base.send(name, *params)
@@ -26,54 +26,54 @@ module R18n
26
26
  #
27
27
  # You can set format to print untranslated string by filters. For example:
28
28
  # Disable standart output:
29
- #
29
+ #
30
30
  # R18n::Filters.off(:untranslated)
31
- #
31
+ #
32
32
  # For development environment:
33
- #
33
+ #
34
34
  # R18n::Filters.add(R18n::Untranslated, :untranslated_html) do
35
35
  # |content, config, translated_path, untranslated_path, path|
36
36
  # "#{translated_path}<span style='color: red'>#{untranslated_path}</span>"
37
37
  # end
38
- #
38
+ #
39
39
  # For production environment:
40
- #
40
+ #
41
41
  # R18n::Filters.add(R18n::Untranslated, :hide_untranslated) { '' }
42
42
  class Untranslated
43
43
  # Path, that isn’t in translation.
44
44
  attr_reader :untranslated_path
45
-
45
+
46
46
  # Path, that exists in translation.
47
47
  attr_reader :translated_path
48
-
48
+
49
49
  def initialize(translated_path, untranslated_path, locale)
50
50
  @translated_path = translated_path
51
51
  @untranslated_path = untranslated_path
52
52
  @locale = locale
53
53
  end
54
-
54
+
55
55
  # Path to translation.
56
56
  def path
57
57
  "#{@translated_path}#{@untranslated_path}"
58
58
  end
59
-
59
+
60
60
  def translated?
61
61
  false
62
62
  end
63
-
63
+
64
64
  def method_missing(*params)
65
65
  self[params.first]
66
66
  end
67
-
67
+
68
68
  def [](*params)
69
69
  Untranslated.new(translated_path, "#{@untranslated_path}.#{params.first}",
70
70
  @locale)
71
71
  end
72
-
72
+
73
73
  def |(default)
74
74
  default
75
75
  end
76
-
76
+
77
77
  def to_s
78
78
  Filters.process(Filters.enabled, Untranslated, path, @locale, path,
79
79
  [@translated_path, @untranslated_path, path])
@@ -26,9 +26,9 @@ module R18n
26
26
  jd = Date.send(:civil_to_jd, time.year, time.mon, time.mday, Date::ITALY)
27
27
  Date.new!(Date.send(:jd_to_ajd, jd, 0, 0), 0, Date::ITALY)
28
28
  end
29
-
29
+
30
30
  HTML_ENTRIES = { '&' => '&amp;', '<' => '&lt;', '>' => '&gt;' }
31
-
31
+
32
32
  # Escape HTML entries (<, >, &). Copy from HAML helper.
33
33
  def self.escape_html(content)
34
34
  content.to_s.gsub(/[><&]/) { |s| HTML_ENTRIES[s] }
@@ -44,7 +44,7 @@ module R18n
44
44
  end
45
45
  result
46
46
  end
47
-
47
+
48
48
  # Recursively hash merge.
49
49
  def self.deep_merge!(a, b)
50
50
  b.each_pair do |key, value|
@@ -57,7 +57,7 @@ module R18n
57
57
  end
58
58
  a
59
59
  end
60
-
60
+
61
61
  # Call +block+ with Syck yamler. It used to load RedCloth, which isn’t
62
62
  # support Psych.
63
63
  def self.use_syck(&block)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module R18n
3
- VERSION = '0.4.10'.freeze unless defined? R18n::VERSION
3
+ VERSION = '0.4.11'.freeze unless defined? R18n::VERSION
4
4
  end
@@ -26,34 +26,36 @@ module R18n
26
26
  # Loader for translations in YAML format. Them should have name like
27
27
  # +en.yml+ (English) or en-US.yml (USA English dialect) with
28
28
  # language/country code (RFC 3066).
29
- #
29
+ #
30
30
  # R18n::I18n.new('en', R18n::Loader::YAML.new('dir/with/translations'))
31
- #
31
+ #
32
32
  # YAML loader is default loader, so you can just set constructor parameter
33
33
  # to <tt>R18n::I18n.new</tt>:
34
- #
34
+ #
35
35
  # R18n::I18n.new('en', 'dir/with/translations')
36
36
  class YAML
37
37
  # Dir with translations.
38
38
  attr_reader :dir
39
-
39
+
40
40
  # Create new loader for +dir+ with YAML translations.
41
41
  def initialize(dir)
42
42
  @dir = File.expand_path(dir)
43
- @private_type_class = if '1.8.' == RUBY_VERSION[0..3]
43
+ @private_type_class = if defined?(JRUBY_VERSION)
44
+ ::YAML::Yecht::PrivateType
45
+ elsif '1.8.' == RUBY_VERSION[0..3]
44
46
  ::YAML::PrivateType
45
47
  else
46
48
  ::Syck::PrivateType
47
49
  end
48
50
  end
49
-
51
+
50
52
  # Array of locales, which has translations in +dir+.
51
53
  def available
52
54
  Dir.glob(File.join(@dir, '**/*.yml')).
53
55
  map { |i| File.basename(i, '.yml') }.uniq.
54
56
  map { |i| R18n::Locale.load(i) }
55
57
  end
56
-
58
+
57
59
  # Return Hash with translations for +locale+.
58
60
  def load(locale)
59
61
  if '1.8.' != RUBY_VERSION[0..3] and 'psych' == ::YAML::ENGINE.yamler
@@ -66,24 +68,24 @@ module R18n
66
68
  end
67
69
  end
68
70
  end
69
-
71
+
70
72
  translations = {}
71
73
  Dir.glob(File.join(@dir, "**/#{locale.code.downcase}.yml")).each do |file_name|
72
74
  Utils.deep_merge!(translations, ::YAML::load_file(file_name) || {})
73
75
  end
74
76
  transform(translations)
75
77
  end
76
-
78
+
77
79
  # YAML loader with same +dir+ will be have same +hash+.
78
80
  def hash
79
81
  self.class.hash + @dir.hash
80
82
  end
81
-
83
+
82
84
  # Is another +loader+ load YAML translations from same +dir+.
83
85
  def ==(loader)
84
86
  self.class == loader.class and self.dir == loader.dir
85
87
  end
86
-
88
+
87
89
  # Wrap YAML private types to Typed.
88
90
  def transform(a_hash)
89
91
  R18n::Utils.hash_map(a_hash) do |key, value|
data/locales/bg.rb CHANGED
@@ -2,18 +2,18 @@
2
2
  module R18n
3
3
  class Locales::Bg < Locale
4
4
  set :title => 'Български',
5
-
5
+
6
6
  :wday_names => %w{Неделя Понеделник Вторник Сряда Четвъртък Петък
7
7
  Събота},
8
8
  :wday_abbrs => %w{Нед Пон Вто Сря Чет Пет Съб},
9
-
9
+
10
10
  :month_names => %w{Януари Февруари Март Април Май Юни Юли Август
11
11
  Септември Октомври Ноември Декември},
12
12
  :month_abbrs => %w{Яну Фев Мар Апр Май Юни Юли Авг Сеп Окт Ное Дек},
13
13
  :month_standalone => %w{Януари Февруари Март Април Май Юни Юли Август
14
14
  Септември Октомври Ноември Декември},
15
15
  :date_format => '%d.%m.%Y',
16
-
16
+
17
17
  :number_decimal => ",",
18
18
  :number_group => " "
19
19
  end
data/locales/ca.rb CHANGED
@@ -2,18 +2,19 @@
2
2
  module R18n
3
3
  class Locales::Ca < Locale
4
4
  set :title => 'Català',
5
-
6
- :wday_names => %w{diumenge dilluns dimarts dimecres dijous divendres dissabte},
5
+
6
+ :wday_names => %w{diumenge dilluns dimarts dimecres dijous divendres
7
+ dissabte},
7
8
  :wday_abbrs => %w{dg dl dm dc dj dv ds},
8
-
9
+
9
10
  :month_names => %w{Gener Febrer Març Abril Maig Juny Juliol Agost
10
11
  Setembre Octubre Novembre Desembre},
11
12
  :month_abbrs => %w{gen feb mar abr mai jun jul ago set oct nov des},
12
-
13
+
13
14
  :date_format => '%d/%m/%Y',
14
15
  :full_format => '%d de %B',
15
16
  :year_format => '_ de %Y',
16
-
17
+
17
18
  :number_decimal => ",",
18
19
  :number_group => "."
19
20
  end
data/locales/cs.rb CHANGED
@@ -3,24 +3,24 @@ module R18n
3
3
  class Locales::Cs < Locale
4
4
  set :title => 'Český',
5
5
  :sublocales => %w{cz sk en},
6
-
6
+
7
7
  :wday_names => %w{Neděle Pondělí Úterý Středa Čtvrtek Pátek Sobota},
8
8
  :wday_abbrs => %w{Ne Po Út St Čt Pá So},
9
-
9
+
10
10
  :month_names => %w{ledna února března dubna května června července srpna
11
11
  září října listopadu prosince},
12
12
  :month_abbrs => %w{led úno bře dub kvě čer čvc srp zář říj lis pro},
13
13
  :month_standalone => %w{Leden Únor Březen Duben Květen Červen Červenec
14
14
  Srpen Září Říjen Listopad Prosinec},
15
-
15
+
16
16
  :time_am => 'dop.',
17
17
  :time_pm => 'odp.',
18
18
  :date_format => '%e. %m. %Y',
19
19
  :full_format => '%e. %B',
20
-
20
+
21
21
  :number_decimal => ",",
22
22
  :number_group => " "
23
-
23
+
24
24
  def pluralize(n)
25
25
  case n
26
26
  when 0
data/locales/da.rb CHANGED
@@ -2,21 +2,21 @@
2
2
  module R18n
3
3
  class Locales::Da < Locale
4
4
  set :title => 'Dansk',
5
-
5
+
6
6
  :wday_names => %w{søndag mandag tirsdag onsdag torsdag fredag
7
7
  lørdag},
8
8
  :wday_abbrs => %w{søn man tir ons tor fre lør},
9
-
9
+
10
10
  :month_names => %w{januar februar marts april Maj juni juli august
11
11
  september oktober november december},
12
12
  :month_abbrs => %w{jan. feb. mar. apr. maj jun. jul. aug. sep. okt.
13
13
  nov. dec.},
14
-
14
+
15
15
  :time_am => 'om formiddagen',
16
16
  :time_pm => 'om eftermiddagen',
17
17
  :date_format => '%d.%m.%Y',
18
18
  :full_format => '%d. %B %Y',
19
-
19
+
20
20
  :number_decimal => ",",
21
21
  :number_group => "."
22
22
  end
data/locales/de.rb CHANGED
@@ -2,21 +2,21 @@
2
2
  module R18n
3
3
  class Locales::De < Locale
4
4
  set :title => 'Deutsch',
5
-
5
+
6
6
  :wday_names => %w{Sonntag Montag Dienstag Mittwoch Donnerstag Freitag
7
7
  Samstag},
8
8
  :wday_abbrs => %w{So Mo Di Mi Do Fr Sa},
9
-
9
+
10
10
  :month_names => %w{Januar Februar März April Mai Juni Juli August
11
11
  September Oktober November Dezember},
12
12
  :month_abbrs => %w{Jan. Feb. Mär. Apr. Mai. Jun. Jul. Aug. Sep. Okt.
13
13
  Nov. Dez.},
14
-
14
+
15
15
  :time_am => 'vormittags',
16
16
  :time_pm => 'nachmittags',
17
17
  :date_format => '%d.%m.%Y',
18
18
  :full_format => '%e. %B',
19
-
19
+
20
20
  :number_decimal => ",",
21
21
  :number_group => "."
22
22
  end