Sha256: 026e0242c52a69cfe1ab02c10adbe9b9dd89fb9d9d6e515f930889b1cb5f722c
Contents?: true
Size: 1.88 KB
Versions: 7
Compression:
Stored size: 1.88 KB
Contents
module Localeapp MissingTranslationRecord = Struct.new(:key, :locale, :description, :options) do def blacklisted? key_path.match(Localeapp.configuration.blacklisted_keys_pattern) end def key_path [options[:scope], key].compact.join('.') end end class MissingTranslations @cached_keys = [] class << self attr_accessor :cached_keys end def initialize @translations = Hash.new { |h, k| h[k] = {} } end def add(locale, key, description = nil, options = {}) separator = options.delete(:separator) { I18n.default_separator } scope = options.delete(:scope) key = I18n.normalize_keys(nil, key, scope, separator).map(&:to_s).join(separator) record = MissingTranslationRecord.new(key, locale, description, options) @translations[locale][key] = record end def [](locale) @translations[locale] end def to_send data = [] # need the sort to make specs work under 1.8 @translations.sort { |a, b| a.to_s <=> b.to_s }.each do |locale, records| records.each do |key, record| next if cached?(key) cache(key) missing_data = {:key => key, :locale => locale, :options => record.options} missing_data[:description] = record.description if record.description data << missing_data end end data end def reject_blacklisted return unless Localeapp.configuration.blacklisted_keys_pattern @translations.each do |locale, records| records.reject! { |key, record| record.blacklisted? } end end private def cached_keys self.class.cached_keys end def cached?(key) Localeapp.configuration.cache_missing_translations && cached_keys.include?(key) end def cache(key) cached_keys << key if Localeapp.configuration.cache_missing_translations end end end
Version data entries
7 entries across 7 versions & 1 rubygems