applocale 0.4.3 → 0.4.4
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/lib/applocale/Command/init.rb +7 -0
- data/lib/applocale/Core/CompareStringFile/compare_string_file.rb +42 -61
- data/lib/applocale/Core/CompareStringFile/compare_string_files.rb +71 -0
- data/lib/applocale/Core/GoogleHepler/google_helper.rb +4 -4
- data/lib/applocale/Core/init.rb +26 -1
- data/lib/applocale/Util/compare_util.rb +38 -0
- data/lib/applocale/Util/config_util.rb +4 -2
- data/lib/applocale/Util/error_util.rb +17 -0
- data/lib/applocale/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '01887bf2b6b99b1f368a205cae7736aceec40f65'
|
4
|
+
data.tar.gz: a7fbb56a6f7f4db100a8bc67c74392d3474fe475
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1055690a659e1dcf3f7ed58d878efc15fbce3dd8dceb0dc714ae2b3f7e633ac13a835370cfc5a3b11dfde48f212dca5f0be76a8c9a468392eb72cf2354fe80bc
|
7
|
+
data.tar.gz: 7798338941273dcfe286a656bfa9d105fcdf88208b872f576c122aa936aea85ea680b0a8beacee9a26ca5c816c9616447fdf1568ab32ab9e5d447eb5f3c217e2
|
@@ -66,6 +66,13 @@ module Applocale
|
|
66
66
|
Applocale::compare(file1, file2)
|
67
67
|
end
|
68
68
|
|
69
|
+
desc "compare the local results of two AppLocale files", "compare the local results of two AppLocale files"
|
70
|
+
option :path, :desc => "Project dir path"
|
71
|
+
option :result_file, :desc => "Comparison Result file path"
|
72
|
+
def compare_local(file1, file2)
|
73
|
+
Applocale::compare_local(file1, file2, options[:path], options[:result_file])
|
74
|
+
end
|
75
|
+
|
69
76
|
end
|
70
77
|
end
|
71
78
|
end
|
@@ -3,31 +3,34 @@ require File.expand_path('../../../Util/platform.rb', __FILE__)
|
|
3
3
|
module Applocale
|
4
4
|
class CompareStringFile
|
5
5
|
|
6
|
-
attr_reader :in_multiline_comments, :platform, :file1, :file2, :errorlist
|
6
|
+
attr_reader :in_multiline_comments, :platform, :file1, :file2, :errorlist, :print_result, :lang
|
7
7
|
|
8
|
-
def initialize(platform, file1, file2)
|
8
|
+
def initialize(platform, file1, file2, lang = nil, print_result = true)
|
9
9
|
@platform = platform
|
10
10
|
@file1 = file1
|
11
|
-
@
|
12
|
-
|
13
|
-
|
11
|
+
@file2 = file2
|
14
12
|
@errorlist = Array.new()
|
15
13
|
@platform = platform
|
14
|
+
@print_result = print_result
|
15
|
+
@lang = lang
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.compare(lang_path_obj)
|
19
|
+
Applocale::CompareStringFile.new(lang_path_obj.platform, lang_path_obj.filepath1, lang_path_obj.filepath2, lang_path_obj.lang, false).compare
|
20
|
+
end
|
16
21
|
|
22
|
+
def compare
|
17
23
|
obj1 = {}
|
18
24
|
obj2 = {}
|
19
|
-
if platform == Platform::IOS
|
20
|
-
obj1 = parse_ios_file(file1)
|
21
|
-
obj2 = parse_ios_file(file2)
|
22
|
-
elsif platform == Platform::ANDROID
|
23
|
-
obj1 = parse_aos_file(file1)
|
24
|
-
obj2 = parse_aos_file(file2)
|
25
|
+
if @platform == Platform::IOS
|
26
|
+
obj1 = parse_ios_file(@file1)
|
27
|
+
obj2 = parse_ios_file(@file2)
|
28
|
+
elsif @platform == Platform::ANDROID
|
29
|
+
obj1 = parse_aos_file(@file1)
|
30
|
+
obj2 = parse_aos_file(@file2)
|
25
31
|
end
|
26
|
-
compare(obj1,obj2)
|
27
|
-
end
|
28
32
|
|
29
33
|
|
30
|
-
def compare(obj1, obj2)
|
31
34
|
missingkeyInObj2 = Array.new
|
32
35
|
mismatch = Array.new
|
33
36
|
duplicateKey = Array.new
|
@@ -49,20 +52,28 @@ module Applocale
|
|
49
52
|
end
|
50
53
|
nobj2.delete(key)
|
51
54
|
end
|
52
|
-
|
53
|
-
notSame.
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
missingKeyInObj1 = nobj2.keys
|
56
|
+
notSameKeys = notSame.keys
|
57
|
+
comparison_result = Applocale::Config::LangPathComparisonResult.init(@platform, @lang, @file1, @file2, notSameKeys, duplicateKey, mismatch, missingKeyInObj1, missingkeyInObj2)
|
58
|
+
|
59
|
+
if @print_result
|
60
|
+
puts "==> not Same value:"
|
61
|
+
notSame.each do |key, value|
|
62
|
+
puts "key = #{key}"
|
63
|
+
puts "#{value[:obj1]}<"
|
64
|
+
puts "#{value[:obj2]}<"
|
65
|
+
end
|
66
|
+
puts "==> duplicateKey"
|
67
|
+
puts duplicateKey
|
68
|
+
puts "==> mismatch"
|
69
|
+
puts mismatch
|
70
|
+
puts "==> missingkeyInObj2"
|
71
|
+
puts missingkeyInObj2
|
72
|
+
puts "==> missingKeyInObj1"
|
73
|
+
puts missingKeyInObj1
|
57
74
|
end
|
58
|
-
|
59
|
-
|
60
|
-
puts "==> mismatch"
|
61
|
-
puts mismatch
|
62
|
-
puts "==> missingkeyInObj2"
|
63
|
-
puts missingkeyInObj2
|
64
|
-
puts "==> missingKeyInObj1"
|
65
|
-
puts nobj2
|
75
|
+
|
76
|
+
comparison_result
|
66
77
|
end
|
67
78
|
|
68
79
|
|
@@ -102,43 +113,13 @@ module Applocale
|
|
102
113
|
|
103
114
|
def parse_ios_file(path)
|
104
115
|
strings_keys = {}
|
105
|
-
@in_multiline_comments = false
|
106
|
-
linenum = 0
|
107
116
|
begin
|
108
117
|
IO.foreach(path, mode: 'r:bom|utf-8') {|line|
|
109
|
-
linenum += 1
|
110
118
|
line.strip!
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
if line.length <= 0
|
116
|
-
next
|
117
|
-
end
|
118
|
-
|
119
|
-
while true
|
120
|
-
key, line = parse_token(linenum, line, "=", path)
|
121
|
-
line.strip!
|
122
|
-
|
123
|
-
if not line.start_with?("=")
|
124
|
-
if !@in_multiline_comments && line.length > 0
|
125
|
-
error = ErrorUtil::ParseLocalizedError::WrongFormat.new(path, "", linenum).raise
|
126
|
-
end
|
127
|
-
break
|
128
|
-
end
|
129
|
-
line.slice!(0)
|
130
|
-
|
131
|
-
value, line = parse_token(linenum, line, ";", path)
|
132
|
-
line.strip!
|
133
|
-
|
134
|
-
if line.start_with?(";")
|
135
|
-
line.slice!(0)
|
136
|
-
else
|
137
|
-
error = ErrorUtil::ParseLocalizedError::WrongFormat.new(path, "", linenum).raise
|
138
|
-
key = nil
|
139
|
-
value = nil
|
140
|
-
break
|
141
|
-
end
|
119
|
+
match = line.match(/"(.*?)" = "(.*)";/)
|
120
|
+
unless match.nil?
|
121
|
+
key = match.captures[0]
|
122
|
+
value = match.captures[1]
|
142
123
|
if strings_keys[key].nil?
|
143
124
|
strings_keys[key] = Array.new
|
144
125
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'parallel'
|
2
|
+
require 'csv'
|
3
|
+
require File.expand_path('../../../Util/platform.rb', __FILE__)
|
4
|
+
require File.expand_path('../../../Util/compare_util.rb', __FILE__)
|
5
|
+
require File.expand_path('../compare_string_file.rb', __FILE__)
|
6
|
+
|
7
|
+
module Applocale
|
8
|
+
class CompareStringFiles
|
9
|
+
attr_reader :platform, :applocale_file1, :applocale_file2, :setting1, :setting2, :langpath_comparison_list, :result_file
|
10
|
+
def compare_all
|
11
|
+
results = @langpath_comparison_list.map do |langpath_comparison|
|
12
|
+
lang = langpath_comparison.lang
|
13
|
+
file1 = langpath_comparison.filepath1
|
14
|
+
file2 = langpath_comparison.filepath2
|
15
|
+
if file1.nil? or file2.nil?
|
16
|
+
Applocale::Config::LangPathComparisonResult.new(langpath_comparison, "Warning: [#{lang}] missing files for comparison!!!!!")
|
17
|
+
else
|
18
|
+
Applocale::CompareStringFile.compare(langpath_comparison)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
results.each {| result |
|
22
|
+
unless result.warning.nil?
|
23
|
+
puts result.warning.yellow
|
24
|
+
end
|
25
|
+
}
|
26
|
+
write_result_to_csv(results)
|
27
|
+
puts "Comparison Finished, output: #{result_file} !!!".green
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(platform, applocale_file1, applocale_file2, setting1, setting2, result_file)
|
31
|
+
@platform = platform
|
32
|
+
@applocale_file1 = applocale_file1
|
33
|
+
@applocale_file2 = applocale_file2
|
34
|
+
@setting1 = setting1
|
35
|
+
@setting2 = setting2
|
36
|
+
@result_file = result_file
|
37
|
+
@langpath_comparison_list = @setting1.lang_path_list.map do |lang_path_obj|
|
38
|
+
file1 = lang_path_obj.filepath
|
39
|
+
file2 = @setting2.lang_path_list.detect { |e| e.lang == lang_path_obj.lang }&.filepath
|
40
|
+
Applocale::Config::LangPathComparison.new(platform, lang_path_obj.lang, file1, file2)
|
41
|
+
end
|
42
|
+
compare_all
|
43
|
+
end
|
44
|
+
|
45
|
+
def write_result_to_csv(results)
|
46
|
+
filtered_results = results.select do | result |
|
47
|
+
result.warning.nil?
|
48
|
+
end
|
49
|
+
columns = filtered_results
|
50
|
+
.map { |result| result.lang }
|
51
|
+
.flat_map do | lang |
|
52
|
+
["notSame", "duplicateKey", "mismatch", "missingKeyIn1st", "missingkeyIn2nd"].map { |column| "#{lang}: #{column}" }
|
53
|
+
end
|
54
|
+
values = filtered_results.flat_map { |result|
|
55
|
+
[result.not_same,
|
56
|
+
result.duplicate_key,
|
57
|
+
result.mismatch,
|
58
|
+
result.missing_in_1,
|
59
|
+
result.missing_in_2]
|
60
|
+
}
|
61
|
+
values_max_length = values.max { |a,b| a.length <=> b.length }.length
|
62
|
+
_first_value, *other_values = values
|
63
|
+
first_value = values_max_length.times.collect { |i| _first_value[i] }
|
64
|
+
csv_values = first_value.zip(*other_values)
|
65
|
+
CSV.open(@result_file, "w") do | csv |
|
66
|
+
csv << columns
|
67
|
+
csv_values.each { | row | csv << row }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -5,6 +5,7 @@ require 'googleauth/stores/file_token_store'
|
|
5
5
|
require 'fileutils'
|
6
6
|
require 'colorize'
|
7
7
|
require 'open-uri'
|
8
|
+
require 'parallel'
|
8
9
|
require File.expand_path('../../../Util/file_util.rb', __FILE__)
|
9
10
|
require File.expand_path('../../../Util/error_util.rb', __FILE__)
|
10
11
|
|
@@ -58,16 +59,15 @@ module Applocale
|
|
58
59
|
end
|
59
60
|
|
60
61
|
index = 0
|
61
|
-
|
62
|
+
Parallel.each(sheet_obj_list) do |sheet_obj|
|
62
63
|
sheet_name = sheet_obj.sheetname
|
63
64
|
file_path = File.expand_path("#{sheet_name}.csv", export_to)
|
64
65
|
if sheetMap[sheet_name].nil?
|
65
66
|
ErrorUtil::SheetNotExist.new(sheet_name).raise
|
66
67
|
end
|
67
|
-
puts "to download sheet: #{sheet_name}"
|
68
68
|
if !sheet_obj.obj.use_export
|
69
69
|
link = "https://docs.google.com/spreadsheets/d/#{self.spreadsheet_id}/gviz/tq?tqx=out:csv&sheet=#{sheet_name}&access_token=#{authorization.access_token}"
|
70
|
-
puts "
|
70
|
+
puts "\nto download sheet: #{sheet_name}\nhttps://docs.google.com/spreadsheets/d/#{self.spreadsheet_id}/gviz/tq?tqx=out:csv&sheet=#{sheet_name}&access_token=xxxxx"
|
71
71
|
csv = open(link)
|
72
72
|
IO.copy_stream(csv, file_path)
|
73
73
|
else
|
@@ -79,7 +79,7 @@ module Applocale
|
|
79
79
|
sleep(2)
|
80
80
|
end
|
81
81
|
link = "https://docs.google.com/spreadsheets/d/#{self.spreadsheet_id}/export?format=csv&gid=#{sheetMap[sheet_name]}&access_token=#{authorization.access_token}"
|
82
|
-
puts "
|
82
|
+
puts "\nto download sheet: #{sheet_name}\nhttps://docs.google.com/spreadsheets/d/#{self.spreadsheet_id}/export?format=csv&gid=#{sheetMap[sheet_name]}&access_token=xxxxx"
|
83
83
|
File.open(file_path, "wb") do |file|
|
84
84
|
file.write open(link).read
|
85
85
|
end
|
data/lib/applocale/Core/init.rb
CHANGED
@@ -9,6 +9,7 @@ require File.expand_path('../ParserStringFile/parse_localized_resource.rb', __FI
|
|
9
9
|
require File.expand_path('../convert_to_localefile', __FILE__)
|
10
10
|
require File.expand_path('../FindStrKey/find_str_key', __FILE__)
|
11
11
|
require File.expand_path('../CompareStringFile/compare_string_file', __FILE__)
|
12
|
+
require File.expand_path('../CompareStringFile/compare_string_files', __FILE__)
|
12
13
|
|
13
14
|
require 'open-uri'
|
14
15
|
|
@@ -128,6 +129,30 @@ module Applocale
|
|
128
129
|
platformsybom = Platform::ANDROID
|
129
130
|
end
|
130
131
|
|
131
|
-
Applocale::CompareStringFile.new(platformsybom,file1_path,file2_path)
|
132
|
+
Applocale::CompareStringFile.new(platformsybom,file1_path,file2_path).compare
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.compare_local(file1, file2, projpath = Dir.pwd, result_file)
|
136
|
+
puts 'Reminder: run `update` for both files before `compare`'.yellow
|
137
|
+
proj_path = projpath
|
138
|
+
proj_path = Dir.pwd if projpath.nil?
|
139
|
+
proj_apath = Applocale::FilePathUtil.get_proj_absoluat_path(proj_path)
|
140
|
+
obj1 = Applocale::Config::ConfigUtil.new(proj_apath, file1)
|
141
|
+
obj2 = Applocale::Config::ConfigUtil.new(proj_apath, file2)
|
142
|
+
setting1 = obj1.load_configfile_to_setting(false)
|
143
|
+
setting2 = obj2.load_configfile_to_setting(false)
|
144
|
+
platform1 = setting1.platform
|
145
|
+
platform2 = setting2.platform
|
146
|
+
if platform1 != platform2
|
147
|
+
ErrorUtil::FileMustSamePlatform.new.raise
|
148
|
+
end
|
149
|
+
if result_file.nil?
|
150
|
+
ErrorUtil::MissingComparisonResultFilePath.new.raise
|
151
|
+
end
|
152
|
+
if File.extname(result_file).strip.downcase[1..-1].downcase != 'csv'
|
153
|
+
ErrorUtil::NotSupportComparisonResultFileExtension.new.raise
|
154
|
+
end
|
155
|
+
result_file_path = File.join(proj_apath, FilePathUtil.default_mainfolder, result_file)
|
156
|
+
Applocale::CompareStringFiles.new(platform1, file1, file2, setting1, setting2, result_file_path)
|
132
157
|
end
|
133
158
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Applocale
|
2
|
+
module Config
|
3
|
+
class LangPathComparison
|
4
|
+
attr_accessor :platform, :lang, :filepath1, :filepath2
|
5
|
+
|
6
|
+
def initialize(platform, lang, filepath1, filepath2)
|
7
|
+
self.platform = platform
|
8
|
+
self.lang = lang
|
9
|
+
self.filepath1 = filepath1
|
10
|
+
self.filepath2 = filepath2
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.init(platform, lang, filepath1, filepath2)
|
14
|
+
LangPathComparison.new(platform, lang, filepath1, filepath2)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class LangPathComparisonResult < LangPathComparison
|
19
|
+
attr_accessor :platform, :lang, :filepath1, :filepath2, :warning, :not_same, :duplicate_key, :mismatch, :missing_in_1, :missing_in_2
|
20
|
+
|
21
|
+
def initialize(langpath_comparison, warning = nil)
|
22
|
+
super(langpath_comparison.platform, langpath_comparison.lang, langpath_comparison.filepath1, langpath_comparison.filepath2)
|
23
|
+
self.warning = warning
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.init(platform, lang, filepath1, filepath2, not_same, duplicate_key, mismatch, missing_in_1, missing_in_2)
|
27
|
+
langpath_comparison = LangPathComparison.init(platform, lang, filepath1, filepath2)
|
28
|
+
result = LangPathComparisonResult.new(langpath_comparison)
|
29
|
+
result.not_same = not_same
|
30
|
+
result.duplicate_key = duplicate_key
|
31
|
+
result.mismatch = mismatch
|
32
|
+
result.missing_in_1 = missing_in_1
|
33
|
+
result.missing_in_2 = missing_in_2
|
34
|
+
result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -75,7 +75,7 @@ module Applocale
|
|
75
75
|
end
|
76
76
|
|
77
77
|
public
|
78
|
-
def load_configfile_to_setting
|
78
|
+
def load_configfile_to_setting(printSetting = true)
|
79
79
|
error_list = Array.new
|
80
80
|
config_yaml = load_configfile
|
81
81
|
link = config_yaml['link'].to_s.strip
|
@@ -230,7 +230,9 @@ module Applocale
|
|
230
230
|
error = ErrorUtil::ConfigFileInValid.new("[isSkipEmptyKey] must be boolean ")
|
231
231
|
error_list.push(error)
|
232
232
|
end
|
233
|
-
|
233
|
+
if printSetting
|
234
|
+
setting.printlog
|
235
|
+
end
|
234
236
|
ErrorUtil::ConfigFileInValid.raiseArr(error_list)
|
235
237
|
return setting
|
236
238
|
end
|
@@ -23,6 +23,18 @@ module Applocale
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
class MissingComparisonResultFilePath < CommonError
|
27
|
+
def message
|
28
|
+
'Missing Comparison Result File path'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class NotSupportComparisonResultFileExtension < CommonError
|
33
|
+
def message
|
34
|
+
'Only support .csv for Comparison Result File'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
26
38
|
class ConfigFileInValid < CommonError
|
27
39
|
def self.raiseArr(list = nil)
|
28
40
|
if !list.nil? && list.length > 0
|
@@ -73,6 +85,11 @@ module Applocale
|
|
73
85
|
end
|
74
86
|
end
|
75
87
|
|
88
|
+
class FileMustSamePlatform < CommandError
|
89
|
+
def message
|
90
|
+
'Two platforms not same'
|
91
|
+
end
|
92
|
+
end
|
76
93
|
end
|
77
94
|
end
|
78
95
|
|
data/lib/applocale/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: applocale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kennix
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,20 @@ dependencies:
|
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: 3.3.23
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: parallel
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 1.11.2
|
124
|
+
type: :runtime
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - '='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.11.2
|
117
131
|
description: Applocale is a localization tool, It can convert file between string
|
118
132
|
and xlsx ,csv, also support download xlsx or csv from google. You can also setup
|
119
133
|
conversion logic for string value of each project. Support ios, android and json
|
@@ -132,6 +146,7 @@ files:
|
|
132
146
|
- lib/applocale/Command/init.rb
|
133
147
|
- lib/applocale/Core/Compare/compare_xlsx_str.rb
|
134
148
|
- lib/applocale/Core/CompareStringFile/compare_string_file.rb
|
149
|
+
- lib/applocale/Core/CompareStringFile/compare_string_files.rb
|
135
150
|
- lib/applocale/Core/FindStrKey/find_str_key.rb
|
136
151
|
- lib/applocale/Core/FindStrKey/find_str_key_ios.rb
|
137
152
|
- lib/applocale/Core/FindStrKey/find_str_key_result.rb
|
@@ -147,6 +162,7 @@ files:
|
|
147
162
|
- lib/applocale/Core/convert_to_localefile.rb
|
148
163
|
- lib/applocale/Core/init.rb
|
149
164
|
- lib/applocale/Core/setting.rb
|
165
|
+
- lib/applocale/Util/compare_util.rb
|
150
166
|
- lib/applocale/Util/config_util.rb
|
151
167
|
- lib/applocale/Util/convert_util.rb
|
152
168
|
- lib/applocale/Util/error_util.rb
|