lost_in_translation 0.2.2 → 0.2.3
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/.rubocop.yml +28 -0
- data/Gemfile +2 -0
- data/README.md +3 -3
- data/Rakefile +6 -4
- data/lib/lost_in_translation/difference.rb +8 -6
- data/lib/lost_in_translation/file_functions.rb +30 -22
- data/lib/lost_in_translation/hash.rb +14 -13
- data/lib/lost_in_translation/railtie.rb +3 -1
- data/lib/lost_in_translation/user_interface.rb +30 -28
- data/lib/lost_in_translation/version.rb +3 -1
- data/lib/lost_in_translation/z_cleanup.rb +19 -18
- data/lib/lost_in_translation/z_full_automatic.rb +14 -16
- data/lib/lost_in_translation/z_half_automatic.rb +14 -16
- data/lib/lost_in_translation/z_interactive.rb +21 -21
- data/lib/lost_in_translation/z_recent.rb +22 -22
- data/lib/lost_in_translation.rb +11 -12
- data/lib/tasks/lit.rake +12 -10
- data/lost_in_translation.gemspec +14 -13
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44c189e98dbaa5e2445b268a39ac3f4cafea196e
|
4
|
+
data.tar.gz: f13226087c1a3a69cf605528ffb8a17e6e29b420
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
-
|
68
|
+
LostInTranslation.interactive
|
69
69
|
or
|
70
|
-
|
70
|
+
LostInTranslation.recent
|
71
71
|
or
|
72
|
-
|
72
|
+
LostInTranslation.cleanup
|
73
73
|
```
|
74
74
|
|
75
75
|
#### Yet to come
|
data/Rakefile
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
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 :
|
8
|
+
task default: :spec
|
7
9
|
|
8
|
-
import
|
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,
|
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,
|
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,
|
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.
|
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(
|
3
|
-
[
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
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 << [
|
42
|
-
snippets << [
|
43
|
-
snippets << [
|
44
|
-
snippets << [
|
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(
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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 =
|
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
|
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(
|
3
|
-
system
|
4
|
-
puts
|
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: #{
|
7
|
-
puts "Slave Locale: #{
|
8
|
-
puts
|
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
|
15
|
-
puts
|
16
|
-
|
17
|
-
|
18
|
-
[
|
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
|
23
|
-
puts
|
24
|
-
max_count = [(print
|
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
|
30
|
-
puts
|
31
|
-
puts
|
32
|
-
|
33
|
-
|
34
|
-
[
|
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,
|
38
|
-
system
|
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
|
41
|
-
puts
|
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,
|
47
|
-
system
|
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 #{
|
51
|
-
new_val = [(print
|
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,36 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
1
4
|
module LostInTranslation
|
2
5
|
def cleanup
|
3
6
|
if defined? Rails
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
10
|
-
path_2, path_1 = LostInTranslationMain.ask_for_paths
|
11
|
+
path2, path1 = LostInTranslation.ask_for_paths
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
lang1 = LostInTranslation.get_locale(path1)
|
14
|
+
lang2 = LostInTranslation.get_locale(path2)
|
14
15
|
end
|
15
16
|
|
16
|
-
abort('NOPE') unless File.exist?(
|
17
|
+
abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
|
17
18
|
|
18
|
-
prepare_paths(
|
19
|
+
prepare_paths(path1, path2, false)
|
19
20
|
|
20
|
-
first = YAML.load_file(
|
21
|
-
second = YAML.load_file(
|
21
|
+
first = YAML.load_file(path1)
|
22
|
+
second = YAML.load_file(path2)
|
22
23
|
|
23
|
-
new_strings_array =
|
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 ==
|
28
|
-
result =
|
29
|
-
|
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(
|
33
|
+
File.open(path1, 'w') { |file| file.write(first.to_yaml) }
|
33
34
|
|
34
|
-
prepare_paths(
|
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
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
10
|
-
path_2, path_1 = LostInTranslationMain.ask_for_paths
|
8
|
+
path2, path1 = LostInTranslation.ask_for_paths
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
lang1 = LostInTranslation.get_locale(path1)
|
11
|
+
lang2 = LostInTranslation.get_locale(path2)
|
14
12
|
end
|
15
13
|
|
16
|
-
abort('NOPE') unless File.exist?(
|
14
|
+
abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
|
17
15
|
|
18
|
-
first = YAML.load_file(
|
19
|
-
second = YAML.load_file(
|
16
|
+
first = YAML.load_file(path1)
|
17
|
+
second = YAML.load_file(path2)
|
20
18
|
|
21
|
-
new_strings_array =
|
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 ==
|
26
|
-
result =
|
27
|
-
|
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(
|
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
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
10
|
-
path_2, path_1 = LostInTranslationMain.ask_for_paths
|
8
|
+
path2, path1 = LostInTranslation.ask_for_paths
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
lang1 = LostInTranslation.get_locale(path1)
|
11
|
+
lang2 = LostInTranslation.get_locale(path2)
|
14
12
|
end
|
15
13
|
|
16
|
-
abort('NOPE') unless File.exist?(
|
14
|
+
abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
|
17
15
|
|
18
|
-
first = YAML.load_file(
|
19
|
-
second = YAML.load_file(
|
16
|
+
first = YAML.load_file(path1)
|
17
|
+
second = YAML.load_file(path2)
|
20
18
|
|
21
|
-
new_strings_array =
|
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 ==
|
26
|
-
result =
|
27
|
-
|
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(
|
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
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
10
|
+
path1, path2 = LostInTranslation.ask_for_paths
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
lang1 = LostInTranslation.get_locale(path1)
|
13
|
+
lang2 = LostInTranslation.get_locale(path2)
|
14
14
|
end
|
15
15
|
|
16
|
-
abort('NOPE') unless File.exist?(
|
17
|
-
abort('Well, in that case, forget it!') unless
|
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(
|
20
|
-
prepare_paths(
|
19
|
+
prepare_paths(path1, path2, true)
|
20
|
+
prepare_paths(path1, path2, false)
|
21
21
|
|
22
|
-
first = YAML.load_file(
|
23
|
-
second = YAML.load_file(
|
22
|
+
first = YAML.load_file(path1)
|
23
|
+
second = YAML.load_file(path2)
|
24
24
|
|
25
|
-
new_strings_array =
|
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 =
|
29
|
-
|
28
|
+
result = LostInTranslation.string_to_hash(string)
|
29
|
+
LostInTranslation.merge_hash(result, second)
|
30
30
|
end
|
31
31
|
|
32
|
-
if
|
33
|
-
first =
|
34
|
-
File.open(
|
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 =
|
38
|
-
File.open(
|
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(
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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?(
|
9
|
+
abort('NOPE') unless File.exist?(path1) && File.exist?(path2)
|
10
10
|
|
11
|
-
FileUtils.cp(
|
12
|
-
`git checkout "#{
|
11
|
+
FileUtils.cp(path1, copy_path1)
|
12
|
+
`git checkout "#{path1}"`
|
13
13
|
|
14
|
-
prepare_paths(
|
14
|
+
prepare_paths(path1, copy_path1, false)
|
15
15
|
|
16
|
-
first = YAML.load_file(
|
17
|
-
first_copy = YAML.load_file(
|
18
|
-
second = YAML.load_file(
|
19
|
-
new_strings_array =
|
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 ==
|
23
|
-
result =
|
24
|
-
|
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
|
28
|
-
first_copy =
|
29
|
-
File.open(
|
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 =
|
33
|
-
File.open(
|
34
|
-
prepare_paths(
|
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(
|
36
|
+
FileUtils.rm(copy_path1)
|
37
37
|
end
|
38
38
|
end
|
data/lib/lost_in_translation.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
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
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
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
|
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
|
8
|
+
desc 'Make the locale-yamls equal again(Interactive)'
|
7
9
|
task :interactive do
|
8
|
-
|
10
|
+
LostInTranslation.interactive
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
14
|
namespace :lit do
|
13
|
-
desc
|
15
|
+
desc 'Use Bing-Translator as a suggestion for translation'
|
14
16
|
task :half_automatic do
|
15
17
|
return 'to_be_done'
|
16
|
-
|
18
|
+
# LostInTranslation.half_automatic
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
namespace :lit do
|
21
|
-
desc
|
23
|
+
desc 'Use Bing-Translator to automatically translate everything'
|
22
24
|
task :fully_automatic do
|
23
25
|
return 'to_be_done'
|
24
|
-
|
26
|
+
# LostInTranslation.full_automatic
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
namespace :lit do
|
29
|
-
desc
|
31
|
+
desc 'Cleaning out the Yaml-Closet'
|
30
32
|
task :cleanup do
|
31
|
-
|
33
|
+
LostInTranslation.cleanup
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
37
|
namespace :lit do
|
36
|
-
desc
|
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
|
-
|
41
|
+
LostInTranslation.recent
|
40
42
|
end
|
41
43
|
end
|
data/lost_in_translation.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
#
|
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 =
|
8
|
+
spec.name = 'lost_in_translation'
|
8
9
|
spec.version = LostInTranslation::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Datyv']
|
11
|
+
spec.email = ['yvesgoizet@gmail.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
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 =
|
19
|
+
spec.bindir = 'exe'
|
19
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
21
22
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
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.
|
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-
|
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.
|
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
|