lost_in_translation 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gitignore +1 -1
 - data/lib/lost_in_translation.rb +3 -0
 - data/lib/lost_in_translation/difference.rb +23 -23
 - data/lib/lost_in_translation/file_functions.rb +37 -16
 - data/lib/lost_in_translation/hash.rb +0 -1
 - data/lib/lost_in_translation/user_interface.rb +36 -30
 - data/lib/lost_in_translation/version.rb +1 -1
 - data/lib/lost_in_translation/z_cleanup.rb +19 -22
 - data/lib/lost_in_translation/z_interactive.rb +34 -27
 - data/lib/lost_in_translation/z_recent.rb +41 -24
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 64cafc716734b1378b969b9d6b11c948e05053aa
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5bfcc42177ec56cb73c8d1329957f1b003efc424
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: eb67dec3972f76e8f50dda2011aec216999eeb09c5907f3dae34582e12b07809636e6500aefb65d8e98c509e0c4a65ffc34362e83784240028b14cd503057d50
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e2753025ed52be2e51081a8122a6c86865b3f47ceb66b01e8ac73c64ce33cf1d990de451d7fef017ae1afd34c12fe68c49c9b5251906407a5fa08d602f3cdb13
         
     | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/lib/lost_in_translation.rb
    CHANGED
    
    
| 
         @@ -2,40 +2,40 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
4 
     | 
    
         
             
            module LostInTranslation
         
     | 
| 
       5 
     | 
    
         
            -
              def self.diff(root, compared, lang1, lang2, structure = [],  
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
      
 5 
     | 
    
         
            +
              def self.diff(root, compared, lang1, lang2, structure = [], new_array = [], options = {})
         
     | 
| 
      
 6 
     | 
    
         
            +
                @slave_file = options[:slave_file]
         
     | 
| 
      
 7 
     | 
    
         
            +
                @mode = options[:mode] # replace, clean, count
         
     | 
| 
      
 8 
     | 
    
         
            +
                @diff_count = options[:diff_count]
         
     | 
| 
      
 9 
     | 
    
         
            +
                @diff_counter = options[:diff_counter]
         
     | 
| 
       7 
10 
     | 
    
         
             
                root.each_pair do |key, value|
         
     | 
| 
       8 
11 
     | 
    
         
             
                  next_root     = root[key]
         
     | 
| 
       9 
12 
     | 
    
         
             
                  next_compared = compared.nil? ? nil : compared[key]
         
     | 
| 
       10 
13 
     | 
    
         
             
                  new_structure = structure.dup << key
         
     | 
| 
       11 
     | 
    
         
            -
                  if value.is_a?  
     | 
| 
       12 
     | 
    
         
            -
                     
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                  if value.is_a?(String) && (compared.nil? || compared[key].nil?)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @diff_counter += 1
         
     | 
| 
      
 16 
     | 
    
         
            +
                    if @mode == 'replace' && value_missing(options[:slave_file], new_structure)
         
     | 
| 
      
 17 
     | 
    
         
            +
                      new_val = ask_for_translation(value, new_structure, lang1, lang2, @diff_count, @diff_counter)
         
     | 
| 
      
 18 
     | 
    
         
            +
                      return new_array if new_val.present? && new_val.end_with?('exit')
         
     | 
| 
       14 
19 
     | 
    
         
             
                      new_array << new_val unless new_val.nil?
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                    elsif @mode == 'clean'
         
     | 
| 
      
 21 
     | 
    
         
            +
                      new_array << "#{new_structure.join('---')}---#{value}"
         
     | 
| 
       16 
22 
     | 
    
         
             
                    end
         
     | 
| 
       17 
23 
     | 
    
         
             
                  end
         
     | 
| 
       18 
     | 
    
         
            -
                   
     | 
| 
      
 24 
     | 
    
         
            +
                  if next_root.is_a? Hash
         
     | 
| 
      
 25 
     | 
    
         
            +
                    diff(next_root, next_compared, lang1, lang2, new_structure, new_array,
         
     | 
| 
      
 26 
     | 
    
         
            +
                         diff_counter: @diff_counter, diff_count: @diff_count, mode: @mode, slave_file: @slave_file)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
       19 
28 
     | 
    
         
             
                end
         
     | 
| 
       20 
     | 
    
         
            -
                new_array
         
     | 
| 
      
 29 
     | 
    
         
            +
                @mode == 'count' ? @diff_counter : new_array
         
     | 
| 
       21 
30 
     | 
    
         
             
              end
         
     | 
| 
       22 
31 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
              def self. 
     | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
      
 32 
     | 
    
         
            +
              def self.value_missing(slave_file, structure)
         
     | 
| 
      
 33 
     | 
    
         
            +
                return true if slave_file.blank?
         
     | 
| 
      
 34 
     | 
    
         
            +
                puts structure
         
     | 
| 
      
 35 
     | 
    
         
            +
                false
         
     | 
| 
       25 
36 
     | 
    
         
             
              end
         
     | 
| 
       26 
37 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
              def self. 
     | 
| 
       28 
     | 
    
         
            -
                 
     | 
| 
       29 
     | 
    
         
            -
                  next_root     = root[key]
         
     | 
| 
       30 
     | 
    
         
            -
                  next_compared = compared.nil? ? nil : compared[key]
         
     | 
| 
       31 
     | 
    
         
            -
                  new_structure = structure.dup << key
         
     | 
| 
       32 
     | 
    
         
            -
                  if value.is_a? String
         
     | 
| 
       33 
     | 
    
         
            -
                    unless compared.nil? || compared[key].nil?
         
     | 
| 
       34 
     | 
    
         
            -
                      new_array << "#{new_structure.join('---')}-#{value}"
         
     | 
| 
       35 
     | 
    
         
            -
                    end
         
     | 
| 
       36 
     | 
    
         
            -
                  end
         
     | 
| 
       37 
     | 
    
         
            -
                  clean(next_root, next_compared, new_structure, new_array) if next_root.is_a? Hash
         
     | 
| 
       38 
     | 
    
         
            -
                end
         
     | 
| 
       39 
     | 
    
         
            -
                new_array
         
     | 
| 
      
 38 
     | 
    
         
            +
              def self.get_locale(path)
         
     | 
| 
      
 39 
     | 
    
         
            +
                path.split('/').last.split('.').first unless path.empty?
         
     | 
| 
       40 
40 
     | 
    
         
             
              end
         
     | 
| 
       41 
41 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,10 +2,38 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
4 
     | 
    
         
             
            module LostInTranslation
         
     | 
| 
       5 
     | 
    
         
            -
              def self. 
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
              def self.prepare_for_edit(paths = [])
         
     | 
| 
      
 6 
     | 
    
         
            +
                copy_path = "#{root}/tmp"
         
     | 
| 
      
 7 
     | 
    
         
            +
                path_array = []
         
     | 
| 
      
 8 
     | 
    
         
            +
                paths.each_with_index do |p, i|
         
     | 
| 
      
 9 
     | 
    
         
            +
                  path = "#{copy_path}/tmp_file#{i}.yml"
         
     | 
| 
      
 10 
     | 
    
         
            +
                  FileUtils.cp(p, path)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  path_array << path
         
     | 
| 
       8 
12 
     | 
    
         
             
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
                path_array
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              def self.prepare_paths(paths = [])
         
     | 
| 
      
 17 
     | 
    
         
            +
                paths.each do |p|
         
     | 
| 
      
 18 
     | 
    
         
            +
                  prepare_yaml(p, false)
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              def self.postpare_paths(paths = [])
         
     | 
| 
      
 23 
     | 
    
         
            +
                paths.each do |p|
         
     | 
| 
      
 24 
     | 
    
         
            +
                  prepare_yaml(p, true)
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              def self.define_snippets
         
     | 
| 
      
 29 
     | 
    
         
            +
                snippets = []
         
     | 
| 
      
 30 
     | 
    
         
            +
                snippets << ['<<', 'a_greater_than_sign']
         
     | 
| 
      
 31 
     | 
    
         
            +
                snippets << ['*', 'an_asterik_sign']
         
     | 
| 
      
 32 
     | 
    
         
            +
                snippets << ['!', 'a_bang_sign']
         
     | 
| 
      
 33 
     | 
    
         
            +
                snippets << ['%', 'a_percentage_sign']
         
     | 
| 
      
 34 
     | 
    
         
            +
                snippets << ['a_bang_sign \'', '\'a_bang_sign']
         
     | 
| 
      
 35 
     | 
    
         
            +
                # snippets << ["&", "this_and_snippet_variable"]
         
     | 
| 
      
 36 
     | 
    
         
            +
                snippets
         
     | 
| 
       9 
37 
     | 
    
         
             
              end
         
     | 
| 
       10 
38 
     | 
    
         | 
| 
       11 
39 
     | 
    
         
             
              private
         
     | 
| 
         @@ -20,8 +48,6 @@ module LostInTranslation 
     | 
|
| 
       20 
48 
     | 
    
         
             
                  text = text.gsub(snippet.first, snippet.second)
         
     | 
| 
       21 
49 
     | 
    
         
             
                end
         
     | 
| 
       22 
50 
     | 
    
         
             
                text = post ? postpare(snippets, text) : prepare(snippets, text)
         
     | 
| 
       23 
     | 
    
         
            -
                text = add_single_quotes(text) if post
         
     | 
| 
       24 
     | 
    
         
            -
                text = text.gsub(': !,', ": '!,'") if post
         
     | 
| 
       25 
51 
     | 
    
         | 
| 
       26 
52 
     | 
    
         
             
                File.open(path, 'w') { |file| file.puts text }
         
     | 
| 
       27 
53 
     | 
    
         
             
              end
         
     | 
| 
         @@ -33,6 +59,12 @@ module LostInTranslation 
     | 
|
| 
       33 
59 
     | 
    
         
             
                  new_var = new_var.gsub('varyberryterry', ': &')
         
     | 
| 
       34 
60 
     | 
    
         
             
                  text = text.gsub(var, new_var)
         
     | 
| 
       35 
61 
     | 
    
         
             
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
                text = add_single_quotes(text)
         
     | 
| 
      
 63 
     | 
    
         
            +
                text = text.gsub(': !,', ": ! ','")
         
     | 
| 
      
 64 
     | 
    
         
            +
                text = text.gsub('\'!', '! \'')
         
     | 
| 
      
 65 
     | 
    
         
            +
                text = text.gsub(/---\n/, '')
         
     | 
| 
      
 66 
     | 
    
         
            +
                text = text.gsub('!…', "! '…'")
         
     | 
| 
      
 67 
     | 
    
         
            +
                text = text.gsub('!:distance_in_words', "! ':distance_in_words'")
         
     | 
| 
       36 
68 
     | 
    
         
             
                text
         
     | 
| 
       37 
69 
     | 
    
         
             
              end
         
     | 
| 
       38 
70 
     | 
    
         | 
| 
         @@ -65,15 +97,4 @@ module LostInTranslation 
     | 
|
| 
       65 
97 
     | 
    
         
             
                arr[1] = arr[1].gsub("\'! ", "! \'")
         
     | 
| 
       66 
98 
     | 
    
         
             
                return arr.join(': ')
         
     | 
| 
       67 
99 
     | 
    
         
             
              end
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
              def self.define_snippets
         
     | 
| 
       70 
     | 
    
         
            -
                snippets = []
         
     | 
| 
       71 
     | 
    
         
            -
                snippets << ['<<', 'a_greater_than_sign']
         
     | 
| 
       72 
     | 
    
         
            -
                snippets << ['*', 'an_asterik_sign']
         
     | 
| 
       73 
     | 
    
         
            -
                snippets << ['!', 'a_bang_sign']
         
     | 
| 
       74 
     | 
    
         
            -
                snippets << ['%', 'a_percentage_sign']
         
     | 
| 
       75 
     | 
    
         
            -
                snippets << ['a_bang_sign \'', '\'a_bang_sign']
         
     | 
| 
       76 
     | 
    
         
            -
                # snippets << ["&", "this_and_snippet_variable"]
         
     | 
| 
       77 
     | 
    
         
            -
                snippets
         
     | 
| 
       78 
     | 
    
         
            -
              end
         
     | 
| 
       79 
100 
     | 
    
         
             
            end
         
     | 
| 
         @@ -11,7 +11,6 @@ module LostInTranslation 
     | 
|
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
              def self.merge_hash(merge_from, merge_to)
         
     | 
| 
       13 
13 
     | 
    
         
             
                return if merge_from.is_a?(String) || merge_to.is_a?(String)
         
     | 
| 
       14 
     | 
    
         
            -
                pp merge_to
         
     | 
| 
       15 
14 
     | 
    
         
             
                merged_hash = merge_to
         
     | 
| 
       16 
15 
     | 
    
         
             
                first_key = merge_from.keys.first
         
     | 
| 
       17 
16 
     | 
    
         
             
                merged_hash[first_key] = if merge_to.key?(first_key)
         
     | 
| 
         @@ -2,54 +2,50 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
4 
     | 
    
         
             
            module LostInTranslation
         
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
      
 5 
     | 
    
         
            +
              require 'readline'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              def self.ask_for_file(master)
         
     | 
| 
      
 8 
     | 
    
         
            +
                text = master ? "# Master (e.g. 'en'): " : "# Slave: (e.g. 'de'): "
         
     | 
| 
      
 9 
     | 
    
         
            +
                file = {}
         
     | 
| 
      
 10 
     | 
    
         
            +
                file[:lang] = [(print text), Readline.readline()][1]
         
     | 
| 
      
 11 
     | 
    
         
            +
                file[:path] = defined?(Rails) ? "#{Rails.root}/config/locales/#{file[:lang]}.yml" : ask_for_path(file)
         
     | 
| 
      
 12 
     | 
    
         
            +
                file[:app_name] = Rails&.application&.class&.parent_name
         
     | 
| 
      
 13 
     | 
    
         
            +
                file
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              def self.ask_for_permission(lang1, lang2, app_name, count)
         
     | 
| 
       6 
17 
     | 
    
         
             
                log
         
     | 
| 
       7 
18 
     | 
    
         
             
                log 'Comparing Locales'
         
     | 
| 
       8 
19 
     | 
    
         
             
                log "Application: #{app_name}" unless app_name.nil?
         
     | 
| 
       9 
20 
     | 
    
         
             
                log "Master Locale: #{lang1}.yml"
         
     | 
| 
       10 
21 
     | 
    
         
             
                log "Slave Locale: #{lang2}.yml"
         
     | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
      
 22 
     | 
    
         
            +
                log "Difference: #{count} Entries"
         
     | 
| 
      
 23 
     | 
    
         
            +
                a = [(print "# Wanna do it? [Y/n]: "), Readline.readline()][1]
         
     | 
| 
       12 
24 
     | 
    
         
             
                a == 'y' || a == 'Y' || a == ''
         
     | 
| 
       13 
25 
     | 
    
         
             
              end
         
     | 
| 
       14 
26 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
              def self.ask_for_languages
         
     | 
| 
       16 
     | 
    
         
            -
                log
         
     | 
| 
       17 
     | 
    
         
            -
                log 'What I18n-yaml files do you want to compare?'
         
     | 
| 
       18 
     | 
    
         
            -
                lang1 = [(print "# Master (e.g. 'en'): "), STDIN.gets.chomp][1]
         
     | 
| 
       19 
     | 
    
         
            -
                lang2 = [(print "# Slave: (e.g. 'de'): "), STDIN.gets.chomp][1]
         
     | 
| 
       20 
     | 
    
         
            -
                [lang1, lang2]
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              def self.ask_for_max_count
         
     | 
| 
       24 
     | 
    
         
            -
                log
         
     | 
| 
       25 
     | 
    
         
            -
                log 'How many do you want to edit max?'
         
     | 
| 
       26 
     | 
    
         
            -
                max_count = [(print '# Max. Count (default = 50000): '), STDIN.gets.chomp][1]
         
     | 
| 
       27 
     | 
    
         
            -
                max_count
         
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
              def self.ask_for_paths
         
     | 
| 
       31 
     | 
    
         
            -
                log
         
     | 
| 
       32 
     | 
    
         
            -
                log 'Please type in the absolute paths to the I18n-yaml file you want to compare?'
         
     | 
| 
       33 
     | 
    
         
            -
                log 'e.g. /home/youruser/Documents/your-awesome-app/config/locales/en.yml'
         
     | 
| 
       34 
     | 
    
         
            -
                path1 = [(print '# Master: '), STDIN.gets.chomp][1]
         
     | 
| 
       35 
     | 
    
         
            -
                path2 = [(print '# Slave:: '), STDIN.gets.chomp][1]
         
     | 
| 
       36 
     | 
    
         
            -
                [path1, path2]
         
     | 
| 
       37 
     | 
    
         
            -
              end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
27 
     | 
    
         
             
              def self.ask_for_sorting(lang, _app_name)
         
     | 
| 
       40 
28 
     | 
    
         
             
                log
         
     | 
| 
       41 
29 
     | 
    
         
             
                log "Do you want the #{lang}.yml to be sorted?"
         
     | 
| 
       42 
30 
     | 
    
         
             
                log 'Alphabetically & Recursive (ASC)'
         
     | 
| 
       43 
     | 
    
         
            -
                a = [(print "# [Y/n]: "),  
     | 
| 
      
 31 
     | 
    
         
            +
                a = [(print "# [Y/n]: "), Readline.readline()][1]
         
     | 
| 
       44 
32 
     | 
    
         
             
                a == 'y' || a == 'Y' || a == ''
         
     | 
| 
       45 
33 
     | 
    
         
             
              end
         
     | 
| 
       46 
34 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
              def self.ask_for_translation(value, new_structure, lang1, lang2)
         
     | 
| 
      
 35 
     | 
    
         
            +
              def self.ask_for_translation(value, new_structure, lang1, lang2, diff_count, diff_counter)
         
     | 
| 
      
 36 
     | 
    
         
            +
                system 'clear'
         
     | 
| 
       48 
37 
     | 
    
         
             
                log
         
     | 
| 
      
 38 
     | 
    
         
            +
                log "#{diff_counter} / #{diff_count}"
         
     | 
| 
       49 
39 
     | 
    
         
             
                new_s = new_structure.join('---')
         
     | 
| 
       50 
40 
     | 
    
         
             
                log "#{new_s} is missing"
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                 
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                snippets = LostInTranslation.define_snippets.reverse
         
     | 
| 
      
 43 
     | 
    
         
            +
                snippets.each do |snippet|
         
     | 
| 
      
 44 
     | 
    
         
            +
                  value = value.gsub(snippet.second, snippet.first)
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                puts "# In #{lang1.upcase}: #{value}"
         
     | 
| 
      
 48 
     | 
    
         
            +
                new_val = [(print '# ' + lang2 + ': '), Readline.readline()][1]
         
     | 
| 
       53 
49 
     | 
    
         
             
                new_val == '' ? nil : (new_s + '---' + new_val)
         
     | 
| 
       54 
50 
     | 
    
         
             
              end
         
     | 
| 
       55 
51 
     | 
    
         | 
| 
         @@ -64,4 +60,14 @@ module LostInTranslation 
     | 
|
| 
       64 
60 
     | 
    
         
             
                  puts '# ' + str + fill + ' #'
         
     | 
| 
       65 
61 
     | 
    
         
             
                end
         
     | 
| 
       66 
62 
     | 
    
         
             
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
              private
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
              def self.ask_for_path(file)
         
     | 
| 
      
 67 
     | 
    
         
            +
                log
         
     | 
| 
      
 68 
     | 
    
         
            +
                log 'Please type in the absolute paths your locales?'
         
     | 
| 
      
 69 
     | 
    
         
            +
                log 'e.g. /home/youruser/Documents/your-awesome-app/config/locales'
         
     | 
| 
      
 70 
     | 
    
         
            +
                path = [(print '# '), Readline.readline()][1]
         
     | 
| 
      
 71 
     | 
    
         
            +
                "#{path}/#{file[:lang]}.yml"
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
       67 
73 
     | 
    
         
             
            end
         
     | 
| 
         @@ -3,36 +3,33 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
4 
     | 
    
         
             
            module LostInTranslation
         
     | 
| 
       5 
5 
     | 
    
         
             
              def self.cleanup
         
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  lang1 = LostInTranslation.get_locale(path1)
         
     | 
| 
       14 
     | 
    
         
            -
                  lang2 = LostInTranslation.get_locale(path2)
         
     | 
| 
       15 
     | 
    
         
            -
                end
         
     | 
| 
      
 6 
     | 
    
         
            +
                system 'clear'
         
     | 
| 
      
 7 
     | 
    
         
            +
                log
         
     | 
| 
      
 8 
     | 
    
         
            +
                log 'What I18n-yaml files do you want to compare?'
         
     | 
| 
      
 9 
     | 
    
         
            +
                log '!!! WARNING!!! This deletes the differences!!! Make a BACKUP!!! !!!'
         
     | 
| 
      
 10 
     | 
    
         
            +
                @master = ask_for_file(true) # lang path app_name
         
     | 
| 
      
 11 
     | 
    
         
            +
                @slave = ask_for_file(false)
         
     | 
| 
       16 
12 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
      
 13 
     | 
    
         
            +
                raise 'Invalid Filepaths' unless File.exist?(@master[:path]) && File.exist?(@slave[:path])
         
     | 
| 
       18 
14 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
       20 
     | 
    
         
            -
                prepare_paths( 
     | 
| 
      
 15 
     | 
    
         
            +
                @master[:copy_path], @slave[:copy_path] = prepare_for_edit([@master[:path], @slave[:path]])
         
     | 
| 
      
 16 
     | 
    
         
            +
                prepare_paths([@master[:copy_path], @slave[:copy_path]])
         
     | 
| 
       21 
17 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
       23 
     | 
    
         
            -
                 
     | 
| 
      
 18 
     | 
    
         
            +
                master_file = YAML.load_file(@master[:copy_path])
         
     | 
| 
      
 19 
     | 
    
         
            +
                slave_file = YAML.load_file(@slave[:copy_path])
         
     | 
| 
       24 
20 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                new_strings_array =  
     | 
| 
      
 21 
     | 
    
         
            +
                new_strings_array = diff(master_file[@master[:lang]], slave_file[@slave[:lang]], @master[:lang],
         
     | 
| 
      
 22 
     | 
    
         
            +
                                         @slave[:lang], [@slave[:lang]], [], mode: 'clean')
         
     | 
| 
       26 
23 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                 
     | 
| 
      
 24 
     | 
    
         
            +
                master_file = {}
         
     | 
| 
       28 
25 
     | 
    
         
             
                new_strings_array.each do |string|
         
     | 
| 
       29 
     | 
    
         
            -
                  string = string.split('---').map { |x| x ==  
     | 
| 
       30 
     | 
    
         
            -
                  result =  
     | 
| 
       31 
     | 
    
         
            -
                   
     | 
| 
      
 26 
     | 
    
         
            +
                  string = string.split('---').map { |x| x == @slave[:lang] ? @master[:lang] : x }.join('---')
         
     | 
| 
      
 27 
     | 
    
         
            +
                  result = string_to_hash(string)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  merge_hash(result, master_file)
         
     | 
| 
       32 
29 
     | 
    
         
             
                end
         
     | 
| 
       33 
30 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                File.open( 
     | 
| 
      
 31 
     | 
    
         
            +
                File.open(@master[:path], 'w') { |file| file.write(master_file.to_yaml) }
         
     | 
| 
       35 
32 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                 
     | 
| 
      
 33 
     | 
    
         
            +
                postpare_paths([@master[:path], @slave[:lang]])
         
     | 
| 
       37 
34 
     | 
    
         
             
              end
         
     | 
| 
       38 
35 
     | 
    
         
             
            end
         
     | 
| 
         @@ -4,43 +4,50 @@ 
     | 
|
| 
       4 
4 
     | 
    
         
             
            module LostInTranslation
         
     | 
| 
       5 
5 
     | 
    
         
             
              def self.interactive
         
     | 
| 
       6 
6 
     | 
    
         
             
                system 'clear'
         
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                 
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                  lang1 = LostInTranslation.get_locale(path1)
         
     | 
| 
       17 
     | 
    
         
            -
                  lang2 = LostInTranslation.get_locale(path2)
         
     | 
| 
       18 
     | 
    
         
            -
                end
         
     | 
| 
      
 7 
     | 
    
         
            +
                log
         
     | 
| 
      
 8 
     | 
    
         
            +
                log 'What I18n-yaml files do you want to compare?'
         
     | 
| 
      
 9 
     | 
    
         
            +
                @master = ask_for_file(true) # lang path app_name
         
     | 
| 
      
 10 
     | 
    
         
            +
                @slave = ask_for_file(false)
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                raise 'Invalid Filepaths' unless File.exist?(@master[:path]) && File.exist?(@slave[:path])
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                @master[:copy_path], @slave[:copy_path] = prepare_for_edit([@master[:path], @slave[:path]])
         
     | 
| 
       19 
15 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                 
     | 
| 
       21 
     | 
    
         
            -
                abort('Well, in that case, forget it!') unless LostInTranslation.ask_for_permission(lang1, lang2, app_name)
         
     | 
| 
      
 16 
     | 
    
         
            +
                prepare_paths([@master[:copy_path], @slave[:copy_path]])
         
     | 
| 
       22 
17 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                 
     | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
      
 18 
     | 
    
         
            +
                master_file = YAML.load_file(@master[:copy_path])
         
     | 
| 
      
 19 
     | 
    
         
            +
                slave_file = YAML.load_file(@slave[:copy_path])
         
     | 
| 
       25 
20 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                 
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
                count = diff(master_file[@master[:lang]], slave_file[@slave[:lang]], @master[:lang],
         
     | 
| 
      
 22 
     | 
    
         
            +
                             @slave[:lang], [@slave[:lang]], [], mode: 'count')
         
     | 
| 
       28 
23 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
                 
     | 
| 
      
 24 
     | 
    
         
            +
                unless ask_for_permission(@master[:lang], @slave[:lang], @master[:app_name], count)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  abort('Well, in that case, forget it!')
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                new_strings_array = diff(master_file[@master[:lang]], slave_file[@slave[:lang]], @master[:lang],
         
     | 
| 
      
 29 
     | 
    
         
            +
                                         @slave[:lang], [@slave[:lang]], [], diff_count: count, mode: 'replace')
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                new_strings_array.each do |string|
         
     | 
| 
       32 
     | 
    
         
            -
                  result =  
     | 
| 
       33 
     | 
    
         
            -
                   
     | 
| 
      
 32 
     | 
    
         
            +
                  result = string_to_hash(string)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  merge_hash(result, slave_file)
         
     | 
| 
       34 
34 
     | 
    
         
             
                end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                 
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
                sorted = false
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                if ask_for_sorting(@master[:lang], @master[:app_name])
         
     | 
| 
      
 39 
     | 
    
         
            +
                  master_file = sort_hash(master_file)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  File.open(@master[:copy_path], 'w') { |file| file.write(master_file.to_yaml(line_width: -1)) }
         
     | 
| 
      
 41 
     | 
    
         
            +
                  sorted = true
         
     | 
| 
       39 
42 
     | 
    
         
             
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
                slave_file = sort_hash(slave_file) if ask_for_sorting(@slave[:lang], @slave[:app_name])
         
     | 
| 
      
 44 
     | 
    
         
            +
                File.open(@slave[:copy_path], 'w') { |file| file.write(slave_file.to_yaml(line_width: -1)) }
         
     | 
| 
       40 
45 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                 
     | 
| 
       42 
     | 
    
         
            -
                File.open(path2, 'w') { |file| file.write(second.to_yaml(line_width: -1)) }
         
     | 
| 
      
 46 
     | 
    
         
            +
                postpare_paths([@master[:copy_path], @slave[:copy_path]])
         
     | 
| 
       43 
47 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                 
     | 
| 
      
 48 
     | 
    
         
            +
                FileUtils.cp(@master[:copy_path], @master[:path]) if sorted
         
     | 
| 
      
 49 
     | 
    
         
            +
                FileUtils.cp(@slave[:copy_path], @slave[:path])
         
     | 
| 
      
 50 
     | 
    
         
            +
                FileUtils.rm(@master[:copy_path])
         
     | 
| 
      
 51 
     | 
    
         
            +
                FileUtils.rm(@slave[:copy_path])
         
     | 
| 
       45 
52 
     | 
    
         
             
              end
         
     | 
| 
       46 
53 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,40 +2,57 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module LostInTranslation
         
     | 
| 
       4 
4 
     | 
    
         
             
              def self.recent
         
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
      
 5 
     | 
    
         
            +
                system 'clear'
         
     | 
| 
      
 6 
     | 
    
         
            +
                log
         
     | 
| 
      
 7 
     | 
    
         
            +
                log 'What I18n-yaml files do you want to compare?'
         
     | 
| 
      
 8 
     | 
    
         
            +
                @master = ask_for_file(true) # lang path app_name
         
     | 
| 
      
 9 
     | 
    
         
            +
                @slave = ask_for_file(false)
         
     | 
| 
      
 10 
     | 
    
         
            +
                @copy = { path: "#{Rails.root}/config/locales/#{@master[:lang]}_copy.yml" }
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
      
 12 
     | 
    
         
            +
                raise 'Invalid Filepaths' unless File.exist?(@master[:path]) && File.exist?(@slave[:path])
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                FileUtils.cp( 
     | 
| 
       14 
     | 
    
         
            -
                `git checkout "#{ 
     | 
| 
      
 14 
     | 
    
         
            +
                FileUtils.cp(@master[:path], @copy[:path])
         
     | 
| 
      
 15 
     | 
    
         
            +
                `git checkout "#{@master[:path]}"`
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                 
     | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
      
 17 
     | 
    
         
            +
                @master[:copy_path], @slave[:copy_path], @copy[:copy_path] = prepare_for_edit([@master[:path], @slave[:path], @copy[:path]])
         
     | 
| 
      
 18 
     | 
    
         
            +
                FileUtils.mv(@copy[:path], @master[:path])
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
      
 20 
     | 
    
         
            +
                prepare_paths([@master[:copy_path], @slave[:copy_path], @copy[:copy_path]])
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                master_file = YAML.load_file(@master[:copy_path])
         
     | 
| 
      
 23 
     | 
    
         
            +
                master_copy_file = YAML.load_file(@copy[:copy_path])
         
     | 
| 
      
 24 
     | 
    
         
            +
                slave_file = YAML.load_file(@slave[:copy_path])
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                count = diff(master_copy_file[@master[:lang]], master_file[@master[:lang]], @master[:lang],
         
     | 
| 
      
 27 
     | 
    
         
            +
                             @slave[:lang], [@slave[:lang]], [], mode: 'count')
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                abort('Well, in that case, forget it!') unless ask_for_permission(@master[:lang], @slave[:lang], @master[:app_name], count)
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                new_strings_array = diff(master_copy_file[@master[:lang]], master_file[@master[:lang]], @master[:lang], @slave[:lang], [@slave[:lang]], [],
         
     | 
| 
      
 32 
     | 
    
         
            +
                                         diff_counter: 0, diff_count: count, mode: 'replace', slave_file: slave_file)
         
     | 
| 
       23 
33 
     | 
    
         | 
| 
       24 
34 
     | 
    
         
             
                new_strings_array.each do |string|
         
     | 
| 
       25 
     | 
    
         
            -
                   
     | 
| 
       26 
     | 
    
         
            -
                  result  
     | 
| 
       27 
     | 
    
         
            -
                  LostInTranslation.merge_hash(result, second)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  result = string_to_hash(string)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  merge_hash(result, slave_file)
         
     | 
| 
       28 
37 
     | 
    
         
             
                end
         
     | 
| 
       29 
38 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
                 
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
                sorted = false
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                if ask_for_sorting(@master[:lang], @master[:app_name])
         
     | 
| 
      
 42 
     | 
    
         
            +
                  master_file = sort_hash(master_file)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  File.open(@master[:copy_path], 'w') { |file| file.write(master_file.to_yaml(line_width: -1)) }
         
     | 
| 
      
 44 
     | 
    
         
            +
                  sorted = true
         
     | 
| 
       33 
45 
     | 
    
         
             
                end
         
     | 
| 
       34 
46 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
       36 
     | 
    
         
            -
                File.open( 
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 47 
     | 
    
         
            +
                slave_file = sort_hash(slave_file) if ask_for_sorting(@slave[:lang], @slave[:app_name])
         
     | 
| 
      
 48 
     | 
    
         
            +
                File.open(@slave[:copy_path], 'w') { |file| file.write(slave_file.to_yaml(line_width: -1)) }
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                postpare_paths([@master[:copy_path], @slave[:copy_path]])
         
     | 
| 
       38 
51 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                FileUtils. 
     | 
| 
      
 52 
     | 
    
         
            +
                FileUtils.cp(@master[:copy_path], @master[:path]) if sorted
         
     | 
| 
      
 53 
     | 
    
         
            +
                FileUtils.cp(@slave[:copy_path], @slave[:path])
         
     | 
| 
      
 54 
     | 
    
         
            +
                FileUtils.rm(@master[:copy_path])
         
     | 
| 
      
 55 
     | 
    
         
            +
                FileUtils.rm(@slave[:copy_path])
         
     | 
| 
      
 56 
     | 
    
         
            +
                FileUtils.rm(@copy[:copy_path])
         
     | 
| 
       40 
57 
     | 
    
         
             
              end
         
     | 
| 
       41 
58 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: lost_in_translation
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.6
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Datyv
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-10-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |