r18n-rails-api 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- r18n-rails-api (0.4.10)
4
+ r18n-rails-api (0.4.11)
5
5
  i18n
6
- r18n-core (= 0.4.10)
6
+ r18n-core (= 0.4.11)
7
7
 
8
8
  PATH
9
9
  remote: ../r18n-core/
10
10
  specs:
11
- r18n-core (0.4.10)
11
+ r18n-core (0.4.11)
12
12
 
13
13
  GEM
14
14
  remote: http://rubygems.org/
data/README.rdoc CHANGED
@@ -38,7 +38,7 @@ example.rb:
38
38
 
39
39
  I18n.load_path = ['i18n/en.yml']
40
40
  i18n = R18n::I18n.new('en', R18n::Loader::Rails)
41
-
41
+
42
42
  i18n.posts(:count => 5) #=> "5 posts"
43
43
 
44
44
  === Backend
@@ -49,7 +49,7 @@ You can use R18n as a backend for Rails I18n:
49
49
 
50
50
  R18n.set('en', 'path/to/translation')
51
51
  I18n.backend = R18n::Backend
52
-
52
+
53
53
  I18n.l Time.now, :format => :full #=> "6th of December, 2009 22:44"
54
54
  I18n.t :greeting, :name => 'John' #=> "Hi, John"
55
55
  I18n.t :users, :count => 5 #=> "5 users"
data/Rakefile CHANGED
@@ -3,7 +3,6 @@
3
3
  require 'rubygems'
4
4
 
5
5
  begin
6
- require 'bundler'
7
6
  require 'bundler/setup'
8
7
  Bundler::GemHelper.install_tasks
9
8
  rescue LoadError
@@ -21,27 +21,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21
21
  module R18n
22
22
  # R18n backend for Rails I18n. You must set R18n I18n object before use this
23
23
  # backend:
24
- #
24
+ #
25
25
  # R18n.set locales, R18n::Loader::Rails
26
- #
26
+ #
27
27
  # I18n.l Time.now, :format => :full #=> "6th of December, 2009 22:44"
28
28
  class Backend
29
29
  RESERVED_KEYS = [:scope, :default, :separator]
30
-
30
+
31
31
  # Find translation in R18n. It didn’t use +locale+ argument, only current
32
32
  # R18n I18n object. Also it doesn’t support Proc and variables in +default+
33
33
  # String option.
34
34
  def translate(locale, key, options = {})
35
35
  return key.map { |k| translate(locale, k, options) } if key.is_a?(Array)
36
-
36
+
37
37
  scope, default, separator = options.values_at(*RESERVED_KEYS)
38
38
  params = options.reject { |name, value| RESERVED_KEYS.include?(name) }
39
-
39
+
40
40
  result = lookup(scope, key, separator, params)
41
-
41
+
42
42
  if result.is_a? Untranslated
43
43
  options = options.reject { |key, value| key == :default }
44
-
44
+
45
45
  Array(default).each do |entry|
46
46
  if entry.is_a? Symbol
47
47
  value = lookup(scope, entry, separator, params)
@@ -50,13 +50,13 @@ module R18n
50
50
  return entry
51
51
  end
52
52
  end
53
-
53
+
54
54
  raise ::I18n::MissingTranslationData.new(locale, key, options)
55
55
  else
56
56
  result
57
57
  end
58
58
  end
59
-
59
+
60
60
  # Convert +object+ to String, according to the rules of the current
61
61
  # R18n locale. It didn’t use +locale+ argument, only current R18n I18n
62
62
  # object. It support Fixnum, Bignum, Float, Time, Date and DateTime.
@@ -72,26 +72,26 @@ module R18n
72
72
  end
73
73
  R18n.get.localize(object, format)
74
74
  end
75
-
75
+
76
76
  # Return array of available locales codes.
77
77
  def available_locales
78
78
  R18n.get.available_locales.map { |i| i.code.to_sym }
79
79
  end
80
-
80
+
81
81
  # Reload R18n I18n object.
82
82
  def reload!
83
83
  R18n.get.reload!
84
84
  end
85
-
85
+
86
86
  protected
87
-
87
+
88
88
  # Find translation by <tt>scope.key(params)</tt> in current R18n I18n
89
89
  # object.
90
90
  def lookup(scope, key, separator, params)
91
91
  keys = (Array(scope) + Array(key)).map { |k|
92
92
  k.to_s.split(separator || ::I18n.default_separator) }.flatten
93
93
  last = keys.pop
94
-
94
+
95
95
  result = keys.inject(R18n.get) { |result, key| result[key] }
96
96
  result[last, params]
97
97
  end
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  =end
19
19
 
20
20
  # Filter to use Rails named variables:
21
- #
21
+ #
22
22
  # name: "My name is %{name}"
23
- #
23
+ #
24
24
  # i18n.name(name: 'Ivan') #=> "My name is Ivan"
25
25
  R18n::Filters.add(String, :named_variables) do |content, config, params|
26
26
  if params.is_a? Hash
@@ -23,9 +23,9 @@ require 'i18n'
23
23
  module R18n
24
24
  module Loader
25
25
  # Loader for translations in Rails I18n format:
26
- #
26
+ #
27
27
  # R18n::I18n.new('en', R18n::Loader::Rails.new)
28
- #
28
+ #
29
29
  # It use Rails I18n backend to load translations. By default, simple
30
30
  # backend will be used, by you can change it, if use extended backend
31
31
  # (for example, with ActiveRecord storage):
@@ -35,7 +35,7 @@ module R18n
35
35
  class Rails
36
36
  PLURAL_KEYS = { :zero => 0, :one => 1, :few => 2, :many => 'n',
37
37
  :other => 'other' }
38
-
38
+
39
39
  # Create new loader for some +backend+ from Rails I18n. Backend must have
40
40
  # +reload!+, +init_translations+ and +translations+ methods.
41
41
  def initialize(backend = ::I18n::Backend::Simple.new)
@@ -46,19 +46,19 @@ module R18n
46
46
  ::Syck::PrivateType
47
47
  end
48
48
  end
49
-
49
+
50
50
  # Array of locales, which has translations in +I18n.load_path+.
51
51
  def available
52
52
  reload!
53
53
  @translations.keys.map { |code| R18n::Locale.load(code) }
54
54
  end
55
-
55
+
56
56
  # Return Hash with translations for +locale+.
57
57
  def load(locale)
58
58
  reload!
59
59
  @translations[locale.code.downcase]
60
60
  end
61
-
61
+
62
62
  # Reload backend if <tt>I18n.load_path</tt> is changed.
63
63
  def reload!
64
64
  return if @last_path == ::I18n.load_path
@@ -67,19 +67,19 @@ module R18n
67
67
  @backend.send(:init_translations)
68
68
  @translations = transform @backend.send(:translations)
69
69
  end
70
-
70
+
71
71
  # Return hash for object and <tt>I18n.load_path</tt>.
72
72
  def hash
73
73
  super + ::I18n.load_path.hash
74
74
  end
75
-
75
+
76
76
  # Is another +loader+ is also load Rails translations.
77
77
  def ==(loader)
78
78
  self.class == loader.class
79
79
  end
80
-
80
+
81
81
  protected
82
-
82
+
83
83
  # Change pluralization and keys to R18n format.
84
84
  def transform(value)
85
85
  if value.is_a? Hash
@@ -14,21 +14,20 @@ Gem::Specification.new do |s|
14
14
  user language support, agnostic core package with out-of-box support for
15
15
  Rails, Sinatra, Merb and desktop applications.
16
16
  EOF
17
-
17
+
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
20
  s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
21
21
  s.require_path = 'lib'
22
- s.has_rdoc = true
23
-
22
+
24
23
  s.author = 'Andrey "A.I." Sitnik'
25
24
  s.email = 'andrey@sitnik.ru'
26
25
  s.homepage = 'http://r18n.rubyforge.org/'
27
26
  s.rubyforge_project = 'r18n-rails-api'
28
-
27
+
29
28
  s.add_dependency 'r18n-core', ["= #{R18n::VERSION}"]
30
29
  s.add_dependency 'i18n'
31
-
30
+
32
31
  s.add_development_dependency "bundler", [">= 1.0.10"]
33
32
  s.add_development_dependency "hanna", [">= 0"]
34
33
  s.add_development_dependency "rake", [">= 0", "!= 0.9.0"]
data/spec/backend_spec.rb CHANGED
@@ -7,63 +7,63 @@ describe R18n::Backend do
7
7
  I18n.backend = R18n::Backend.new
8
8
  R18n.set('en', R18n::Loader::Rails.new)
9
9
  end
10
-
10
+
11
11
  it "should return available locales" do
12
12
  I18n.available_locales.should =~ [:en]
13
13
  end
14
-
14
+
15
15
  it "should localize objects" do
16
16
  time = Time.at(0).utc
17
17
  date = Date.parse('1970-01-01')
18
-
18
+
19
19
  I18n.l(time).should == 'Thu, 01 Jan 1970 00:00:00 +0000'
20
20
  I18n.l(date).should == '1970-01-01'
21
-
21
+
22
22
  I18n.l(time, :format => :short).should == '01 Jan 00:00'
23
23
  I18n.l(time, :format => :full).should == '1st of January, 1970 00:00'
24
-
24
+
25
25
  I18n.l(-5000.5).should == '−5,000.5'
26
26
  end
27
-
27
+
28
28
  it "should translate by key and scope" do
29
29
  I18n.t('in.another.level').should == 'Hierarchical'
30
30
  I18n.t(:level, :scope => 'in.another').should == 'Hierarchical'
31
31
  I18n.t(:'another.level', :scope => 'in').should == 'Hierarchical'
32
32
  end
33
-
33
+
34
34
  it "should use pluralization and variables" do
35
35
  I18n.t(:users, :count => 0).should == '0 users'
36
36
  I18n.t(:users, :count => 1).should == '1 user'
37
37
  I18n.t(:users, :count => 5).should == '5 users'
38
38
  end
39
-
39
+
40
40
  it "should use another separator" do
41
41
  I18n.t('in/another/level', :separator => '/').should == 'Hierarchical'
42
42
  end
43
-
43
+
44
44
  it "should translate array" do
45
45
  I18n.t(['in.another.level', 'in.default']).should == ['Hierarchical',
46
46
  'Default']
47
47
  end
48
-
48
+
49
49
  it "should use default value" do
50
50
  I18n.t(:missed, :default => 'Default').should == 'Default'
51
51
  I18n.t(:missed, :default => :default, :scope => :in).should == 'Default'
52
52
  I18n.t(:missed, :default => [:also_no, :'in.default']).should == 'Default'
53
53
  end
54
-
54
+
55
55
  it "should raise error on no translation" do
56
56
  lambda {
57
57
  I18n.backend.translate(:en, :missed)
58
58
  }.should raise_error(::I18n::MissingTranslationData)
59
59
  I18n.t(:missed).should == 'translation missing: en.missed'
60
60
  end
61
-
61
+
62
62
  it "should reload translations" do
63
63
  I18n.t(:other).should == 'translation missing: en.other'
64
64
  I18n.load_path << OTHER
65
65
  I18n.reload!
66
66
  I18n.t(:other).should == 'Other'
67
67
  end
68
-
68
+
69
69
  end
data/spec/filters_spec.rb CHANGED
@@ -5,29 +5,29 @@ describe 'Rails filters' do
5
5
  before :all do
6
6
  @en = R18n::Locale.load('en')
7
7
  end
8
-
8
+
9
9
  it "should use named variables" do
10
10
  i18n = R18n::Translation.new(@en, '', @en, {'echo' => 'Value is %{value}'})
11
-
11
+
12
12
  i18n.echo(:value => 'R18n').should == 'Value is R18n'
13
13
  i18n.echo(:value => -5.5).should == 'Value is −5.5'
14
14
  i18n.echo(:value => 5000).should == 'Value is 5,000'
15
15
  i18n.echo.should == 'Value is %{value}'
16
16
  end
17
-
17
+
18
18
  it "should use old variables syntax" do
19
19
  i18n = R18n::Translation.new(@en, '', @en, {'echo' => 'Value is {{value}}',})
20
20
  i18n.echo(:value => 'Old').should == 'Value is Old'
21
21
  end
22
-
22
+
23
23
  it "should pluralize by variable %{count}" do
24
24
  i18n = R18n::Translation.new(@en, '', @en, {'users' => R18n::Typed.new('pl',
25
25
  { 0 => 'no users', 1 => '1 user', 'n' => '%{count} users' }
26
26
  ) })
27
-
27
+
28
28
  i18n.users(:count => 0).should == 'no users'
29
29
  i18n.users(:count => 1).should == '1 user'
30
30
  i18n.users(:count => 5).should == '5 users'
31
31
  end
32
-
32
+
33
33
  end
data/spec/loader_spec.rb CHANGED
@@ -6,15 +6,15 @@ describe R18n::Loader::Rails do
6
6
  I18n.load_path = [SIMPLE]
7
7
  @loader = R18n::Loader::Rails.new
8
8
  end
9
-
9
+
10
10
  it "should return available locales" do
11
11
  @loader.available.should =~ [EN, RU]
12
12
  end
13
-
13
+
14
14
  it "should load translation" do
15
15
  @loader.load(RU).should == { 'one' => 'Один', 'two' => 'Два' }
16
16
  end
17
-
17
+
18
18
  it "should change pluralization" do
19
19
  @loader.load(EN).should == {
20
20
  'users' => R18n::Typed.new('pl', {
@@ -22,17 +22,17 @@ describe R18n::Loader::Rails do
22
22
  })
23
23
  }
24
24
  end
25
-
25
+
26
26
  it "should reload translations on load_path changes" do
27
27
  I18n.load_path << OTHER
28
28
  @loader.load(RU).should == { 'one' => 'Один', 'two' => 'Два',
29
29
  'three' => 'Три' }
30
30
  end
31
-
31
+
32
32
  it "should change hash on load_path changes" do
33
33
  before = @loader.hash
34
34
  I18n.load_path << OTHER
35
35
  @loader.hash.should_not == before
36
36
  end
37
-
37
+
38
38
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r18n-rails-api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 25
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 10
10
- version: 0.4.10
9
+ - 11
10
+ version: 0.4.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrey "A.I." Sitnik
@@ -15,26 +15,27 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-08 00:00:00 +04:00
19
- default_executable:
18
+ date: 2011-10-02 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ name: r18n-core
22
23
  prerelease: false
23
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
28
- hash: 27
29
+ hash: 25
29
30
  segments:
30
31
  - 0
31
32
  - 4
32
- - 10
33
- version: 0.4.10
33
+ - 11
34
+ version: 0.4.11
34
35
  requirement: *id001
35
- type: :runtime
36
- name: r18n-core
37
36
  - !ruby/object:Gem::Dependency
37
+ type: :runtime
38
+ name: i18n
38
39
  prerelease: false
39
40
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
@@ -46,9 +47,9 @@ dependencies:
46
47
  - 0
47
48
  version: "0"
48
49
  requirement: *id002
49
- type: :runtime
50
- name: i18n
51
50
  - !ruby/object:Gem::Dependency
51
+ type: :development
52
+ name: bundler
52
53
  prerelease: false
53
54
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
55
  none: false
@@ -62,9 +63,9 @@ dependencies:
62
63
  - 10
63
64
  version: 1.0.10
64
65
  requirement: *id003
65
- type: :development
66
- name: bundler
67
66
  - !ruby/object:Gem::Dependency
67
+ type: :development
68
+ name: hanna
68
69
  prerelease: false
69
70
  version_requirements: &id004 !ruby/object:Gem::Requirement
70
71
  none: false
@@ -76,9 +77,9 @@ dependencies:
76
77
  - 0
77
78
  version: "0"
78
79
  requirement: *id004
79
- type: :development
80
- name: hanna
81
80
  - !ruby/object:Gem::Dependency
81
+ type: :development
82
+ name: rake
82
83
  prerelease: false
83
84
  version_requirements: &id005 !ruby/object:Gem::Requirement
84
85
  none: false
@@ -98,9 +99,9 @@ dependencies:
98
99
  - 0
99
100
  version: 0.9.0
100
101
  requirement: *id005
101
- type: :development
102
- name: rake
103
102
  - !ruby/object:Gem::Dependency
103
+ type: :development
104
+ name: rspec-core
104
105
  prerelease: false
105
106
  version_requirements: &id006 !ruby/object:Gem::Requirement
106
107
  none: false
@@ -112,9 +113,9 @@ dependencies:
112
113
  - 0
113
114
  version: "0"
114
115
  requirement: *id006
115
- type: :development
116
- name: rspec-core
117
116
  - !ruby/object:Gem::Dependency
117
+ type: :development
118
+ name: rspec-expectations
118
119
  prerelease: false
119
120
  version_requirements: &id007 !ruby/object:Gem::Requirement
120
121
  none: false
@@ -126,9 +127,9 @@ dependencies:
126
127
  - 0
127
128
  version: "0"
128
129
  requirement: *id007
129
- type: :development
130
- name: rspec-expectations
131
130
  - !ruby/object:Gem::Dependency
131
+ type: :development
132
+ name: rspec-mocks
132
133
  prerelease: false
133
134
  version_requirements: &id008 !ruby/object:Gem::Requirement
134
135
  none: false
@@ -140,9 +141,9 @@ dependencies:
140
141
  - 0
141
142
  version: "0"
142
143
  requirement: *id008
143
- type: :development
144
- name: rspec-mocks
145
144
  - !ruby/object:Gem::Dependency
145
+ type: :development
146
+ name: rcov
146
147
  prerelease: false
147
148
  version_requirements: &id009 !ruby/object:Gem::Requirement
148
149
  none: false
@@ -154,8 +155,6 @@ dependencies:
154
155
  - 0
155
156
  version: "0"
156
157
  requirement: *id009
157
- type: :development
158
- name: rcov
159
158
  description: " R18n backend for Rails I18n and R18n filters and loader to support Rails\n translation format.\n R18n has nice Ruby-style syntax, filters, flexible locales, custom loaders,\n translation support for any classes, time and number localization, several\n user language support, agnostic core package with out-of-box support for\n Rails, Sinatra, Merb and desktop applications.\n"
160
159
  email: andrey@sitnik.ru
161
160
  executables: []
@@ -187,7 +186,6 @@ files:
187
186
  - spec/filters_spec.rb
188
187
  - spec/loader_spec.rb
189
188
  - spec/spec_helper.rb
190
- has_rdoc: true
191
189
  homepage: http://r18n.rubyforge.org/
192
190
  licenses: []
193
191
 
@@ -217,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
215
  requirements: []
218
216
 
219
217
  rubyforge_project: r18n-rails-api
220
- rubygems_version: 1.3.7
218
+ rubygems_version: 1.7.2
221
219
  signing_key:
222
220
  specification_version: 3
223
221
  summary: Rails I18n compatibility for R18n