Class: Localeapp::MissingTranslations

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

Instance Method Summary collapse

Constructor Details

#initializeMissingTranslations

Returns a new instance of MissingTranslations.



5
6
7
# File 'lib/localeapp/missing_translations.rb', line 5

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

Instance Method Details

#[](locale) ⇒ Object



14
15
16
# File 'lib/localeapp/missing_translations.rb', line 14

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

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



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

def add(locale, key, description = nil, options = {})
  record = MissingTranslationRecord.new(key, locale, description, options)
  @translations[locale][key] = record
end

#to_sendObject

This method will get cleverer so we don’t resend keys we’ve already sent, or send multiple times for the same locale etc. For now it’s pretty dumb



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/localeapp/missing_translations.rb', line 21

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|
      missing_data = {}
      missing_data[:key] = key
      missing_data[:locale] = locale
      missing_data[:description] = record.description if record.description
      missing_data[:options] = record.options
      data << missing_data
    end
  end
  data
end