Sha256: 1b35fd43204c5c5629d00482c56c9855afac2350563b4bf32aec7e99f18615bb

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module I18nAdminUtils
  class Translation
    attr_accessor :key
    attr_accessor :locations
    attr_accessor :translations

    def initialize(key, location = nil)
      @key = key
      @translations = {}
      @locations = []
      @locations << location unless location.nil?
      load_translation
    end

    def self.from_hash(hash)
      translation = I18nAdminUtils::Translation.new(hash[:key])
      if hash[:locations].is_a? Array
        translation.locations = hash[:locations]
      elsif hash[:locations].is_a? Hash
        translation.locations = []
        hash[:locations].each do |k, v|
          translation.locations << v
        end
      end
      translation
    end

    def load_translation
      @translations = {}
      I18nAdminUtils::Config.locales.each do |locale|
        @translations[locale] = I18n.t(key, :locale => locale, :default => '')
      end
    end

    #Return list of the untranslated locales
    def missing_translations
      @translations.select { |x, v| v.nil? or v.blank? }
    end

    #Return boolean if at least on translation is missing
    def missing_translation?
      @translations.any? { |x, v| v.nil? or v.blank? }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i18n_admin_utils-1.1.0 lib/i18n_admin_utils/translation.rb