Class: Localeapp::MissingTranslations

Inherits:
Object
  • Object
show all
Defined in:
lib/localeapp/missing_translations.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMissingTranslations

Returns a new instance of MissingTranslations.



21
22
23
# File 'lib/localeapp/missing_translations.rb', line 21

def initialize
  @translations = Hash.new { |h, k| h[k] = {} }
end

Class Attribute Details

.cached_keysObject

Returns the value of attribute cached_keys.



18
19
20
# File 'lib/localeapp/missing_translations.rb', line 18

def cached_keys
  @cached_keys
end

Instance Method Details

#[](locale) ⇒ Object



33
34
35
# File 'lib/localeapp/missing_translations.rb', line 33

def [](locale)
  @translations[locale]
end

#add(locale, key, description = nil, options = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/localeapp/missing_translations.rb', line 25

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

#reject_blacklistedObject



52
53
54
55
56
57
# File 'lib/localeapp/missing_translations.rb', line 52

def reject_blacklisted
  return unless Localeapp.configuration.blacklisted_keys_pattern
  @translations.each do |locale, records|
    records.reject! { |key, record| record.blacklisted? }
  end
end

#to_sendObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/localeapp/missing_translations.rb', line 37

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