lost_in_translation 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64cafc716734b1378b969b9d6b11c948e05053aa
4
- data.tar.gz: 5bfcc42177ec56cb73c8d1329957f1b003efc424
3
+ metadata.gz: f0faf76dd6e900232f9339662f1ee88e430bc3f0
4
+ data.tar.gz: bd0843ca90fcfcb4433d98befe7f889775ba9662
5
5
  SHA512:
6
- metadata.gz: eb67dec3972f76e8f50dda2011aec216999eeb09c5907f3dae34582e12b07809636e6500aefb65d8e98c509e0c4a65ffc34362e83784240028b14cd503057d50
7
- data.tar.gz: e2753025ed52be2e51081a8122a6c86865b3f47ceb66b01e8ac73c64ce33cf1d990de451d7fef017ae1afd34c12fe68c49c9b5251906407a5fa08d602f3cdb13
6
+ metadata.gz: b28e288ea6fe416352196ce74b9084466fcba9a8b5be27ecf12afb0eab374c63b5a949d81c2612e0195a1cddab8640dfae2932dc984721fbc14f65d0e0005a2e
7
+ data.tar.gz: c95b7867c1948d916d8f2c11e5ae995acb2045dc213fb3c6c2d9c1254691f087cb1f06e42d3156f75da25b6ee57d1f28e16c862cd2f5a9eed6635975cf49f703
data/.gitignore CHANGED
@@ -6,4 +6,3 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
- /tmp/*.yml
@@ -17,6 +17,14 @@ module LostInTranslation
17
17
  def self.root
18
18
  File.dirname __dir__
19
19
  end
20
+
21
+ def self.tmp_paths
22
+ tmp_paths = {}
23
+ tmp_paths[:copy] = "#{root}/tmp/tmp_master_copy.yml"
24
+ tmp_paths[:master] = "#{root}/tmp/tmp_master.yml"
25
+ tmp_paths[:slave] = "#{root}/tmp/tmp_slave.yml"
26
+ tmp_paths
27
+ end
20
28
  end
21
29
 
22
30
  #
@@ -2,15 +2,11 @@
2
2
 
3
3
  #
4
4
  module LostInTranslation
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
12
- end
13
- path_array
5
+ def self.prepare_for_edit(options = {})
6
+ paths = copy_paths
7
+ FileUtils.cp(options[:master], paths[:master]) if options[:master]
8
+ FileUtils.cp(options[:slave], paths[:slave]) if options[:slave]
9
+ FileUtils.cp(options[:copy], paths[:copy]) if options[:copy]
14
10
  end
15
11
 
16
12
  def self.prepare_paths(paths = [])
@@ -32,10 +28,16 @@ module LostInTranslation
32
28
  snippets << ['!', 'a_bang_sign']
33
29
  snippets << ['%', 'a_percentage_sign']
34
30
  snippets << ['a_bang_sign \'', '\'a_bang_sign']
35
- # snippets << ["&", "this_and_snippet_variable"]
36
31
  snippets
37
32
  end
38
33
 
34
+ def reset_tmp_files
35
+ paths = copy_paths
36
+ paths.each_value do |path|
37
+ File.open(path, 'w') { |file| file.write('') }
38
+ end
39
+ end
40
+
39
41
  private
40
42
 
41
43
  def self.prepare_yaml(path, post)
@@ -8,7 +8,11 @@ module LostInTranslation
8
8
  text = master ? "# Master (e.g. 'en'): " : "# Slave: (e.g. 'de'): "
9
9
  file = {}
10
10
  file[:lang] = [(print text), Readline.readline()][1]
11
- file[:path] = defined?(Rails) ? "#{Rails.root}/config/locales/#{file[:lang]}.yml" : ask_for_path(file)
11
+ file[:path] = defined?(Rails) ? "#{Rails.root}/config/locales/#{file[:lang]}.yml" : ask_for_path
12
+ unless File.exist?(file[:path])
13
+ log "File #{file[:path]} not found!"
14
+ file[:path] = ask_for_path
15
+ end
12
16
  file[:app_name] = Rails&.application&.class&.parent_name
13
17
  file
14
18
  end
@@ -63,11 +67,11 @@ module LostInTranslation
63
67
 
64
68
  private
65
69
 
66
- def self.ask_for_path(file)
70
+ def self.ask_for_path
67
71
  log
68
- log 'Please type in the absolute paths your locales?'
69
- log 'e.g. /home/youruser/Documents/your-awesome-app/config/locales'
72
+ log 'Please type in the absolute path your locale?'
73
+ log 'e.g. /home/youruser/Documents/your-awesome-app/config/locales/de.yml'
70
74
  path = [(print '# '), Readline.readline()][1]
71
- "#{path}/#{file[:lang]}.yml"
75
+ path
72
76
  end
73
77
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  #
4
4
  module LostInTranslation
5
- VERSION = '0.2.6'
5
+ VERSION = '0.2.7'
6
6
  end
@@ -9,14 +9,16 @@ module LostInTranslation
9
9
  log '!!! WARNING!!! This deletes the differences!!! Make a BACKUP!!! !!!'
10
10
  @master = ask_for_file(true) # lang path app_name
11
11
  @slave = ask_for_file(false)
12
+ paths = copy_paths
12
13
 
13
14
  raise 'Invalid Filepaths' unless File.exist?(@master[:path]) && File.exist?(@slave[:path])
14
15
 
15
- @master[:copy_path], @slave[:copy_path] = prepare_for_edit([@master[:path], @slave[:path]])
16
- prepare_paths([@master[:copy_path], @slave[:copy_path]])
16
+ prepare_for_edit(master: @master[:path], slave: @slave[:path])
17
17
 
18
- master_file = YAML.load_file(@master[:copy_path])
19
- slave_file = YAML.load_file(@slave[:copy_path])
18
+ prepare_paths([paths[:master], paths[:slave]])
19
+
20
+ master_file = YAML.load_file(paths[:master])
21
+ slave_file = YAML.load_file(paths[:slave])
20
22
 
21
23
  new_strings_array = diff(master_file[@master[:lang]], slave_file[@slave[:lang]], @master[:lang],
22
24
  @slave[:lang], [@slave[:lang]], [], mode: 'clean')
@@ -30,6 +32,7 @@ module LostInTranslation
30
32
 
31
33
  File.open(@master[:path], 'w') { |file| file.write(master_file.to_yaml) }
32
34
 
33
- postpare_paths([@master[:path], @slave[:lang]])
35
+ postpare_paths([@master[:path], @slave[:path]])
36
+ reset_tmp_files
34
37
  end
35
38
  end
@@ -8,15 +8,16 @@ module LostInTranslation
8
8
  log 'What I18n-yaml files do you want to compare?'
9
9
  @master = ask_for_file(true) # lang path app_name
10
10
  @slave = ask_for_file(false)
11
-
12
11
  raise 'Invalid Filepaths' unless File.exist?(@master[:path]) && File.exist?(@slave[:path])
13
12
 
14
- @master[:copy_path], @slave[:copy_path] = prepare_for_edit([@master[:path], @slave[:path]])
13
+ paths = copy_paths
14
+
15
+ prepare_for_edit(master: @master[:path], slave: @slave[:path])
15
16
 
16
- prepare_paths([@master[:copy_path], @slave[:copy_path]])
17
+ prepare_paths([paths[:master], paths[:slave]])
17
18
 
18
- master_file = YAML.load_file(@master[:copy_path])
19
- slave_file = YAML.load_file(@slave[:copy_path])
19
+ master_file = YAML.load_file(paths[:master])
20
+ slave_file = YAML.load_file(paths[:slave])
20
21
 
21
22
  count = diff(master_file[@master[:lang]], slave_file[@slave[:lang]], @master[:lang],
22
23
  @slave[:lang], [@slave[:lang]], [], mode: 'count')
@@ -37,17 +38,16 @@ module LostInTranslation
37
38
 
38
39
  if ask_for_sorting(@master[:lang], @master[:app_name])
39
40
  master_file = sort_hash(master_file)
40
- File.open(@master[:copy_path], 'w') { |file| file.write(master_file.to_yaml(line_width: -1)) }
41
+ File.open(paths[:master], 'w') { |file| file.write(master_file.to_yaml(line_width: -1)) }
41
42
  sorted = true
42
43
  end
43
44
  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)) }
45
+ File.open(paths[:slave], 'w') { |file| file.write(slave_file.to_yaml(line_width: -1)) }
45
46
 
46
- postpare_paths([@master[:copy_path], @slave[:copy_path]])
47
+ postpare_paths([paths[:master], paths[:slave]])
47
48
 
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])
49
+ FileUtils.cp(paths[:master], @master[:path]) if sorted
50
+ FileUtils.cp(paths[:slave], @slave[:path])
51
+ reset_tmp_files
52
52
  end
53
53
  end
@@ -8,20 +8,21 @@ module LostInTranslation
8
8
  @master = ask_for_file(true) # lang path app_name
9
9
  @slave = ask_for_file(false)
10
10
  @copy = { path: "#{Rails.root}/config/locales/#{@master[:lang]}_copy.yml" }
11
+ paths = copy_paths
11
12
 
12
13
  raise 'Invalid Filepaths' unless File.exist?(@master[:path]) && File.exist?(@slave[:path])
13
14
 
14
- FileUtils.cp(@master[:path], @copy[:path])
15
+ FileUtils.cp(@master[:path], paths[:copy])
15
16
  `git checkout "#{@master[:path]}"`
16
17
 
17
- @master[:copy_path], @slave[:copy_path], @copy[:copy_path] = prepare_for_edit([@master[:path], @slave[:path], @copy[:path]])
18
+ prepare_for_edit(master: @master[:path], slave: @slave[:path])
18
19
  FileUtils.mv(@copy[:path], @master[:path])
19
20
 
20
- prepare_paths([@master[:copy_path], @slave[:copy_path], @copy[:copy_path]])
21
+ prepare_paths([paths[:master], paths[:slave], paths[:copy]])
21
22
 
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])
23
+ master_file = YAML.load_file(paths[:master])
24
+ master_copy_file = YAML.load_file(paths[:copy])
25
+ slave_file = YAML.load_file(paths[:slave])
25
26
 
26
27
  count = diff(master_copy_file[@master[:lang]], master_file[@master[:lang]], @master[:lang],
27
28
  @slave[:lang], [@slave[:lang]], [], mode: 'count')
@@ -40,19 +41,17 @@ module LostInTranslation
40
41
 
41
42
  if ask_for_sorting(@master[:lang], @master[:app_name])
42
43
  master_file = sort_hash(master_file)
43
- File.open(@master[:copy_path], 'w') { |file| file.write(master_file.to_yaml(line_width: -1)) }
44
+ File.open(paths[:master], 'w') { |file| file.write(master_file.to_yaml(line_width: -1)) }
44
45
  sorted = true
45
46
  end
46
47
 
47
48
  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
+ File.open(paths[:slave], 'w') { |file| file.write(slave_file.to_yaml(line_width: -1)) }
49
50
 
50
- postpare_paths([@master[:copy_path], @slave[:copy_path]])
51
+ postpare_paths([paths[:master], paths[:slave]])
51
52
 
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])
53
+ FileUtils.cp(paths[:master], @master[:path]) if sorted
54
+ FileUtils.cp(paths[:slave], @slave[:path])
55
+ reset_tmp_files
57
56
  end
58
57
  end
data/lib/tasks/lit.rake CHANGED
@@ -30,7 +30,8 @@ end
30
30
  namespace :lit do
31
31
  desc 'Cleaning out the Yaml-Closet'
32
32
  task :cleanup do
33
- LostInTranslation.cleanup
33
+ return 'to_be_done'
34
+ # LostInTranslation.cleanup
34
35
  end
35
36
  end
36
37
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ['lib']
21
+ spec.require_paths = ['lib', 'tmp', 'spec']
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.11'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
File without changes
File without changes
data/tmp/tmp_slave.yml ADDED
File without changes
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.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datyv
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-19 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,6 +84,9 @@ files:
84
84
  - lib/lost_in_translation/z_recent.rb
85
85
  - lib/tasks/lit.rake
86
86
  - lost_in_translation.gemspec
87
+ - tmp/tmp_master.yml
88
+ - tmp/tmp_master_copy.yml
89
+ - tmp/tmp_slave.yml
87
90
  homepage: https://github.com/Datyv/lost_in_translation
88
91
  licenses:
89
92
  - MIT
@@ -92,6 +95,8 @@ post_install_message:
92
95
  rdoc_options: []
93
96
  require_paths:
94
97
  - lib
98
+ - tmp
99
+ - spec
95
100
  required_ruby_version: !ruby/object:Gem::Requirement
96
101
  requirements:
97
102
  - - ">="