Class: I18nDashboard::Translation
- Inherits:
-
Object
- Object
- I18nDashboard::Translation
- Defined in:
- app/models/i18n_dashboard/translation.rb
Class Method Summary collapse
- .all(string = nil) ⇒ Object
- .create(key, value, locale) ⇒ Object
- .destroy(digest) ⇒ Object
- .digest_key(key) ⇒ Object
- .exists?(key, locale) ⇒ Boolean
- .keys ⇒ Object
- .rehash! ⇒ Object
- .system_key?(key) ⇒ Boolean
- .system_keys ⇒ Object
Class Method Details
.all(string = nil) ⇒ Object
7 8 9 10 11 12 13 |
# File 'app/models/i18n_dashboard/translation.rb', line 7 def self.all(string = nil) keys = Engine.redis.sunion('keys', 'system_keys') if string.present? keys = keys.grep(/#{string}/) end keys.sort end |
.create(key, value, locale) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'app/models/i18n_dashboard/translation.rb', line 27 def self.create(key, value, locale) if key.present? digest = digest_key(key) Engine.redis.hset('keys_digest', digest, key) Engine.redis.sadd('keys', key) I18n.backend.store_translations(locale, {key => value}, :escape => false) digest end end |
.destroy(digest) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/models/i18n_dashboard/translation.rb', line 41 def self.destroy(digest) key = Engine.redis.hget('keys_digest', digest) Engine.redis.srem('keys', key) Engine.redis.hdel("keys_digest", digest) I18n.available_locales.each do |locale| Engine.redis.del("#{locale}.#{key}") end I18n.reload! end |
.digest_key(key) ⇒ Object
51 52 53 |
# File 'app/models/i18n_dashboard/translation.rb', line 51 def self.digest_key(key) Digest::MD5.hexdigest(key) end |
.exists?(key, locale) ⇒ Boolean
37 38 39 |
# File 'app/models/i18n_dashboard/translation.rb', line 37 def self.exists?(key, locale) Engine.redis.exists("#{locale}.#{key}") end |
.keys ⇒ Object
15 16 17 |
# File 'app/models/i18n_dashboard/translation.rb', line 15 def self.keys Engine.redis.smembers('keys').sort! end |
.rehash! ⇒ Object
55 56 57 58 59 60 |
# File 'app/models/i18n_dashboard/translation.rb', line 55 def self.rehash! self.all.each do |key| Engine.redis.hset('keys_digest', digest_key(key), key) end true end |
.system_key?(key) ⇒ Boolean
23 24 25 |
# File 'app/models/i18n_dashboard/translation.rb', line 23 def self.system_key?(key) Engine.redis.sismember('system_keys', key) end |
.system_keys ⇒ Object
19 20 21 |
# File 'app/models/i18n_dashboard/translation.rb', line 19 def self.system_keys Engine.redis.smembers('system_keys').sort! end |