applocale 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/applocale/AppLocaleFile +2 -30
- data/lib/applocale/Command/init.rb +19 -5
- data/lib/applocale/Core/CompareStringFile/compare_string_file.rb +223 -0
- data/lib/applocale/Core/ParseCSV/parse_csv.rb +18 -5
- data/lib/applocale/Core/ParseXLSX/parse_xlsx.rb +13 -7
- data/lib/applocale/Core/ParserStringFile/parse_localized_resource.rb +5 -6
- data/lib/applocale/Core/ParserStringFile/parse_strings_file.rb +6 -16
- data/lib/applocale/Core/ParserStringFile/parse_xml_file.rb +7 -15
- data/lib/applocale/Core/convert_to_localefile.rb +14 -24
- data/lib/applocale/Core/init.rb +48 -11
- data/lib/applocale/Core/setting.rb +5 -1
- data/lib/applocale/Util/config_util.rb +22 -204
- data/lib/applocale/Util/convert_util.rb +71 -0
- data/lib/applocale/Util/error_util.rb +13 -0
- data/lib/applocale/Util/file_util.rb +8 -7
- data/lib/applocale/Util/regex_util.rb +1 -1
- data/lib/applocale/convert.rb +19 -0
- data/lib/applocale/version.rb +1 -1
- metadata +6 -4
- data/lib/applocale/Util/injection.rb +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a97e66f54bd439a61cf20ed5f4437b25f2ff105
|
4
|
+
data.tar.gz: d407f1d876105f666af854f3e8f276edc7c3ff47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcfb679486adde4bd7a8b494f43cc562b7dcb5c516e52d821916f5afbfc3728eec7809e11a582b7d35986fb713c797a6f57f3528d12a4d88acf5d6201ef1da98
|
7
|
+
data.tar.gz: 78bc79fe9ed3f26817c4940a70b8c88d60f9413b5dba5c518c45eb62ff266f2e6e1c4ba66d8b32fde91d03aeb0d2152579d2a2844232f4f9a3374ed4437255d1
|
data/lib/applocale/AppLocaleFile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
link: "https://docs.google.com/spreadsheets/d/1Wy2gN_DSw-TCU2gPCzqvYxLfFG5fyK5rodXs5MLUy8w"
|
2
2
|
platform: "#{platform}"
|
3
|
+
resource_folder: "#{resource_folder}"
|
3
4
|
xlsxpath: "#{xlsxpath}"
|
4
5
|
export_format: "#{export_format}"
|
5
6
|
#google_credentials_path: "#{google_credentials_path}"
|
@@ -25,33 +26,4 @@ sheetname:
|
|
25
26
|
zh_TW: "C"
|
26
27
|
zh_CN: "D"
|
27
28
|
isSkipEmptyKey: true
|
28
|
-
|
29
|
-
|
30
|
-
# def convent_to_locale(lang, key, value)
|
31
|
-
# return value
|
32
|
-
# end
|
33
|
-
|
34
|
-
# def before_convent_to_locale(lang, key, value)
|
35
|
-
# return value
|
36
|
-
# end
|
37
|
-
|
38
|
-
# def after_convent_to_locale(lang, key, value)
|
39
|
-
# return value
|
40
|
-
# end
|
41
|
-
|
42
|
-
# def parse_from_locale(lang, key, value)
|
43
|
-
# return value
|
44
|
-
# end
|
45
|
-
|
46
|
-
# def before_parse_from_locale(lang, key, value)
|
47
|
-
# return value
|
48
|
-
# end
|
49
|
-
|
50
|
-
# def after_parse_from_locale(lang, key, value)
|
51
|
-
# return value
|
52
|
-
# end
|
53
|
-
|
54
|
-
# def is_skip_by_key(sheetname, key)
|
55
|
-
# return true
|
56
|
-
# end
|
57
|
-
|
29
|
+
# convertFile: "convert.rb"
|
@@ -14,28 +14,32 @@ module Applocale
|
|
14
14
|
class Init < Thor
|
15
15
|
desc "init [platform]", "Create Config File, platform: ios | android | json"
|
16
16
|
option :path, :desc => "Project dir path"
|
17
|
+
option :config_file, :desc => "the filename of config, default AppLocaleFile"
|
17
18
|
def init(platform = nil)
|
18
|
-
Applocale.create_config_file(platform, options[:path])
|
19
|
+
Applocale.create_config_file(platform, options[:path], options[:config_file])
|
19
20
|
end
|
20
21
|
|
21
22
|
desc "update", "Download xlsx and convert to localization string file"
|
22
23
|
option :path, :desc => "Project dir path"
|
24
|
+
option :config_file, :desc => "the filename of config, default AppLocaleFile"
|
23
25
|
def update()
|
24
|
-
Applocale.start_update(options[:path])
|
26
|
+
Applocale.start_update(options[:path],options[:config_file])
|
25
27
|
end
|
26
28
|
|
27
29
|
desc "update_local", "Convert local xlsx file to localization string file"
|
28
30
|
option :path, :desc => "Project dir path"
|
31
|
+
option :config_file, :desc => "the filename of config, default AppLocaleFile"
|
29
32
|
def update_local()
|
30
|
-
Applocale.start_local_update(nil,options[:path])
|
33
|
+
Applocale.start_local_update(nil,options[:path], options[:config_file])
|
31
34
|
end
|
32
35
|
|
33
36
|
desc "reverse", "Convert localization string file to xlsx"
|
34
37
|
option :skip, :desc => "Skip Error"
|
35
38
|
option :path, :desc => "Project dir path"
|
39
|
+
option :config_file, :desc => "the filename of config, default AppLocaleFile"
|
36
40
|
def reverse()
|
37
41
|
is_skip = !options[:skip].nil?
|
38
|
-
Applocale::start_reverse(is_skip, options[:path])
|
42
|
+
Applocale::start_reverse(is_skip, options[:path],options[:config_file])
|
39
43
|
end
|
40
44
|
|
41
45
|
desc "version", "show the AppLocale verions"
|
@@ -50,9 +54,19 @@ module Applocale
|
|
50
54
|
|
51
55
|
desc "findkey [key]", "findkey for ios and convert to xlsx"
|
52
56
|
option :path, :desc => "Project dir path"
|
57
|
+
option :config_file, :desc => "the filename of config, default AppLocaleFile"
|
53
58
|
def findkey(key)
|
54
|
-
Applocale::findkey(key, options[:path])
|
59
|
+
Applocale::findkey(key, options[:path], options[:config_file])
|
55
60
|
end
|
61
|
+
|
62
|
+
|
63
|
+
desc "compare two string file", "compare two string file"
|
64
|
+
option :file2, :desc => "second file path"
|
65
|
+
def compare(file1, file2)
|
66
|
+
Applocale::compare(file1, file2)
|
67
|
+
end
|
68
|
+
|
56
69
|
end
|
57
70
|
end
|
58
71
|
end
|
72
|
+
|
@@ -0,0 +1,223 @@
|
|
1
|
+
require File.expand_path('../../../Util/platform.rb', __FILE__)
|
2
|
+
|
3
|
+
module Applocale
|
4
|
+
class CompareStringFile
|
5
|
+
|
6
|
+
attr_reader :in_multiline_comments, :platform, :file1, :file2, :errorlist
|
7
|
+
|
8
|
+
def initialize(platform, file1, file2)
|
9
|
+
@platform = platform
|
10
|
+
@file1 = file1
|
11
|
+
@file12 = file2
|
12
|
+
|
13
|
+
|
14
|
+
@errorlist = Array.new()
|
15
|
+
@platform = platform
|
16
|
+
|
17
|
+
obj1 = {}
|
18
|
+
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
|
+
end
|
26
|
+
compare(obj1,obj2)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def compare(obj1, obj2)
|
31
|
+
missingkeyInObj2 = Array.new
|
32
|
+
mismatch = Array.new
|
33
|
+
duplicateKey = Array.new
|
34
|
+
notSame = {}
|
35
|
+
nobj2 = obj2
|
36
|
+
obj1.each do |key, value|
|
37
|
+
if nobj2[key].nil?
|
38
|
+
missingkeyInObj2.push(key)
|
39
|
+
else
|
40
|
+
obj1Value = value
|
41
|
+
obj2Value = obj2[key]
|
42
|
+
if obj1Value.length != obj2Value.length
|
43
|
+
mismatch.push(key)
|
44
|
+
elsif obj1Value.length != 1
|
45
|
+
duplicateKey.push(key)
|
46
|
+
elsif obj1Value[0] != obj2Value[0]
|
47
|
+
notSame[key] = {obj1: obj1Value[0],obj2: obj2Value[0]}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
nobj2.delete(key)
|
51
|
+
end
|
52
|
+
puts "==> not Same value:"
|
53
|
+
notSame.each do |key, value|
|
54
|
+
puts "key = #{key}"
|
55
|
+
puts "#{value[:obj1]}<"
|
56
|
+
puts "#{value[:obj2]}<"
|
57
|
+
end
|
58
|
+
puts "==> duplicateKey"
|
59
|
+
puts duplicateKey
|
60
|
+
puts "==> mismatch"
|
61
|
+
puts mismatch
|
62
|
+
puts "==> missingkeyInObj2"
|
63
|
+
puts missingkeyInObj2
|
64
|
+
puts "==> missingKeyInObj1"
|
65
|
+
puts nobj2
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
def parse_aos_file(strings_path)
|
71
|
+
strings_keys = {}
|
72
|
+
|
73
|
+
return if !File.exist? strings_path
|
74
|
+
puts "Start to Parse xml file: \"#{strings_path}\" ...".green
|
75
|
+
|
76
|
+
xml_doc = Nokogiri::XML(File.open(strings_path))
|
77
|
+
string_nodes = xml_doc.xpath("//string")
|
78
|
+
string_nodes.each do |node|
|
79
|
+
key = node["name"]
|
80
|
+
value = node.content
|
81
|
+
if !key.nil? && key.strip.length > 0
|
82
|
+
if strings_keys[key].nil?
|
83
|
+
strings_keys[key] = Array.new
|
84
|
+
end
|
85
|
+
strings_keys[key].push(value)
|
86
|
+
|
87
|
+
# if @strings_keys[key].nil?
|
88
|
+
# @strings_keys[key] = Hash.new
|
89
|
+
# @keys_list.push(key)
|
90
|
+
# end
|
91
|
+
# if @strings_keys[key][lang.to_s].nil?
|
92
|
+
# @strings_keys[key][lang.to_s] = Hash.new
|
93
|
+
# @strings_keys[key][lang.to_s][:value] = self.remove_escape(lang, key, value)
|
94
|
+
# else
|
95
|
+
# error = ErrorUtil::ParseLocalizedError::DuplicateKey.new(key, -1, strings_path, lang, -1).raise
|
96
|
+
# end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
return strings_keys
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
def parse_ios_file(path)
|
104
|
+
strings_keys = {}
|
105
|
+
@in_multiline_comments = false
|
106
|
+
linenum = 0
|
107
|
+
begin
|
108
|
+
IO.foreach(path, mode: 'r:bom|utf-8') {|line|
|
109
|
+
linenum += 1
|
110
|
+
line.strip!
|
111
|
+
if !@in_multiline_comments
|
112
|
+
next if line.start_with?('#')
|
113
|
+
next if line.start_with?('//')
|
114
|
+
end
|
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
|
142
|
+
if strings_keys[key].nil?
|
143
|
+
strings_keys[key] = Array.new
|
144
|
+
end
|
145
|
+
strings_keys[key].push(value)
|
146
|
+
end
|
147
|
+
}
|
148
|
+
rescue Exception => e
|
149
|
+
puts e.message
|
150
|
+
ErrorUtil::ParseLocalizedError::InvalidFile.new(file1).raise
|
151
|
+
end
|
152
|
+
|
153
|
+
return strings_keys
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def parse_token(linenum, line, sep, file)
|
158
|
+
n = 0
|
159
|
+
in_value = false
|
160
|
+
in_quote = false
|
161
|
+
in_escape = false
|
162
|
+
value = ""
|
163
|
+
|
164
|
+
for ch in line.chars
|
165
|
+
prech = ""
|
166
|
+
prech = line.chars[n-1] if n > 0
|
167
|
+
n += 1
|
168
|
+
if @in_multiline_comments
|
169
|
+
if "#{prech}#{ch}" == "*/"
|
170
|
+
@in_multiline_comments = false
|
171
|
+
in_value = false
|
172
|
+
value = ""
|
173
|
+
end
|
174
|
+
next
|
175
|
+
end
|
176
|
+
|
177
|
+
if not in_value
|
178
|
+
if ch == "\""
|
179
|
+
in_quote = true
|
180
|
+
in_value = true
|
181
|
+
elsif ch != " " and ch != "\t" and ch != sep
|
182
|
+
in_value = true
|
183
|
+
value << ch
|
184
|
+
end
|
185
|
+
next
|
186
|
+
end
|
187
|
+
|
188
|
+
if in_escape
|
189
|
+
value << prech
|
190
|
+
value << ch
|
191
|
+
in_escape = false
|
192
|
+
elsif ch == "\\"
|
193
|
+
in_escape = true
|
194
|
+
elsif in_quote
|
195
|
+
if ch == "\""
|
196
|
+
break
|
197
|
+
else
|
198
|
+
value << ch
|
199
|
+
end
|
200
|
+
else
|
201
|
+
if ch == " " or ch == "\t" or ch == sep
|
202
|
+
n -= 1
|
203
|
+
break
|
204
|
+
elsif "#{prech}#{ch}" == "/*"
|
205
|
+
@in_multiline_comments = true
|
206
|
+
elsif "#{prech}#{ch}" == "//"
|
207
|
+
return value, ""
|
208
|
+
elsif ch == "#"
|
209
|
+
return value, ""
|
210
|
+
elsif "#{prech}#{ch}".length > 1
|
211
|
+
error = ErrorUtil::ParseLocalizedError::WrongFormat.new(file, "", linenum)
|
212
|
+
@errorlist.push(error)
|
213
|
+
return value, ""
|
214
|
+
else
|
215
|
+
value << ch
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
return value, line[n..-1]
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
end
|
@@ -2,6 +2,7 @@ require File.expand_path('../../setting.rb', __FILE__)
|
|
2
2
|
require File.expand_path('../../../Util/error_util.rb', __FILE__)
|
3
3
|
require File.expand_path('../../../Util/regex_util.rb', __FILE__)
|
4
4
|
require File.expand_path('../../ParseModel/parse_model_module.rb', __FILE__)
|
5
|
+
require File.expand_path('../../../Util/convert_util.rb', __FILE__)
|
5
6
|
|
6
7
|
require 'colorize'
|
7
8
|
require 'csv'
|
@@ -18,7 +19,7 @@ module Applocale
|
|
18
19
|
@langlist
|
19
20
|
@sheetobj_list
|
20
21
|
@is_skip_empty_key
|
21
|
-
@
|
22
|
+
@convertFile
|
22
23
|
|
23
24
|
|
24
25
|
def initialize(setting)
|
@@ -30,7 +31,7 @@ module Applocale
|
|
30
31
|
@allkey_dict = {}
|
31
32
|
@all_error = Array.new
|
32
33
|
@is_skip_empty_key = setting.is_skip_empty_key
|
33
|
-
@
|
34
|
+
@convertFile = setting.convert_file
|
34
35
|
# puts "Start to Parse CSV: \"#{csv_directory}\" ...".green
|
35
36
|
parse
|
36
37
|
end
|
@@ -56,8 +57,8 @@ module Applocale
|
|
56
57
|
row_content = parse_row(sheet_name, index, row, sheet_content.keyStr_with_colno, sheet_content.lang_with_colno_list)
|
57
58
|
next if row_content.nil?
|
58
59
|
toskip = false
|
59
|
-
if @
|
60
|
-
is_skip_by_key = @
|
60
|
+
if @convertFile.has_is_skip_by_key
|
61
|
+
is_skip_by_key = @convertFile.load_is_skip_by_key(sheet_name, row_content.key_str)
|
61
62
|
if is_skip_by_key.to_s.downcase == "true"
|
62
63
|
toskip = true
|
63
64
|
end
|
@@ -137,7 +138,19 @@ module Applocale
|
|
137
138
|
end
|
138
139
|
end
|
139
140
|
rowinfo = ParseModelModule::RowInfo.new(sheet_name, index, key_str)
|
140
|
-
|
141
|
+
|
142
|
+
arr = Array.new
|
143
|
+
language_header_list.each do |language_header|
|
144
|
+
value = row[language_header.colno] || ''
|
145
|
+
after_value = ContentUtil.from_excel(value)
|
146
|
+
if @convertFile.has_parse_from_excel_or_csv
|
147
|
+
value = @convertFile.load_parse_from_excel_or_csv(sheet_name, key_str, value, after_value)
|
148
|
+
else
|
149
|
+
value = after_value
|
150
|
+
end
|
151
|
+
arr.push([language_header.lang, value])
|
152
|
+
end
|
153
|
+
rowinfo.content_dict = Hash[arr]
|
141
154
|
rowinfo
|
142
155
|
end
|
143
156
|
|
@@ -3,6 +3,7 @@ require File.expand_path('../parse_xlsx_module.rb', __FILE__)
|
|
3
3
|
require File.expand_path('../../../Util/error_util.rb', __FILE__)
|
4
4
|
require File.expand_path('../../../Util/regex_util.rb', __FILE__)
|
5
5
|
require File.expand_path('../../ParseModel/parse_model_module.rb', __FILE__)
|
6
|
+
require File.expand_path('../../../Util/convert_util.rb', __FILE__)
|
6
7
|
|
7
8
|
require 'rubyXL'
|
8
9
|
require 'colorize'
|
@@ -24,7 +25,7 @@ module Applocale
|
|
24
25
|
@langlist
|
25
26
|
@sheetobj_list
|
26
27
|
@is_skip_empty_key
|
27
|
-
@
|
28
|
+
@convert_file
|
28
29
|
|
29
30
|
def initialize(setting)
|
30
31
|
@platform = setting.platform
|
@@ -36,7 +37,7 @@ module Applocale
|
|
36
37
|
@allkey_dict = {}
|
37
38
|
@all_error = Array.new
|
38
39
|
@is_skip_empty_key = setting.is_skip_empty_key
|
39
|
-
@
|
40
|
+
@convert_file = setting.convert_file
|
40
41
|
self.parse
|
41
42
|
end
|
42
43
|
|
@@ -135,8 +136,8 @@ module Applocale
|
|
135
136
|
end
|
136
137
|
|
137
138
|
unless keystr.nil?
|
138
|
-
if @
|
139
|
-
is_skip_by_key = @
|
139
|
+
if @convert_file.has_is_skip_by_key
|
140
|
+
is_skip_by_key = @convert_file.load_is_skip_by_key(sheetname, keystr)
|
140
141
|
if is_skip_by_key.to_s.downcase == "true"
|
141
142
|
return nil
|
142
143
|
end
|
@@ -147,7 +148,7 @@ module Applocale
|
|
147
148
|
val = cell && cell.value
|
148
149
|
cell_value = val.to_s
|
149
150
|
lang_name = lang_with_colno.lang
|
150
|
-
rowinfo.content_dict[lang_name] = convert_contect(cell_value)
|
151
|
+
rowinfo.content_dict[lang_name] = convert_contect(sheetname,keystr, cell_value)
|
151
152
|
end
|
152
153
|
return rowinfo
|
153
154
|
end
|
@@ -165,11 +166,16 @@ module Applocale
|
|
165
166
|
end
|
166
167
|
end
|
167
168
|
|
168
|
-
def convert_contect(cell_value)
|
169
|
+
def convert_contect(sheetname, key, cell_value)
|
169
170
|
if cell_value.nil?
|
170
171
|
return ''
|
171
172
|
else
|
172
|
-
|
173
|
+
value = ContentUtil.from_excel(cell_value)
|
174
|
+
if @convert_file.has_parse_from_excel_or_csv
|
175
|
+
return @convert_file.load_parse_from_excel_or_csv(sheetname, key, cell_value, value)
|
176
|
+
else
|
177
|
+
return value
|
178
|
+
end
|
173
179
|
end
|
174
180
|
end
|
175
181
|
|