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.



9
10
11
12
13
# File 'lib/missing_translation_detector.rb', line 9

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.



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

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”.



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

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)


31
32
33
# File 'lib/missing_translation_detector.rb', line 31

def missing_translations?
  !@missing_translations.empty?
end