Class: Localeapp::MissingTranslations
- Inherits:
-
Object
- Object
- Localeapp::MissingTranslations
- Defined in:
- lib/localeapp/missing_translations.rb
Class Attribute Summary collapse
-
.cached_keys ⇒ Object
Returns the value of attribute cached_keys.
Instance Method Summary collapse
- #[](locale) ⇒ Object
- #add(locale, key, description = nil, options = {}) ⇒ Object
-
#initialize ⇒ MissingTranslations
constructor
A new instance of MissingTranslations.
- #reject_blacklisted ⇒ Object
- #to_send ⇒ Object
Constructor Details
#initialize ⇒ MissingTranslations
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_keys ⇒ Object
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, = {}) separator = .delete(:separator) { I18n.default_separator } scope = .delete(:scope) key = I18n.normalize_keys(nil, key, scope, separator).map(&:to_s).join(separator) record = MissingTranslationRecord.new(key, locale, description, ) @translations[locale][key] = record end |
#reject_blacklisted ⇒ Object
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_send ⇒ Object
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.} missing_data[:description] = record.description if record.description data << missing_data end end data end |