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.



11
12
13
# File 'lib/localeapp/missing_translations.rb', line 11

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

Class Attribute Details

.cached_keysObject

Returns the value of attribute cached_keys.



8
9
10
# File 'lib/localeapp/missing_translations.rb', line 8

def cached_keys
  @cached_keys
end

Instance Method Details

#[](locale) ⇒ Object



23
24
25
# File 'lib/localeapp/missing_translations.rb', line 23

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

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



15
16
17
18
19
20
21
# File 'lib/localeapp/missing_translations.rb', line 15

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

#to_sendObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/localeapp/missing_translations.rb', line 27

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