r18n-core 1.1.0 → 1.1.1

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.
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ == 1.1.1 (Dunhuang)
2
+ * Don’t change YAML parser in Ruby 1.9.
3
+ * Allow to change locale by argument in R18n Rails backend.
4
+ * Set also Rails I18n locale in Rails autodetect filter.
5
+ * Fix caching with custom filters (by Anton Onyshchenko).
6
+ * Fix translation variables with “%1” text inside (by Taras Kunch).
7
+ * Fix Latvian locale (by Aleksandrs Ļedovskis).
8
+
1
9
  == 1.1.0 (Leipzig)
2
10
  * A lot of fixes in Rails I18n compatibility (thanks for Stephan Schubert).
3
11
  * Return Untranslted, when user try to call another translation key on
data/base/lv.yml CHANGED
@@ -8,24 +8,24 @@ delete: 'Dzēst'
8
8
 
9
9
  human_time:
10
10
  after_days: !!pl
11
- 1: 'nākamajā dienā'
11
+ 1: 'pēc %1 dienas'
12
12
  n: 'pēc %1 dienām'
13
13
  tomorrow: 'rīt'
14
14
  after_hours: !!pl
15
- 1: 'nākamajā stundā'
16
- n: 'pēc %1 stundas'
15
+ 1: 'pēc %1 stundas'
16
+ n: 'pēc %1 stundām'
17
17
  after_minutes: !!pl
18
- 1: 'nākamajā minūtē'
18
+ 1: 'pēc %1 minūtes'
19
19
  n: 'pēc %1 minūtēm'
20
20
  now: 'tagad'
21
21
  today: 'šodien'
22
22
  minutes_ago: !!pl
23
- 1: 'pirms minūtes'
23
+ 1: 'pirms %1 minūtes'
24
24
  n: 'pirms %1 minūtēm'
25
25
  hours_ago: !!pl
26
- 1: 'pirms stundas'
26
+ 1: 'pirms %1 stundas'
27
27
  n: 'pirms %1 stundām'
28
28
  yesterday: 'vakar'
29
29
  days_ago: !!pl
30
- 1: 'pirms vienas dienas'
31
- n: 'pirms %1 stundām'
30
+ 1: 'pirms %1 dienas'
31
+ n: 'pirms %1 dienām'
@@ -153,5 +153,8 @@ module R18n
153
153
  enabled += @on_by_type[type]
154
154
  end
155
155
 
156
+ def hash
157
+ [@on, @off].hash
158
+ end
156
159
  end
157
160
  end
@@ -230,13 +230,19 @@ module R18n
230
230
  end
231
231
 
232
232
  Filters.add(String, :variables) do |content, config, *params|
233
+ cached_params = []
233
234
  content = content.clone
234
- params.each_with_index do |param, i|
235
- param = config[:locale].localize(param)
236
- if defined? ActiveSupport::SafeBuffer
237
- param = ActiveSupport::SafeBuffer.new + param
235
+ content.gsub!(/\%\d/) do |key|
236
+ i = key[1..-1].to_i
237
+ unless cached_params.include? i - 1
238
+ param = config[:locale].localize(params[i - 1])
239
+ if defined? ActiveSupport::SafeBuffer
240
+ param = ActiveSupport::SafeBuffer.new + param
241
+ end
242
+
243
+ cached_params[i - 1] = param
238
244
  end
239
- content.gsub! "%#{i+1}", param
245
+ cached_params[i - 1]
240
246
  end
241
247
  content
242
248
  end
@@ -18,8 +18,6 @@ You should have received a copy of the GNU Lesser General Public License
18
18
  along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  =end
20
20
 
21
- require 'singleton'
22
-
23
21
  module R18n
24
22
  # Return if translation isn’t exists. Unlike nil, it didn’t raise error when
25
23
  # you try to access for subtranslations.
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module R18n
3
- VERSION = '1.1.0'.freeze unless defined? R18n::VERSION
3
+ VERSION = '1.1.1'.freeze unless defined? R18n::VERSION
4
4
  end
@@ -18,9 +18,6 @@ You should have received a copy of the GNU Lesser General Public License
18
18
  along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  =end
20
20
 
21
- require 'yaml'
22
- require 'syck' if '1.8.' != RUBY_VERSION[0..3] and RUBY_PLATFORM != 'java'
23
-
24
21
  module R18n
25
22
  module Loader
26
23
  # Loader for translations in YAML format. Them should have name like
@@ -34,19 +31,15 @@ module R18n
34
31
  #
35
32
  # R18n::I18n.new('en', 'dir/with/translations')
36
33
  class YAML
34
+ include ::R18n::YamlMethods
35
+
37
36
  # Dir with translations.
38
37
  attr_reader :dir
39
38
 
40
39
  # Create new loader for +dir+ with YAML translations.
41
40
  def initialize(dir)
42
41
  @dir = File.expand_path(dir)
43
- @private_type_class = if defined?(JRUBY_VERSION)
44
- ::YAML::Yecht::PrivateType
45
- elsif '1.8.' == RUBY_VERSION[0..3]
46
- ::YAML::PrivateType
47
- else
48
- ::Syck::PrivateType
49
- end
42
+ detect_yaml_private_type
50
43
  end
51
44
 
52
45
  # Array of locales, which has translations in +dir+.
@@ -58,16 +51,7 @@ module R18n
58
51
 
59
52
  # Return Hash with translations for +locale+.
60
53
  def load(locale)
61
- if '1.8.' != RUBY_VERSION[0..3] and 'psych' == ::YAML::ENGINE.yamler
62
- Filters.by_type.keys.each do |type|
63
- next unless type.is_a? String
64
- # Yeah, I add R18n’s types to global, send me patch if you really
65
- # use YAML types too ;).
66
- Psych.add_domain_type('yaml.org,2002', type) do |full_type, value|
67
- Typed.new(type, value)
68
- end
69
- end
70
- end
54
+ initialize_types
71
55
 
72
56
  translations = {}
73
57
  Dir.glob(File.join(@dir, "**/#{locale.code.downcase}.yml")).each do |i|
@@ -89,17 +73,14 @@ module R18n
89
73
  # Wrap YAML private types to Typed.
90
74
  def transform(a_hash)
91
75
  R18n::Utils.hash_map(a_hash) do |key, value|
92
- value = case value
93
- when @private_type_class
76
+ if value.is_a? Hash
77
+ value = transform(value)
78
+ elsif @private_type_class and value.is_a? @private_type_class
94
79
  v = value.value
95
80
  if v.respond_to?(:force_encoding) and v.encoding != __ENCODING__
96
81
  v = v.force_encoding(__ENCODING__)
97
82
  end
98
- Typed.new(value.type_id, v)
99
- when Hash
100
- transform(value)
101
- else
102
- value
83
+ value = Typed.new(value.type_id, v)
103
84
  end
104
85
  [key, value]
105
86
  end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ =begin
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
+ =end
20
+
21
+ require 'yaml'
22
+ require 'yecht' if RUBY_PLATFORM == 'java'
23
+
24
+ module R18n
25
+ # Base methods to load translations for YAML.
26
+ # It is used by YAML and Rails loaders.
27
+ module YamlMethods
28
+ # Detect class for private type depend on YAML parser.
29
+ def detect_yaml_private_type
30
+ @private_type_class = if defined?(JRUBY_VERSION)
31
+ ::YAML::Yecht::PrivateType
32
+ elsif '1.8.' == RUBY_VERSION[0..3]
33
+ ::YAML::PrivateType
34
+ elsif 'syck' == ::YAML::ENGINE.yamler
35
+ ::Syck::PrivateType
36
+ end
37
+ end
38
+
39
+ # Register global types in Psych
40
+ def initialize_types
41
+ if '1.8.' != RUBY_VERSION[0..3] and 'psych' == ::YAML::ENGINE.yamler
42
+ Filters.by_type.keys.each do |type|
43
+ next unless type.is_a? String
44
+ # Yeah, I add R18n’s types to global, send me patch if you really
45
+ # use YAML types too ;).
46
+ Psych.add_domain_type('yaml.org,2002', type) do |full_type, value|
47
+ Typed.new(type, value)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end
data/lib/r18n-core.rb CHANGED
@@ -32,12 +32,11 @@ require dir.join('untranslated').to_s
32
32
  require dir.join('translation').to_s
33
33
  require dir.join('filters').to_s
34
34
  require dir.join('filter_list').to_s
35
+ require dir.join('yaml_methods').to_s
35
36
  require dir.join('yaml_loader').to_s
36
37
  require dir.join('i18n').to_s
37
38
  require dir.join('helpers').to_s
38
39
 
39
- require 'yecht' if RUBY_PLATFORM == 'java'
40
-
41
40
  module R18n
42
41
  autoload :Translated, 'r18n-core/translated'
43
42
 
data/locales/lv.rb CHANGED
@@ -3,19 +3,21 @@ module R18n
3
3
  class Locales::Lv < Locale
4
4
  set :title => 'Latviešu',
5
5
 
6
+ :week_start => :monday,
6
7
  :wday_names => %w{Svētdiena Pirmdiena Otrdiena Trešdiena Ceturtdiena
7
- Piektiena Sestdiena},
8
+ Piektdiena Sestdiena},
8
9
  :wday_abbrs => %w{Sv P O T C P S},
9
10
 
10
- :month_names => %w{janvāris februāris marts aprīlis maijs jūnijs jūlijs
11
- augusts septembris oktobris novembris decembris},
11
+ :month_names => %w{janvārī februārī martā aprīlī maijā jūnijā jūlijā
12
+ augustā septembrī oktobrī novembrī decembrī},
12
13
  :month_abbrs => %w{jan feb mar apr mai jūn jūl aug sep okt nov dec},
13
- :month_standalone => %w{Janvāris Februāris Marts Aprīlis Maijs Jūnijs
14
- Jūlijs Augusts Septembris Oktobris Novembris
15
- Decembris},
14
+ :month_standalone => %w{janvāris februāris marts aprīlis maijs jūnijs
15
+ jūlijs augusts septembris oktobris novembris
16
+ decembris},
16
17
 
17
- :date_format => '%d.%m.%Y',
18
- :year_format => '_, %Y',
18
+ :date_format => '%d.%m.%Y.',
19
+ :full_format => '%e.%B',
20
+ :year_format => '%Y.gada _',
19
21
 
20
22
  :number_decimal => ",",
21
23
  :number_group => " "
data/spec/filters_spec.rb CHANGED
@@ -173,6 +173,10 @@ describe R18n::Filters do
173
173
  @i18n.params(-1, 2).should == 'Is −1 between −1 and 2?'
174
174
  end
175
175
 
176
+ it "should substitute '%2' as param but not value of second param" do
177
+ @i18n.params('%2 FIRST', 'SECOND').should == 'Is %2 FIRST between %2 FIRST and SECOND?'
178
+ end
179
+
176
180
  it "should format untranslated" do
177
181
  @i18n.in.not.to_s.should == 'in.[not]'
178
182
  @i18n.in.not.to_str.should == 'in.[not]'
data/spec/i18n_spec.rb CHANGED
@@ -130,6 +130,16 @@ describe R18n::I18n do
130
130
  counter.loaded.should == 2
131
131
  end
132
132
 
133
+ it "shouldn't clear cache when custom filters are specified" do
134
+ counter = CounterLoader.new('en')
135
+
136
+ R18n::I18n.new('en', counter, :off_filters => :untranslated, :on_filters => :untranslated_html)
137
+ counter.loaded.should == 1
138
+
139
+ R18n::I18n.new('en', counter, :off_filters => :untranslated, :on_filters => :untranslated_html)
140
+ counter.loaded.should == 1
141
+ end
142
+
133
143
  it "should cache translations by used locales" do
134
144
  counter = CounterLoader.new('en', 'ru')
135
145
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r18n-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-15 00:00:00.000000000 Z
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -222,6 +222,7 @@ files:
222
222
  - lib/r18n-core/utils.rb
223
223
  - lib/r18n-core/version.rb
224
224
  - lib/r18n-core/yaml_loader.rb
225
+ - lib/r18n-core/yaml_methods.rb
225
226
  - locales/bg.rb
226
227
  - locales/ca.rb
227
228
  - locales/cs.rb
@@ -297,7 +298,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
297
298
  version: '0'
298
299
  segments:
299
300
  - 0
300
- hash: 1266686224539252765
301
+ hash: 1126722854268271207
301
302
  required_rubygems_version: !ruby/object:Gem::Requirement
302
303
  none: false
303
304
  requirements:
@@ -306,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
307
  version: '0'
307
308
  segments:
308
309
  - 0
309
- hash: 1266686224539252765
310
+ hash: 1126722854268271207
310
311
  requirements: []
311
312
  rubyforge_project:
312
313
  rubygems_version: 1.8.23