Sha256: 42ae7af765120502bd1632221935a0d8d96e1bbf0bcb26a4be5a3f5809ad68e9
Contents?: true
Size: 1.49 KB
Versions: 6
Compression:
Stored size: 1.49 KB
Contents
module Localeapp MissingTranslationRecord = Struct.new(:key, :locale, :description, :options) 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 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
6 entries across 6 versions & 1 rubygems