r18n-core 1.1.1 → 1.1.2

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,8 @@
1
+ == 1.1.2 (Marshal)
2
+ * Fix translation and untranslated marshalizing (by silentshade).
3
+ * Allow to compare untranslated strings.
4
+ * Fix untranslated strings output in tests.
5
+
1
6
  == 1.1.1 (Dunhuang)
2
7
  * Don’t change YAML parser in Ruby 1.9.
3
8
  * Allow to change locale by argument in R18n Rails backend.
@@ -60,6 +60,17 @@ module R18n
60
60
  end
61
61
  end
62
62
 
63
+ # Override marshal_dump to avoid Marshalizing filter procs
64
+ def _dump(limit)
65
+ [@locale.code, @path, to_str].join(":")
66
+ end
67
+
68
+ # Load object from Marshalizing.
69
+ def self._load(str)
70
+ arr = str.split(":", 3)
71
+ new arr[2], R18n.locale(arr[0]), arr[1]
72
+ end
73
+
63
74
  # Return untranslated for deeper node `key`. It is in separated methods to
64
75
  # be used in R18n I18n backend.
65
76
  def get_untranslated(key)
@@ -44,6 +44,9 @@ module R18n
44
44
  # Path, that exists in translation.
45
45
  attr_reader :translated_path
46
46
 
47
+ # Main locale, where string was try to find
48
+ attr_reader :locale
49
+
47
50
  def initialize(translated_path, untranslated_path, locale, filters)
48
51
  @translated_path = translated_path
49
52
  @untranslated_path = untranslated_path
@@ -60,8 +63,24 @@ module R18n
60
63
  false
61
64
  end
62
65
 
63
- def method_missing(*params)
64
- self[params.first]
66
+ # Override marshal_dump to avoid Marshalizing filter procs
67
+ def _dump(limit)
68
+ [@locale.code, @translated_path, @untranslated_path].join(":")
69
+ end
70
+
71
+ # Load object from Marshalizing.
72
+ def self._load(str)
73
+ arr = str.split(":", 3)
74
+ new arr[1], arr[2], R18n.locale(arr[0]), GlobalFilterList.instance
75
+ end
76
+
77
+ def method_missing(name, *params)
78
+ # It is need to fix some hack in specs
79
+ if name == :to_ary
80
+ raise NoMethodError, "undefined method `to_ary' for #{to_s}"
81
+ end
82
+
83
+ self[name]
65
84
  end
66
85
 
67
86
  def [](*params)
@@ -79,5 +98,14 @@ module R18n
79
98
  end
80
99
 
81
100
  alias :to_str :to_s
101
+
102
+ # Is another locale has same code.
103
+ def ==(untrsl)
104
+ return false unless untrsl.is_a? Untranslated
105
+ return false unless locale == untrsl.locale
106
+ return false unless translated_path == untrsl.translated_path
107
+ return false unless untranslated_path == untrsl.untranslated_path
108
+ true
109
+ end
82
110
  end
83
111
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module R18n
3
- VERSION = '1.1.1'.freeze unless defined? R18n::VERSION
3
+ VERSION = '1.1.2'.freeze unless defined? R18n::VERSION
4
4
  end
data/spec/i18n_spec.rb CHANGED
@@ -220,4 +220,17 @@ describe R18n::I18n do
220
220
  i18n.l(Date.new(0)).should == '01.01.0000'
221
221
  end
222
222
 
223
+ it "should return marshalizable values", :not_ruby => 1.8 do
224
+ i18n = R18n::I18n.new('en', DIR, :off_filters => :untranslated,
225
+ :on_filters => :untranslated_html)
226
+ demarsh = Marshal.load(Marshal.dump(i18n.t.one))
227
+
228
+ i18n.t.one.should == demarsh
229
+ i18n.t.one.path.should == demarsh.path
230
+ i18n.t.one.locale.should == demarsh.locale
231
+
232
+ demarsh = Marshal.load(Marshal.dump(i18n.t.no_translation))
233
+ i18n.t.no_translation.should == demarsh
234
+ end
235
+
223
236
  end
data/spec/spec_helper.rb CHANGED
@@ -40,3 +40,9 @@ end
40
40
  if '1.8.' != RUBY_VERSION[0..3]
41
41
  YAML::ENGINE.yamler = ENV['test_syck'] ? 'syck' : 'psych'
42
42
  end
43
+
44
+ RSpec.configure do |c|
45
+ c.filter_run_excluding :not_ruby => lambda { |version|
46
+ RUBY_VERSION.to_s.start_with? version.to_s
47
+ }
48
+ end
@@ -8,6 +8,10 @@ describe R18n::Translation do
8
8
  i18n.not.exists.should be_a(R18n::Untranslated)
9
9
  i18n.not.exists.should_not be_translated
10
10
  (i18n.not.exists | 'default').should == 'default'
11
+ i18n.not.exists.locale.should == R18n.locale('en')
12
+
13
+ i18n.not.exists.should == i18n.not.exists
14
+ i18n.not.exists.should_not == i18n.not.exists2
11
15
 
12
16
  (i18n.in | 'default').should == 'default'
13
17
 
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.1
4
+ version: 1.1.2
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-09-11 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -298,7 +298,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
298
  version: '0'
299
299
  segments:
300
300
  - 0
301
- hash: 1126722854268271207
301
+ hash: 631700017419690142
302
302
  required_rubygems_version: !ruby/object:Gem::Requirement
303
303
  none: false
304
304
  requirements:
@@ -307,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  version: '0'
308
308
  segments:
309
309
  - 0
310
- hash: 1126722854268271207
310
+ hash: 631700017419690142
311
311
  requirements: []
312
312
  rubyforge_project:
313
313
  rubygems_version: 1.8.23