Class: Helper
- Inherits:
-
Object
- Object
- Helper
- Defined in:
- lib/helper.rb
Overview
The Helper class provides utility methods for various tasks.
Class Method Summary collapse
-
.find_lproj(path) ⇒ Array<String>
Finds lproj localization files in the specified path.
-
.find_missing(file_a, file_b) ⇒ Array<String>
Finds missing keys in the target localization file compared to the base file.
-
.make_keys_dict(base_file, target_file) ⇒ Hash<String, String>
Creates a dictionary mapping keys between two localization files.
-
.merge(source, _target, keys, lost_keys) ⇒ void
Merges the source strings into the target strings.
Class Method Details
.find_lproj(path) ⇒ Array<String>
Finds lproj localization files in the specified path.
11 12 13 14 |
# File 'lib/helper.rb', line 11 def self.find_lproj(path) lproj_files = Dir.glob("#{path}/*.lproj").select { |f| File.directory? f } lproj_files.map { |f| File.basename(f, ".lproj") } end |
.find_missing(file_a, file_b) ⇒ Array<String>
Finds missing keys in the target localization file compared to the base file.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/helper.rb', line 38 def self.find_missing(file_a, file_b) strings_a = LocoStrings.load(file_a).read strings_b = LocoStrings.load(file_b).read lost_keys = [] strings_a.each do |key, _string_a| lost_keys << key unless strings_b.key?(key) end lost_keys end |
.make_keys_dict(base_file, target_file) ⇒ Hash<String, String>
Creates a dictionary mapping keys between two localization files.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/helper.rb', line 21 def self.make_keys_dict(base_file, target_file) strings_base = LocoStrings.load(base_file).read strings_target = LocoStrings.load(target_file).read keys = {} strings_base.each do |key_base, string_base| strings_target.each do |key_target, string_target| keys[key_base] = key_target if string_base.value == string_target.value end end keys end |
.merge(source, _target, keys, lost_keys) ⇒ void
This method returns an undefined value.
Merges the source strings into the target strings
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/helper.rb', line 57 def self.merge(source, _target, keys, lost_keys) source.each do |key, source_string| target_key = keys[key] next unless target_key next unless lost_keys.include?(target_key) strings_b_file.update(target_key, source_string.value) lost_keys.delete(target_key) Logger.string_value(target_key, source_string.value) end end |