Class: MissingTranslationDetector

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

Overview

Compares two locale files and detects missing translations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_file_name, target_file_name) ⇒ MissingTranslationDetector

Returns a new instance of MissingTranslationDetector.



7
8
9
10
11
# File 'lib/missing_translation_detector.rb', line 7

def initialize(base_file_name, target_file_name)
  @base = yml_load base_file_name 
  @target = yml_load target_file_name 
  @missing_translations = []
end

Instance Attribute Details

#missing_translationsObject (readonly)

Returns the value of attribute missing_translations.



3
4
5
# File 'lib/missing_translation_detector.rb', line 3

def missing_translations
  @missing_translations
end

Instance Method Details

#detect(h = @base, keys = []) ⇒ Object

Detects missing translations within the target locale file and stores it in “missing_translations”.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/missing_translation_detector.rb', line 15

def detect(h=@base, keys=[])
  h.each_key do |key|
    key_path = keys.clone.push key

    if h[key].is_a?(Hash)
      detect h[key], key_path 
    elsif blank?(key_path)
      missing_translations << OpenStruct.new(:key_path => key_path,
                                             :value => h[key]) 
    end 
  end
end

#missing_translations?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/missing_translation_detector.rb', line 29

def missing_translations?
  !@missing_translations.empty?
end