Sha256: 99fd5ccc071ad41e8a87a5df5bc959e9d01cd8aaa54302b11a2f57eb3e8a40d1

Contents?: true

Size: 1005 Bytes

Versions: 5

Compression:

Stored size: 1005 Bytes

Contents

module Localeapp
  MissingTranslationRecord = Struct.new(:key, :locale, :options)

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

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

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

    # 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
    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[:options] = record.options
          data << missing_data
        end
      end
      data
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
localeapp-0.1.2 lib/localeapp/missing_translations.rb
localeapp-0.1.1 lib/localeapp/missing_translations.rb
localeapp-0.0.11 lib/localeapp/missing_translations.rb
localeapp-0.0.10 lib/localeapp/missing_translations.rb
localeapp-0.0.8 lib/localeapp/missing_translations.rb