Sha256: 36ffb3124a1514bed6248d1349372e7668022cac67cda6f386c0fbbd20f96222

Contents?: true

Size: 960 Bytes

Versions: 2

Compression:

Stored size: 960 Bytes

Contents

module I18nDashboard
  class Translation


    def self.all(string = nil)
      keys = Engine.redis.sunion('keys', 'system_keys')
      if string.present?
        keys = keys.grep(/#{string}/)
      end
      keys.sort
    end

    def self.keys
      Engine.redis.smembers('keys').sort!
    end

    def self.system_keys
      Engine.redis.smembers('system_keys').sort!
    end

    def self.system_key?(key)
      Engine.redis.sismember('system_keys', key)
    end

    def self.create(key, value, locale)
      if key.present?
        Engine.redis.sadd('keys', key)
        I18n.backend.store_translations(locale, {key => value}, :escape => false)
      end
    end

    def self.exists?(key, locale)
      Engine.redis.exists("#{locale}.#{key}")
    end

    def self.destroy(key)
      Engine.redis.srem('keys', key)
      I18n.available_locales.each do |locale|
        Engine.redis.del("#{locale}.#{key}")
      end
      I18n.reload!
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i18n_dashboard-0.1.4 app/models/i18n_dashboard/translation.rb
i18n_dashboard-0.1.3 app/models/i18n_dashboard/translation.rb