redis-i18n 0.0.0 → 0.6.0.rc

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ tmp/*
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
  gemspec
3
+
4
+ gem 'redis-store', '1.1.0.rc', :path => File.expand_path('../../redis-store', __FILE__)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 - 2011 Luca Guidi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Redis stores for I18n
2
+
3
+ __`redis-i18n`__ provides a Redis backend for __I18n__. It natively supports object marshalling, timeouts, single or multiple nodes and namespaces.
4
+
5
+ ## Redis Installation
6
+
7
+ ### Option 1: Homebrew
8
+
9
+ MacOS X users should use [Homebrew](https://github.com/mxcl/homebrew) to install Redis:
10
+
11
+ brew install redis
12
+
13
+ ### Option 2: From Source
14
+
15
+ Download and install Redis from [http://redis.io](http://redis.io/)
16
+
17
+ wget http://redis.googlecode.com/files/redis-2.4.5.tar.gz
18
+ tar -zxf redis-2.4.5.tar.gz
19
+ mv redis-2.4.5 redis
20
+ cd redis
21
+ make
22
+
23
+ ## Usage
24
+
25
+ # Gemfile
26
+ gem 'redis-i18n'
27
+
28
+ ### Backend:
29
+
30
+ I18n.backend = I18n::Backend::Redis.new
31
+
32
+ #### Configuration
33
+
34
+ For advanced configuration options, please check the [Redis Store Wiki](https://github.com/jodosha/redis-store/wiki).
35
+
36
+ ## Running tests
37
+
38
+ git clone git://github.com/jodosha/redis-store.git
39
+ cd redis-store/redis-i18n
40
+ gem install bundler --pre # required version: 1.1.rc
41
+ bundle exec rake
42
+
43
+ If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle exec rake`
44
+
45
+ ## Copyright
46
+
47
+ (c) 2009 - 2011 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
data/Rakefile CHANGED
@@ -1 +1,14 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler'
2
+ Bundler.setup
3
+ require 'rake'
4
+ require 'bundler/gem_tasks'
5
+
6
+ begin
7
+ require 'rdoc/task'
8
+ rescue LoadError
9
+ require 'rake/rdoctask'
10
+ end
11
+
12
+ load 'tasks/redis.tasks.rb'
13
+ task :default => 'redis:test:suite'
14
+
@@ -0,0 +1,70 @@
1
+ require 'redis-store'
2
+
3
+ module I18n
4
+ module Backend
5
+ class Redis
6
+ include Base, Flatten
7
+ attr_accessor :store
8
+
9
+ # Instantiate the store.
10
+ #
11
+ # Example:
12
+ # RedisStore.new
13
+ # # => host: localhost, port: 6379, db: 0
14
+ #
15
+ # RedisStore.new "example.com"
16
+ # # => host: example.com, port: 6379, db: 0
17
+ #
18
+ # RedisStore.new "example.com:23682"
19
+ # # => host: example.com, port: 23682, db: 0
20
+ #
21
+ # RedisStore.new "example.com:23682/1"
22
+ # # => host: example.com, port: 23682, db: 1
23
+ #
24
+ # RedisStore.new "example.com:23682/1/theplaylist"
25
+ # # => host: example.com, port: 23682, db: 1, namespace: theplaylist
26
+ #
27
+ # RedisStore.new "localhost:6379/0", "localhost:6380/0"
28
+ # # => instantiate a cluster
29
+ def initialize(*addresses)
30
+ @store = ::Redis::Factory.create(addresses)
31
+ end
32
+
33
+ def translate(locale, key, options = {})
34
+ options[:resolve] ||= false
35
+ super locale, key, options
36
+ end
37
+
38
+ def store_translations(locale, data, options = {})
39
+ escape = options.fetch(:escape, true)
40
+ flatten_translations(locale, data, escape, false).each do |key, value|
41
+ case value
42
+ when Proc
43
+ raise "Key-value stores cannot handle procs"
44
+ else
45
+ @store.set "#{locale}.#{key}", value
46
+ end
47
+ end
48
+ end
49
+
50
+ def available_locales
51
+ locales = @store.keys.map { |k| k =~ /\./; $` }
52
+ locales.uniq!
53
+ locales.compact!
54
+ locales.map! { |k| k.to_sym }
55
+ locales
56
+ end
57
+
58
+ protected
59
+ def lookup(locale, key, scope = [], options = {})
60
+ key = normalize_flat_keys(locale, key, scope, options[:separator])
61
+ @store.get "#{locale}.#{key}"
62
+ end
63
+
64
+ def resolve_link(locale, key)
65
+ key
66
+ end
67
+ end
68
+ end
69
+ end
70
+
@@ -0,0 +1,5 @@
1
+ class Redis
2
+ module I18n
3
+ VERSION = '0.6.0.rc'
4
+ end
5
+ end
data/lib/redis-i18n.rb CHANGED
@@ -1,7 +1,2 @@
1
- require "redis-i18n/version"
2
-
3
- module Redis
4
- module I18n
5
- # Your code goes here...
6
- end
7
- end
1
+ require 'redis/i18n/version'
2
+ require 'i18n/backend/redis'
data/redis-i18n.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "redis-i18n/version"
3
+ require "redis/i18n/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "redis-i18n"
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Luca Guidi"]
9
9
  s.email = ["guidi.luca@gmail.com"]
10
10
  s.homepage = "http://jodosha.github.com/redis-store"
11
- s.summary = %q{Redis for i18n}
12
- s.description = %q{Redis for i18n}
11
+ s.summary = %q{Redis store for i18n}
12
+ s.description = %q{Redis backed store for i18n}
13
13
 
14
14
  s.rubyforge_project = "redis-i18n"
15
15
 
@@ -18,7 +18,12 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
21
+ s.add_runtime_dependency 'redis-store', '1.1.0.rc'
22
+ s.add_runtime_dependency 'i18n', '0.6.0'
23
+
24
+ s.add_development_dependency 'rake', '~> 0.9.2.2'
25
+ s.add_development_dependency 'bundler', '~> 1.1.rc'
26
+ s.add_development_dependency 'mocha', '~> 0.10.0'
27
+ s.add_development_dependency 'minitest', '~> 2.8.0'
28
+ s.add_development_dependency 'purdytest', '~> 1.0.0'
24
29
  end
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ describe "I18n::Backend::Redis" do
4
+ def setup
5
+ @backend = I18n::Backend::Redis.new
6
+ @store = @backend.store
7
+ I18n.backend = @backend
8
+ end
9
+
10
+ it "stores translations" do
11
+ I18n.backend.store_translations :en, :foo => { :bar => :baz }
12
+ I18n.t(:"foo.bar").must_equal(:baz)
13
+
14
+ I18n.backend.store_translations :en, "foo" => { "bar" => "baz" }
15
+ I18n.t(:"foo.bar").must_equal("baz")
16
+ end
17
+
18
+ it "gets translations" do
19
+ I18n.backend.store_translations :en, :foo => { :bar => { :baz => :bang } }
20
+ I18n.t(:"foo.bar.baz").must_equal(:bang)
21
+ I18n.t(:"baz", :scope => :"foo.bar").must_equal(:bang)
22
+ end
23
+
24
+ it "raises an exception when a proc translation is being saved" do
25
+ lambda {
26
+ I18n.backend.store_translations :en, :foo => lambda {|| }
27
+ }.must_raise RuntimeError
28
+ end
29
+
30
+ describe "available locales" do
31
+ def setup
32
+ @locales = [ :en, :it, :es, :fr, :de ]
33
+ end
34
+
35
+ it "returns values" do
36
+ @locales.each { |locale| I18n.backend.store_translations locale, :foo => "bar" }
37
+ available_locales = I18n.backend.available_locales
38
+
39
+ @locales.each do |locale|
40
+ available_locales.must_include(locale)
41
+ end
42
+ end
43
+
44
+ it "returns right values when the store is namespaced" do
45
+ I18n.backend = I18n::Backend::Redis.new :namespace => 'foo'
46
+
47
+ @locales.each { |locale| I18n.backend.store_translations locale, :foo => "bar" }
48
+ available_locales = I18n.backend.available_locales
49
+
50
+ @locales.each do |locale|
51
+ available_locales.must_include(locale)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ describe Redis::I18n::VERSION do
4
+ it "must be equal to 0.6.0.rc" do
5
+ Redis::I18n::VERSION.must_equal '0.6.0.rc'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ Bundler.setup
2
+ gem 'minitest'
3
+ require 'minitest/spec'
4
+ require 'minitest/autorun'
5
+ require 'mocha'
6
+ require 'i18n'
7
+ require 'i18n/backend/redis'
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-i18n
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease:
4
+ hash: 7712042
5
+ prerelease: 6
6
6
  segments:
7
7
  - 0
8
+ - 6
8
9
  - 0
9
- - 0
10
- version: 0.0.0
10
+ - rc
11
+ version: 0.6.0.rc
11
12
  platform: ruby
12
13
  authors:
13
14
  - Luca Guidi
@@ -15,10 +16,123 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-09-08 00:00:00 Z
19
- dependencies: []
20
-
21
- description: Redis for i18n
19
+ date: 2011-12-30 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: redis-store
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7712002
30
+ segments:
31
+ - 1
32
+ - 1
33
+ - 0
34
+ - rc
35
+ version: 1.1.0.rc
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: i18n
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - "="
45
+ - !ruby/object:Gem::Version
46
+ hash: 7
47
+ segments:
48
+ - 0
49
+ - 6
50
+ - 0
51
+ version: 0.6.0
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ hash: 11
63
+ segments:
64
+ - 0
65
+ - 9
66
+ - 2
67
+ - 2
68
+ version: 0.9.2.2
69
+ type: :development
70
+ version_requirements: *id003
71
+ - !ruby/object:Gem::Dependency
72
+ name: bundler
73
+ prerelease: false
74
+ requirement: &id004 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ hash: 7712070
80
+ segments:
81
+ - 1
82
+ - 1
83
+ - rc
84
+ version: 1.1.rc
85
+ type: :development
86
+ version_requirements: *id004
87
+ - !ruby/object:Gem::Dependency
88
+ name: mocha
89
+ prerelease: false
90
+ requirement: &id005 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ hash: 55
96
+ segments:
97
+ - 0
98
+ - 10
99
+ - 0
100
+ version: 0.10.0
101
+ type: :development
102
+ version_requirements: *id005
103
+ - !ruby/object:Gem::Dependency
104
+ name: minitest
105
+ prerelease: false
106
+ requirement: &id006 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ hash: 47
112
+ segments:
113
+ - 2
114
+ - 8
115
+ - 0
116
+ version: 2.8.0
117
+ type: :development
118
+ version_requirements: *id006
119
+ - !ruby/object:Gem::Dependency
120
+ name: purdytest
121
+ prerelease: false
122
+ requirement: &id007 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ~>
126
+ - !ruby/object:Gem::Version
127
+ hash: 23
128
+ segments:
129
+ - 1
130
+ - 0
131
+ - 0
132
+ version: 1.0.0
133
+ type: :development
134
+ version_requirements: *id007
135
+ description: Redis backed store for i18n
22
136
  email:
23
137
  - guidi.luca@gmail.com
24
138
  executables: []
@@ -30,10 +144,16 @@ extra_rdoc_files: []
30
144
  files:
31
145
  - .gitignore
32
146
  - Gemfile
147
+ - MIT-LICENSE
148
+ - README.md
33
149
  - Rakefile
150
+ - lib/i18n/backend/redis.rb
34
151
  - lib/redis-i18n.rb
35
- - lib/redis-i18n/version.rb
152
+ - lib/redis/i18n/version.rb
36
153
  - redis-i18n.gemspec
154
+ - test/i18n/backend/redis_test.rb
155
+ - test/redis/i18n/version_test.rb
156
+ - test/test_helper.rb
37
157
  homepage: http://jodosha.github.com/redis-store
38
158
  licenses: []
39
159
 
@@ -54,18 +174,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
174
  required_rubygems_version: !ruby/object:Gem::Requirement
55
175
  none: false
56
176
  requirements:
57
- - - ">="
177
+ - - ">"
58
178
  - !ruby/object:Gem::Version
59
- hash: 3
179
+ hash: 25
60
180
  segments:
61
- - 0
62
- version: "0"
181
+ - 1
182
+ - 3
183
+ - 1
184
+ version: 1.3.1
63
185
  requirements: []
64
186
 
65
187
  rubyforge_project: redis-i18n
66
188
  rubygems_version: 1.8.6
67
189
  signing_key:
68
190
  specification_version: 3
69
- summary: Redis for i18n
70
- test_files: []
71
-
191
+ summary: Redis store for i18n
192
+ test_files:
193
+ - test/i18n/backend/redis_test.rb
194
+ - test/redis/i18n/version_test.rb
195
+ - test/test_helper.rb
196
+ has_rdoc:
@@ -1,5 +0,0 @@
1
- module Redis
2
- module I18n
3
- VERSION = "0.0.0"
4
- end
5
- end