lost_in_translation 0.2.2 → 0.2.3

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: 1b5ad5b54d21c5230363ffd5484b7ea677ab628e
4
- data.tar.gz: ce901a81a874616cb4c3dd91f209592861afaf76
3
+ metadata.gz: 44c189e98dbaa5e2445b268a39ac3f4cafea196e
4
+ data.tar.gz: f13226087c1a3a69cf605528ffb8a17e6e29b420
5
5
  SHA512:
6
- metadata.gz: db2cff3026ff8b913ec0149c92b735a17717f9ceb3868a1e15a7519d006ffff8ec277bd8d57adef022b989c29a6b3c8885f29385f2045a335e4d24b54f371683
7
- data.tar.gz: 5a086bf90a4b44a4f928fb25ca9f4634e27010c237a1cf2aabdc1597fefb3450475f6f7695eac4b260ded0ed7678c521071c14f14dcd795762fdcb5307500673
6
+ metadata.gz: fe1923dd3c0f86ab2a371beb85a5014686b8b5d46313035600ca223fca81fa52f70d6a050d56da27c10c85d614c4b882f44b1747f6a4b796c303def0575f16aa
7
+ data.tar.gz: 26a24b2ae38876256305ba55a65c70922b96c43f4d3018f3a9a6e3eea56c8a0961d8f3500ead0564de787d2c269c9c900c557383d211a0003bd1a0d3a3502b8b
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ # This is the configuration used to check the rubocop source code.
2
+
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.3
6
+ Exclude:
7
+ - 'vendor/**/*'
8
+ - 'spec/fixtures/**/*'
9
+ - 'db/functional_test_data.rb'
10
+ - 'db/schema.rb'
11
+
12
+ Lint/HandleExceptions:
13
+ Exclude:
14
+ - 'bin/rails'
15
+ - 'bin/rake'
16
+ - 'bin/rspec'
17
+
18
+ Style/Encoding:
19
+ Enabled: true
20
+
21
+ Style/NumericLiterals:
22
+ Enabled: false
23
+
24
+ Style/RescueModifier:
25
+ Enabled: false
26
+
27
+ Metrics/LineLength:
28
+ Max: 120
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in lost_in_translation.gemspec
data/README.md CHANGED
@@ -65,11 +65,11 @@ In this case you can use the Rails-Console and the Class -LostInTranslation-.
65
65
  rails c
66
66
  ```
67
67
  ```
68
- LostInTranslationMain.interactive
68
+ LostInTranslation.interactive
69
69
  or
70
- LostInTranslationMain.recent
70
+ LostInTranslation.recent
71
71
  or
72
- LostInTranslationMain.cleanup
72
+ LostInTranslation.cleanup
73
73
  ```
74
74
 
75
75
  #### Yet to come
data/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
7
9
 
8
- import "./lib/tasks/lit.rake"
10
+ import './lib/tasks/lit.rake'
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LostInTranslation
2
- def diff(root, compared, lang_1, lang_2, structure = [], max_count = 0, new_array = [])
4
+ def diff(root, compared, lang1, lang2, structure = [], _max_count = 0, new_array = [])
3
5
  count = 0
4
- root.each_pair do |key,value|
6
+ root.each_pair do |key, value|
5
7
  next_root = root[key]
6
8
  next_compared = compared.nil? ? nil : compared[key]
7
9
  new_structure = structure.dup << key
8
10
  if value.is_a? String
9
11
  if compared.nil? || compared[key].nil?
10
- new_val = ask_for_translation(value, new_structure, lang_1, lang_2)
12
+ new_val = ask_for_translation(value, new_structure, lang1, lang2)
11
13
  new_array << new_val unless new_val.nil?
12
14
  count += 1
13
15
  end
14
16
  end
15
- diff(next_root, next_compared, lang_1, lang_2, new_structure, new_array) if next_root.kind_of? Hash
17
+ diff(next_root, next_compared, lang1, lang2, new_structure, new_array) if next_root.is_a? Hash
16
18
  end
17
19
  new_array
18
20
  end
@@ -22,7 +24,7 @@ module LostInTranslation
22
24
  end
23
25
 
24
26
  def clean(root, compared, structure = [], new_array = [])
25
- root.each_pair do |key,value|
27
+ root.each_pair do |key, value|
26
28
  next_root = root[key]
27
29
  next_compared = compared.nil? ? nil : compared[key]
28
30
  new_structure = structure.dup << key
@@ -31,7 +33,7 @@ module LostInTranslation
31
33
  new_array << "#{new_structure.join('---')}-#{value}"
32
34
  end
33
35
  end
34
- clean(next_root, next_compared, new_structure, new_array) if next_root.kind_of? Hash
36
+ clean(next_root, next_compared, new_structure, new_array) if next_root.is_a? Hash
35
37
  end
36
38
  new_array
37
39
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LostInTranslation
2
- def prepare_paths(path_1, path_2, post)
3
- [path_1, path_2].each do |p|
4
+ def prepare_paths(path1, path2, post)
5
+ [path1, path2].each do |p|
4
6
  prepare_yaml(p, post)
5
7
  end
6
8
  end
7
9
 
8
- private
10
+ private
9
11
 
10
12
  def prepare_yaml(path, post)
11
13
  text = File.read(path)
@@ -17,31 +19,37 @@ private
17
19
  text = text.gsub(snippet.first, snippet.second)
18
20
  end
19
21
 
20
- if post
21
- variables = text.scan(/varyberryterry.*/)
22
- variables.each do |var|
23
- new_var = var.gsub(':', '')
24
- new_var = new_var.gsub('varyberryterry', ': &')
25
- text = text.gsub(var, new_var)
26
- end
27
- else
28
- variables = text.scan(/: &.*/)
29
- variables.each do |var|
30
- new_var = var.gsub(': &', 'varyberryterry')
31
- new_var += ':'
32
- text = text.gsub(var, new_var)
33
- end
22
+ text = post ? postpare(variables, text) : prepare(variables, text)
23
+
24
+ File.open(path, 'w') { |file| file.puts text }
25
+ end
26
+
27
+ def postpare(variables, text)
28
+ variables = text.scan(/varyberryterry.*/)
29
+ variables.each do |var|
30
+ new_var = var.delete(':')
31
+ new_var = new_var.gsub('varyberryterry', ': &')
32
+ text = text.gsub(var, new_var)
34
33
  end
34
+ text
35
+ end
35
36
 
36
- File.open(path, "w") {|file| file.puts text }
37
+ def prepare(variables, text)
38
+ variables = text.scan(/: &.*/)
39
+ variables.each do |var|
40
+ new_var = var.gsub(': &', 'varyberryterry')
41
+ new_var += ':'
42
+ text = text.gsub(var, new_var)
43
+ end
44
+ text
37
45
  end
38
46
 
39
47
  def define_snippets
40
48
  snippets = []
41
- snippets << ["<<", "a_greater_than_sign"]
42
- snippets << ["*", "an_asterik_sign"]
43
- snippets << ["!", "a_bang_sign"]
44
- snippets << ["%", "a_percentage_sign"]
49
+ snippets << ['<<', 'a_greater_than_sign']
50
+ snippets << ['*', 'an_asterik_sign']
51
+ snippets << ['!', 'a_bang_sign']
52
+ snippets << ['%', 'a_percentage_sign']
45
53
  snippets << ['a_bang_sign \'', '\'a_bang_sign']
46
54
  # snippets << ["&", "this_and_snippet_variable"]
47
55
  snippets
@@ -1,28 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
1
4
  module LostInTranslation
2
5
  def string_to_hash(string)
3
6
  array = string.split('---')
4
7
  value = array.pop
5
8
  arr = array.reverse
6
- arr[1..-1].inject({arr[0] => value}){ |memo, i| {i => memo} }
9
+ arr[1..-1].inject(arr[0] => value) { |memo, i| { i => memo } }
7
10
  end
8
11
 
9
12
  def merge_hash(merge_from, merge_to)
10
- unless merge_from.kind_of?(String) || merge_to.kind_of?(String)
11
- merged_hash = merge_to
12
- first_key = merge_from.keys.first
13
- if merge_to.has_key?(first_key)
14
- merged_hash[first_key] = merge_hash( merge_from[first_key], merge_to[first_key] )
15
- else
16
- merged_hash[first_key] = merge_from[first_key]
17
- end
18
- merged_hash
19
- end
13
+ return if merge_from.is_a?(String) || merge_to.is_a?(String)
14
+ merged_hash = merge_to
15
+ first_key = merge_from.keys.first
16
+ merged_hash[first_key] = if merge_to.key?(first_key)
17
+ merge_hash(merge_from[first_key], merge_to[first_key])
18
+ else
19
+ merge_from[first_key]
20
+ end
21
+ merged_hash
20
22
  end
21
23
 
22
-
23
24
  def sort_hash(object)
24
25
  return object unless object.is_a?(Hash)
25
- hash = Hash.new
26
+ hash = {}
26
27
  object.each { |k, v| hash[k] = sort_hash(v) }
27
28
  sorted = hash.sort { |a, b| a[0].to_s <=> b[0].to_s }
28
29
  hash.class[sorted]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'lost_in_translation'
2
4
  require 'rails'
3
5
  module LostInTranslation
@@ -5,7 +7,7 @@ module LostInTranslation
5
7
  railtie_name :lost_in_translation
6
8
 
7
9
  rake_tasks do
8
- load "tasks/translate.rake"
10
+ load 'tasks/lit.rake'
9
11
  end
10
12
  end
11
13
  end
@@ -1,54 +1,56 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LostInTranslation
2
- def ask_for_permission(lang_1, lang_2, app_name)
3
- system "clear"
4
- puts "Comparing Locales"
4
+ def ask_for_permission(lang1, lang2, app_name)
5
+ system 'clear'
6
+ puts 'Comparing Locales'
5
7
  puts "Application: #{app_name}" unless app_name.nil?
6
- puts "Master Locale: #{lang_1}.yml"
7
- puts "Slave Locale: #{lang_2}.yml"
8
- puts "Is this ok?[y/n]"
8
+ puts "Master Locale: #{lang1}.yml"
9
+ puts "Slave Locale: #{lang2}.yml"
10
+ puts 'Is this ok?[y/n]'
9
11
  a = STDIN.gets.chomp
10
12
  a == 'y' || a == 'Y'
11
13
  end
12
14
 
13
15
  def ask_for_languages
14
- system "clear"
15
- puts "What I18n-yaml files do you want to compare?"
16
- lang_1 = [(print "Master (e.g. 'en'): "), STDIN.gets.chomp][1]
17
- lang_2 = [(print "Slave: (e.g. 'de'): "), STDIN.gets.chomp][1]
18
- [lang_1, lang_2]
16
+ system 'clear'
17
+ puts '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]
19
21
  end
20
22
 
21
23
  def ask_for_max_count
22
- system "clear"
23
- puts "How many do you want to edit max?"
24
- max_count = [(print "Max. Count (default = 50000): "), STDIN.gets.chomp][1]
24
+ system 'clear'
25
+ puts 'How many do you want to edit max?'
26
+ max_count = [(print 'Max. Count (default = 50000): '), STDIN.gets.chomp][1]
25
27
  max_count
26
28
  end
27
29
 
28
30
  def ask_for_paths
29
- system "clear"
30
- puts "Please type in the absolute paths to the I18n-yaml file you want to compare?"
31
- puts "e.g. /home/youruser/Documents/your-awesome-app/config/locales/en.yml"
32
- path_1 = [(print "Master: "), STDIN.gets.chomp][1]
33
- path_2 = [(print "Slave:: "), STDIN.gets.chomp][1]
34
- [path_1,path_2]
31
+ system 'clear'
32
+ puts 'Please type in the absolute paths to the I18n-yaml file you want to compare?'
33
+ puts '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]
35
37
  end
36
38
 
37
- def ask_for_sorting(lang, app_name)
38
- system "clear"
39
+ def ask_for_sorting(lang, _app_name)
40
+ system 'clear'
39
41
  puts "Do you want the #{lang}.yml to be sorted?"
40
- puts "Alphabetically & Recursive (ASC)"
41
- puts "[y/n]"
42
+ puts 'Alphabetically & Recursive (ASC)'
43
+ puts '[y/n]'
42
44
  a = STDIN.gets.chomp
43
45
  a == 'y' || a == 'Y'
44
46
  end
45
47
 
46
- def ask_for_translation(value, new_structure, lang_1, lang_2)
47
- system "clear"
48
+ def ask_for_translation(value, new_structure, lang1, lang2)
49
+ system 'clear'
48
50
  new_s = new_structure.join('---')
49
51
  puts "#{new_s} is missing"
50
- puts "in #{lang_1}: #{value}"
51
- new_val = [(print lang_2 + ": "), STDIN.gets.chomp][1]
52
+ puts "in #{lang1}: #{value}"
53
+ new_val = [(print lang2 + ': '), STDIN.gets.chomp][1]
52
54
  new_val == '' ? nil : (new_s + '---' + new_val)
53
55
  end
54
56
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LostInTranslation
2
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
3
5
  end
@@ -1,36 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
1
4
  module LostInTranslation
2
5
  def cleanup
3
6
  if defined? Rails
4
- app_name = Rails.application.class.parent_name
5
- lang_2, lang_1 = LostInTranslationMain.ask_for_languages
6
- path_1 = "#{Rails.root}/config/locales/#{lang_1}.yml"
7
- path_2 = "#{Rails.root}/config/locales/#{lang_2}.yml"
7
+ lang2, lang1 = LostInTranslation.ask_for_languages
8
+ path1 = "#{Rails.root}/config/locales/#{lang1}.yml"
9
+ path2 = "#{Rails.root}/config/locales/#{lang2}.yml"
8
10
  else
9
- app_name = nil
10
- path_2, path_1 = LostInTranslationMain.ask_for_paths
11
+ path2, path1 = LostInTranslation.ask_for_paths
11
12
 
12
- lang_1 = LostInTranslationMain.get_locale(path_1)
13
- lang_2 = LostInTranslationMain.get_locale(path_2)
13
+ lang1 = LostInTranslation.get_locale(path1)
14
+ lang2 = LostInTranslation.get_locale(path2)
14
15
  end
15
16
 
16
- abort('NOPE') unless File.exist?(path_1) && File.exist?(path_2)
17
+ abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
17
18
 
18
- prepare_paths(path_1, path_2, false)
19
+ prepare_paths(path1, path2, false)
19
20
 
20
- first = YAML.load_file(path_1)
21
- second = YAML.load_file(path_2)
21
+ first = YAML.load_file(path1)
22
+ second = YAML.load_file(path2)
22
23
 
23
- new_strings_array = LostInTranslationMain.clean(first[lang_1], second[lang_2], [lang_2])
24
+ new_strings_array = LostInTranslation.clean(first[lang1], second[lang2], [lang2])
24
25
 
25
26
  first = {}
26
27
  new_strings_array.each do |string|
27
- string = string.split('---').map { |x| x == lang_2 ? x = lang_1 : x }.join('---')
28
- result = LostInTranslationMain.string_to_hash(string)
29
- LostInTranslationMain.merge_hash(result, first)
28
+ string = string.split('---').map { |x| x == lang2 ? lang1 : x }.join('---')
29
+ result = LostInTranslation.string_to_hash(string)
30
+ LostInTranslation.merge_hash(result, first)
30
31
  end
31
32
 
32
- File.open(path_1, 'w') { |file| file.write(first.to_yaml) }
33
+ File.open(path1, 'w') { |file| file.write(first.to_yaml) }
33
34
 
34
- prepare_paths(path_1, path_2, true)
35
+ prepare_paths(path1, path2, true)
35
36
  end
36
37
  end
@@ -1,32 +1,30 @@
1
1
  module LostInTranslation
2
2
  def full_automatic
3
3
  if defined? Rails
4
- app_name = Rails.application.class.parent_name
5
- lang_2, lang_1 = LostInTranslationMain.ask_for_languages
6
- path_1 = "#{Rails.root}/config/locales/#{lang_1}.yml"
7
- path_2 = "#{Rails.root}/config/locales/#{lang_2}.yml"
4
+ lang2, lang1 = LostInTranslation.ask_for_languages
5
+ path1 = "#{Rails.root}/config/locales/#{lang1}.yml"
6
+ path2 = "#{Rails.root}/config/locales/#{lang2}.yml"
8
7
  else
9
- app_name = nil
10
- path_2, path_1 = LostInTranslationMain.ask_for_paths
8
+ path2, path1 = LostInTranslation.ask_for_paths
11
9
 
12
- lang_1 = LostInTranslationMain.get_locale(path_1)
13
- lang_2 = LostInTranslationMain.get_locale(path_2)
10
+ lang1 = LostInTranslation.get_locale(path1)
11
+ lang2 = LostInTranslation.get_locale(path2)
14
12
  end
15
13
 
16
- abort('NOPE') unless File.exist?(path_1) && File.exist?(path_2)
14
+ abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
17
15
 
18
- first = YAML.load_file(path_1)
19
- second = YAML.load_file(path_2)
16
+ first = YAML.load_file(path1)
17
+ second = YAML.load_file(path2)
20
18
 
21
- new_strings_array = LostInTranslationMain.clean(first[lang_1], second[lang_2], [lang_2])
19
+ new_strings_array = LostInTranslation.clean(first[lang1], second[lang2], [lang2])
22
20
 
23
21
  first = {}
24
22
  new_strings_array.each do |string|
25
- string = string.split('---').map { |x| x == lang_2 ? x = lang_1 : x }.join('---')
26
- result = LostInTranslationMain.string_to_hash(string)
27
- LostInTranslationMain.merge_hash(result, first)
23
+ string = string.split('---').map { |x| x == lang2 ? lang1 : x }.join('---')
24
+ result = LostInTranslation.string_to_hash(string)
25
+ LostInTranslation.merge_hash(result, first)
28
26
  end
29
27
 
30
- File.open(path_1, 'w') { |file| file.write(first.to_yaml) }
28
+ File.open(path1, 'w') { |file| file.write(first.to_yaml) }
31
29
  end
32
30
  end
@@ -1,32 +1,30 @@
1
1
  module LostInTranslation
2
2
  def half_automatic
3
3
  if defined? Rails
4
- app_name = Rails.application.class.parent_name
5
- lang_2, lang_1 = LostInTranslationMain.ask_for_languages
6
- path_1 = "#{Rails.root}/config/locales/#{lang_1}.yml"
7
- path_2 = "#{Rails.root}/config/locales/#{lang_2}.yml"
4
+ lang2, lang1 = LostInTranslation.ask_for_languages
5
+ path1 = "#{Rails.root}/config/locales/#{lang1}.yml"
6
+ path2 = "#{Rails.root}/config/locales/#{lang2}.yml"
8
7
  else
9
- app_name = nil
10
- path_2, path_1 = LostInTranslationMain.ask_for_paths
8
+ path2, path1 = LostInTranslation.ask_for_paths
11
9
 
12
- lang_1 = LostInTranslationMain.get_locale(path_1)
13
- lang_2 = LostInTranslationMain.get_locale(path_2)
10
+ lang1 = LostInTranslation.get_locale(path1)
11
+ lang2 = LostInTranslation.get_locale(path2)
14
12
  end
15
13
 
16
- abort('NOPE') unless File.exist?(path_1) && File.exist?(path_2)
14
+ abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
17
15
 
18
- first = YAML.load_file(path_1)
19
- second = YAML.load_file(path_2)
16
+ first = YAML.load_file(path1)
17
+ second = YAML.load_file(path2)
20
18
 
21
- new_strings_array = LostInTranslationMain.clean(first[lang_1], second[lang_2], [lang_2])
19
+ new_strings_array = LostInTranslation.clean(first[lang1], second[lang2], [lang2])
22
20
 
23
21
  first = {}
24
22
  new_strings_array.each do |string|
25
- string = string.split('---').map { |x| x == lang_2 ? x = lang_1 : x }.join('---')
26
- result = LostInTranslationMain.string_to_hash(string)
27
- LostInTranslationMain.merge_hash(result, first)
23
+ string = string.split('---').map { |x| x == lang2 ? lang1 : x }.join('---')
24
+ result = LostInTranslation.string_to_hash(string)
25
+ LostInTranslation.merge_hash(result, first)
28
26
  end
29
27
 
30
- File.open(path_1, 'w') { |file| file.write(first.to_yaml) }
28
+ File.open(path1, 'w') { |file| file.write(first.to_yaml) }
31
29
  end
32
30
  end
@@ -2,41 +2,41 @@ module LostInTranslation
2
2
  def interactive
3
3
  if defined? Rails
4
4
  app_name = Rails.application.class.parent_name
5
- lang_1, lang_2 = LostInTranslationMain.ask_for_languages
6
- path_1 = "#{Rails.root}/config/locales/#{lang_1}.yml"
7
- path_2 = "#{Rails.root}/config/locales/#{lang_2}.yml"
5
+ lang1, lang2 = LostInTranslation.ask_for_languages
6
+ path1 = "#{Rails.root}/config/locales/#{lang1}.yml"
7
+ path2 = "#{Rails.root}/config/locales/#{lang2}.yml"
8
8
  else
9
9
  app_name = nil
10
- path_1, path_2 = LostInTranslationMain.ask_for_paths
10
+ path1, path2 = LostInTranslation.ask_for_paths
11
11
 
12
- lang_1 = LostInTranslationMain.get_locale(path_1)
13
- lang_2 = LostInTranslationMain.get_locale(path_2)
12
+ lang1 = LostInTranslation.get_locale(path1)
13
+ lang2 = LostInTranslation.get_locale(path2)
14
14
  end
15
15
 
16
- abort('NOPE') unless File.exist?(path_1) && File.exist?(path_2)
17
- abort('Well, in that case, forget it!') unless LostInTranslationMain.ask_for_permission(lang_1,lang_2,app_name)
16
+ abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
17
+ abort('Well, in that case, forget it!') unless LostInTranslation.ask_for_permission(lang1, lang2, app_name)
18
18
 
19
- prepare_paths(path_1, path_2, true)
20
- prepare_paths(path_1, path_2, false)
19
+ prepare_paths(path1, path2, true)
20
+ prepare_paths(path1, path2, false)
21
21
 
22
- first = YAML.load_file(path_1)
23
- second = YAML.load_file(path_2)
22
+ first = YAML.load_file(path1)
23
+ second = YAML.load_file(path2)
24
24
 
25
- new_strings_array = LostInTranslationMain.diff(first[lang_1], second[lang_2], lang_1, lang_2, [lang_2])
25
+ new_strings_array = LostInTranslation.diff(first[lang1], second[lang2], lang1, lang2, [lang2])
26
26
 
27
27
  new_strings_array.each do |string|
28
- result = LostInTranslationMain.string_to_hash(string)
29
- LostInTranslationMain.merge_hash(result, second)
28
+ result = LostInTranslation.string_to_hash(string)
29
+ LostInTranslation.merge_hash(result, second)
30
30
  end
31
31
 
32
- if LostInTranslationMain.ask_for_sorting(lang_1, app_name)
33
- first = LostInTranslationMain.sort_hash(first)
34
- File.open(path_1, 'w') { |file| file.write(first.to_yaml(line_width: -1)) }
32
+ if LostInTranslation.ask_for_sorting(lang1, app_name)
33
+ first = LostInTranslation.sort_hash(first)
34
+ File.open(path1, 'w') { |file| file.write(first.to_yaml(line_width: -1)) }
35
35
  end
36
36
 
37
- second = LostInTranslationMain.sort_hash(second) if LostInTranslationMain.ask_for_sorting(lang_2, app_name)
38
- File.open(path_2, 'w') { |file| file.write(second.to_yaml(line_width: -1)) }
37
+ second = LostInTranslation.sort_hash(second) if LostInTranslation.ask_for_sorting(lang2, app_name)
38
+ File.open(path2, 'w') { |file| file.write(second.to_yaml(line_width: -1)) }
39
39
 
40
- prepare_paths(path_1, path_2, true)
40
+ prepare_paths(path1, path2, true)
41
41
  end
42
42
  end
@@ -1,38 +1,38 @@
1
1
  module LostInTranslation
2
2
  def recent
3
3
  app_name = Rails.application.class.parent_name
4
- lang_1, lang_2 = LostInTranslationMain.ask_for_languages
5
- path_1 = "#{Rails.root}/config/locales/#{lang_1}.yml"
6
- copy_path_1 = "#{Rails.root}/config/locales/#{lang_1}_copy.yml"
7
- path_2 = "#{Rails.root}/config/locales/#{lang_2}.yml"
4
+ lang1, lang2 = LostInTranslation.ask_for_languages
5
+ path1 = "#{Rails.root}/config/locales/#{lang1}.yml"
6
+ copy_path1 = "#{Rails.root}/config/locales/#{lang1}_copy.yml"
7
+ path2 = "#{Rails.root}/config/locales/#{lang2}.yml"
8
8
 
9
- abort('NOPE') unless File.exist?(path_1) && File.exist?(path_2)
9
+ abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
10
10
 
11
- FileUtils.cp(path_1, copy_path_1)
12
- `git checkout "#{path_1}"`
11
+ FileUtils.cp(path1, copy_path1)
12
+ `git checkout "#{path1}"`
13
13
 
14
- prepare_paths(path_1, copy_path_1, false)
14
+ prepare_paths(path1, copy_path1, false)
15
15
 
16
- first = YAML.load_file(path_1)
17
- first_copy = YAML.load_file(copy_path_1)
18
- second = YAML.load_file(path_2)
19
- new_strings_array = LostInTranslationMain.diff(first_copy[lang_1], first[lang_1], lang_1, lang_2, [lang_1])
16
+ first = YAML.load_file(path1)
17
+ first_copy = YAML.load_file(copy_path1)
18
+ second = YAML.load_file(path2)
19
+ new_strings_array = LostInTranslation.diff(first_copy[lang1], first[lang1], lang1, lang2, [lang1])
20
20
 
21
21
  new_strings_array.each do |string|
22
- string = string.split('---').map { |x| x == lang_1 ? x = lang_2 : x }.join('---')
23
- result = LostInTranslationMain.string_to_hash(string)
24
- LostInTranslationMain.merge_hash(result, second)
22
+ string = string.split('---').map { |x| x == lang1 ? lang2 : x }.join('---')
23
+ result = LostInTranslation.string_to_hash(string)
24
+ LostInTranslation.merge_hash(result, second)
25
25
  end
26
26
 
27
- if LostInTranslationMain.ask_for_sorting(lang_1, app_name)
28
- first_copy = LostInTranslationMain.sort_hash(first_copy)
29
- File.open(path_1, 'w') { |file| file.write(first_copy.to_yaml) }
27
+ if LostInTranslation.ask_for_sorting(lang1, app_name)
28
+ first_copy = LostInTranslation.sort_hash(first_copy)
29
+ File.open(path1, 'w') { |file| file.write(first_copy.to_yaml) }
30
30
  end
31
31
 
32
- second = LostInTranslationMain.sort_hash(second) if LostInTranslationMain.ask_for_sorting(lang_2, app_name)
33
- File.open(path_2, 'w') { |file| file.write(second.to_yaml) }
34
- prepare_paths(path_1, path_2, true)
32
+ second = LostInTranslation.sort_hash(second) if LostInTranslation.ask_for_sorting(lang2, app_name)
33
+ File.open(path2, 'w') { |file| file.write(second.to_yaml) }
34
+ prepare_paths(path1, path2, true)
35
35
 
36
- FileUtils.rm(copy_path_1)
36
+ FileUtils.rm(copy_path1)
37
37
  end
38
38
  end
@@ -1,19 +1,18 @@
1
- require "lost_in_translation/difference"
2
- require "lost_in_translation/file_functions"
3
- require "lost_in_translation/hash"
1
+ require 'lost_in_translation/difference'
2
+ require 'lost_in_translation/file_functions'
3
+ require 'lost_in_translation/hash'
4
4
  require 'lost_in_translation/railtie' if defined?(Rails)
5
- require "lost_in_translation/user_interface"
6
- require "lost_in_translation/version"
7
- require "lost_in_translation/z_recent"
8
- require "lost_in_translation/z_interactive"
9
- require "lost_in_translation/z_cleanup"
10
- require "lost_in_translation/z_half_automatic"
11
- require "lost_in_translation/z_full_automatic"
5
+ require 'lost_in_translation/user_interface'
6
+ require 'lost_in_translation/version'
7
+ require 'lost_in_translation/z_recent'
8
+ require 'lost_in_translation/z_interactive'
9
+ require 'lost_in_translation/z_cleanup'
10
+ require 'lost_in_translation/z_half_automatic'
11
+ require 'lost_in_translation/z_full_automatic'
12
12
 
13
13
  module LostInTranslation
14
-
15
14
  end
16
15
 
17
- class LostInTranslationMain
16
+ class LostInTranslation
18
17
  extend LostInTranslation
19
18
  end
data/lib/tasks/lit.rake CHANGED
@@ -1,41 +1,43 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'lost_in_translation'
3
5
  require 'fileutils'
4
6
 
5
7
  namespace :lit do
6
- desc "Make the locale-yamls equal again(Interactive)"
8
+ desc 'Make the locale-yamls equal again(Interactive)'
7
9
  task :interactive do
8
- LostInTranslationMain.interactive
10
+ LostInTranslation.interactive
9
11
  end
10
12
  end
11
13
 
12
14
  namespace :lit do
13
- desc "Use Bing-Translator as a suggestion for translation"
15
+ desc 'Use Bing-Translator as a suggestion for translation'
14
16
  task :half_automatic do
15
17
  return 'to_be_done'
16
- LostInTranslationMain.half_automatic
18
+ # LostInTranslation.half_automatic
17
19
  end
18
20
  end
19
21
 
20
22
  namespace :lit do
21
- desc "Use Bing-Translator to automatically translate everything"
23
+ desc 'Use Bing-Translator to automatically translate everything'
22
24
  task :fully_automatic do
23
25
  return 'to_be_done'
24
- LostInTranslationMain.full_automatic
26
+ # LostInTranslation.full_automatic
25
27
  end
26
28
  end
27
29
 
28
30
  namespace :lit do
29
- desc "Cleaning out the Yaml-Closet"
31
+ desc 'Cleaning out the Yaml-Closet'
30
32
  task :cleanup do
31
- LostInTranslationMain.cleanup
33
+ LostInTranslation.cleanup
32
34
  end
33
35
  end
34
36
 
35
37
  namespace :lit do
36
- desc "Tranlate just your recently changed Strings(requires git)"
38
+ desc 'Tranlate just your recently changed Strings(requires git)'
37
39
  task :recent do
38
40
  abort('Please use this feature inside a Rails-Application') unless defined? Rails
39
- LostInTranslationMain.recent
41
+ LostInTranslation.recent
40
42
  end
41
43
  end
@@ -1,25 +1,26 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'lost_in_translation/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "lost_in_translation"
8
+ spec.name = 'lost_in_translation'
8
9
  spec.version = LostInTranslation::VERSION
9
- spec.authors = ["Datyv"]
10
- spec.email = ["yvesgoizet@gmail.com"]
10
+ spec.authors = ['Datyv']
11
+ spec.email = ['yvesgoizet@gmail.com']
11
12
 
12
- spec.summary = %q{A Gem to compare two locale yamls}
13
- spec.description = %q{Take two locales yamls and merge them together with different values.}
14
- spec.homepage = "https://github.com/Datyv/lost_in_translation"
15
- spec.license = "MIT"
13
+ spec.summary = 'A Gem to compare two locale yamls'
14
+ spec.description = 'Take two locales yamls and merge them together with different values.'
15
+ spec.homepage = 'https://github.com/Datyv/lost_in_translation'
16
+ spec.license = 'MIT'
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
+ spec.bindir = 'exe'
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
21
22
 
22
- spec.add_development_dependency "bundler", "~> 1.11"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency 'bundler', '~> 1.11'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
26
  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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datyv
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-30 00:00:00.000000000 Z
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
+ - ".rubocop.yml"
64
65
  - ".travis.yml"
65
66
  - CODE_OF_CONDUCT.md
66
67
  - Gemfile
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  version: '0'
104
105
  requirements: []
105
106
  rubyforge_project:
106
- rubygems_version: 2.5.1
107
+ rubygems_version: 2.5.2
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: A Gem to compare two locale yamls