Class: I18n::Backend::Redis
- Inherits:
-
Object
- Object
- I18n::Backend::Redis
- Includes:
- Base, Flatten
- Defined in:
- lib/i18n/backend/redis.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
- #available_locales ⇒ Object
-
#initialize(*addresses) ⇒ Redis
constructor
Instantiate the store.
- #store_translations(locale, data, options = {}) ⇒ Object
- #translate(locale, key, options = {}) ⇒ Object
Constructor Details
#initialize(*addresses) ⇒ Redis
Instantiate the store.
Example:
RedisStore.new
# => host: localhost, port: 6379, db: 0
RedisStore.new "example.com"
# => host: example.com, port: 6379, db: 0
RedisStore.new "example.com:23682"
# => host: example.com, port: 23682, db: 0
RedisStore.new "example.com:23682/1"
# => host: example.com, port: 23682, db: 1
RedisStore.new "example.com:23682/1/theplaylist"
# => host: example.com, port: 23682, db: 1, namespace: theplaylist
RedisStore.new "localhost:6379/0", "localhost:6380/0"
# => instantiate a cluster
27 28 29 |
# File 'lib/i18n/backend/redis.rb', line 27 def initialize(*addresses) @store = ::Redis::Factory.create(addresses) end |
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
5 6 7 |
# File 'lib/i18n/backend/redis.rb', line 5 def store @store end |
Instance Method Details
#available_locales ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/i18n/backend/redis.rb', line 48 def available_locales locales = @store.keys.map { |k| k =~ /\./; $` } locales.uniq! locales.compact! locales.map! { |k| k.to_sym } locales end |
#store_translations(locale, data, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/i18n/backend/redis.rb', line 36 def store_translations(locale, data, = {}) escape = .fetch(:escape, true) flatten_translations(locale, data, escape, false).each do |key, value| case value when Proc raise "Key-value stores cannot handle procs" else @store.set "#{locale}.#{key}", value end end end |
#translate(locale, key, options = {}) ⇒ Object
31 32 33 34 |
# File 'lib/i18n/backend/redis.rb', line 31 def translate(locale, key, = {}) [:resolve] ||= false super locale, key, end |