Class: MissingTranslationDetector
- Inherits:
-
Object
- Object
- MissingTranslationDetector
- Defined in:
- lib/missing_translation_detector.rb
Overview
Compares two locale files and detects missing translations.
Instance Attribute Summary collapse
-
#missing_translations ⇒ Object
readonly
Returns the value of attribute missing_translations.
Instance Method Summary collapse
-
#detect(h = @base, keys = []) ⇒ Object
Detects missing translations within the target locale file and stores it in “missing_translations”.
-
#initialize(base_file_name, target_file_name) ⇒ MissingTranslationDetector
constructor
A new instance of MissingTranslationDetector.
- #missing_translations? ⇒ Boolean
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_translations ⇒ Object (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
29 30 31 |
# File 'lib/missing_translation_detector.rb', line 29 def missing_translations? !@missing_translations.empty? end |