applocale 0.1.6 → 0.2.0
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.rb +3 -1
- data/lib/applocale/AppLocaleFile +50 -0
- data/lib/applocale/Command/init.rb +21 -29
- data/lib/applocale/Core/FindStrKey/find_str_key.rb +40 -0
- data/lib/applocale/Core/FindStrKey/find_str_key_ios.rb +210 -0
- data/lib/applocale/Core/FindStrKey/find_str_key_result.rb +72 -0
- data/lib/applocale/Core/GoogleHepler/google_helper.rb +74 -33
- data/lib/applocale/Core/ParseXLSX/parse_xlsx.rb +56 -28
- data/lib/applocale/Core/ParseXLSX/parse_xlsx_module.rb +39 -4
- data/lib/applocale/Core/ParserStringFile/parse_localized_resource.rb +54 -27
- data/lib/applocale/Core/ParserStringFile/parse_strings_file.rb +38 -19
- data/lib/applocale/Core/ParserStringFile/parse_xml_file.rb +25 -8
- data/lib/applocale/Core/convert_to_localefile.rb +40 -18
- data/lib/applocale/Core/init.rb +76 -14
- data/lib/applocale/Core/setting.rb +111 -10
- data/lib/applocale/Util/config_util.rb +348 -139
- data/lib/applocale/Util/error_util.rb +3 -2
- data/lib/applocale/Util/file_util.rb +28 -29
- data/lib/applocale/Util/injection.rb +79 -0
- data/lib/applocale/Util/regex_util.rb +14 -40
- data/lib/applocale/version.rb +1 -1
- metadata +27 -23
- data/lib/applocale/AppLocaleFile.yaml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03973ae877a51412ba43c0d8c8aa988c851f5e08
|
4
|
+
data.tar.gz: 1eebce14afd82cd736edc82df57aef6534ba371c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d4a6eb16589ed4841d480442e0bb37566e51ac24b1cc6467ac3e89e2f54cf6c19517024edf28065b2b0b8bc5d08cf3bf30f4fec90ef7a801656d452ae0e0c03
|
7
|
+
data.tar.gz: 8500bdebd7a1a510482ed8488db26f96bad97d8cbec273885f60be7154c4da6a19b4a18efbce7bab87c671a96cbbd07bdfc1262a856237e03827d94ce8e33992
|
data/lib/applocale.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
link: "https://docs.google.com/spreadsheets/d/1Wy2gN_DSw-TCU2gPCzqvYxLfFG5fyK5rodXs5MLUy8w"
|
2
|
+
platform: "#{platform}"
|
3
|
+
xlsxpath: "#{xlsxpath}"
|
4
|
+
#google_credentials_path: "#{google_credentials_path}"
|
5
|
+
langlist:
|
6
|
+
zh_TW: "#{path_zh_TW}"
|
7
|
+
zh_CN: "#{path_zh_CN}"
|
8
|
+
en_US: "#{path_en_US}"
|
9
|
+
sheetname:
|
10
|
+
Section1:
|
11
|
+
key_str: "Key"
|
12
|
+
en_US: "English"
|
13
|
+
zh_TW: "Chinese(Traditional)"
|
14
|
+
zh_CN: "Chinese(Simplified)"
|
15
|
+
Section2:
|
16
|
+
key_str: "Key"
|
17
|
+
en_US: "English"
|
18
|
+
zh_TW: "zh_TW"
|
19
|
+
zh_CN: "zh_CN"
|
20
|
+
Section3:
|
21
|
+
row: "3"
|
22
|
+
key: "A"
|
23
|
+
en_US: "B"
|
24
|
+
zh_TW: "C"
|
25
|
+
zh_CN: "D"
|
26
|
+
|
27
|
+
|
28
|
+
# def convent_to_locale(lang, key, value)
|
29
|
+
# return value
|
30
|
+
# end
|
31
|
+
|
32
|
+
# def before_convent_to_locale(lang, key, value)
|
33
|
+
# return value
|
34
|
+
# end
|
35
|
+
|
36
|
+
# def after_convent_to_locale(lang, key, value)
|
37
|
+
# return value
|
38
|
+
# end
|
39
|
+
|
40
|
+
# def parse_from_locale(lang, key, value)
|
41
|
+
# return value
|
42
|
+
# end
|
43
|
+
|
44
|
+
# def before_parse_from_locale(lang, key, value)
|
45
|
+
# return value
|
46
|
+
# end
|
47
|
+
|
48
|
+
# def after_parse_from_locale(lang, key, value)
|
49
|
+
# return value
|
50
|
+
# end
|
@@ -13,43 +13,29 @@ module Applocale
|
|
13
13
|
class Command
|
14
14
|
class Init < Thor
|
15
15
|
desc "init [platform]", "Create Config File, platform: ios | android"
|
16
|
-
|
16
|
+
option :path, :desc => "Project dir path"
|
17
17
|
def init(platform = nil)
|
18
|
-
|
19
|
-
if Dir["*.xcodeproj"].length > 0
|
20
|
-
platformsybom = Platform::IOS
|
21
|
-
elsif Dir[".gradle"].length > 0
|
22
|
-
platformsybom = Platform::ANDROID
|
23
|
-
else
|
24
|
-
self.class.help(shell)
|
25
|
-
Applocale::ErrorUtil::CommandError.new("Mssing [platform] : ios | android ").raise
|
26
|
-
end
|
27
|
-
else
|
28
|
-
platformsybom = Platform.init(platform)
|
29
|
-
end
|
30
|
-
|
31
|
-
if platformsybom.nil?
|
32
|
-
self.class.help(shell)
|
33
|
-
ErrorUtil::CommandError.new("Invalid [platform] : ios | android ").raise
|
34
|
-
else
|
35
|
-
ConfigUtil.create_configfile_ifneed(platformsybom)
|
36
|
-
end
|
18
|
+
Applocale.create_config_file(platform, options[:path])
|
37
19
|
end
|
38
20
|
|
39
21
|
desc "update", "Download xlsx and convert to localization string file"
|
40
|
-
option :
|
22
|
+
option :path, :desc => "Project dir path"
|
41
23
|
def update()
|
42
|
-
|
43
|
-
|
24
|
+
Applocale.start_update(options[:path])
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "update_local", "Convert local xlsx file to localization string file"
|
28
|
+
option :path, :desc => "Project dir path"
|
29
|
+
def update_local()
|
30
|
+
Applocale.start_local_update(nil,options[:path])
|
44
31
|
end
|
45
32
|
|
46
33
|
desc "reverse", "Convert localization string file to xlsx"
|
47
34
|
option :skip, :desc => "Skip Error"
|
35
|
+
option :path, :desc => "Project dir path"
|
48
36
|
def reverse()
|
49
37
|
is_skip = !options[:skip].nil?
|
50
|
-
|
51
|
-
Setting.printlog
|
52
|
-
Applocale::start_reverse(is_skip)
|
38
|
+
Applocale::start_reverse(is_skip, options[:path])
|
53
39
|
end
|
54
40
|
|
55
41
|
desc "version", "show the AppLocale verions"
|
@@ -57,9 +43,15 @@ module Applocale
|
|
57
43
|
puts Applocale::VERSION
|
58
44
|
end
|
59
45
|
|
60
|
-
desc "google_logout", "logout google account"
|
61
|
-
def google_logout()
|
62
|
-
|
46
|
+
# desc "google_logout", "logout google account"
|
47
|
+
# def google_logout()
|
48
|
+
# GoogleHelper.reset_loginacc
|
49
|
+
# end
|
50
|
+
|
51
|
+
desc "findkey [key]", "findkey for ios and convert to xlsx"
|
52
|
+
option :path, :desc => "Project dir path"
|
53
|
+
def findkey(key)
|
54
|
+
Applocale::findkey(key, options[:path])
|
63
55
|
end
|
64
56
|
end
|
65
57
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('../../../Util/platform.rb', __FILE__)
|
3
|
+
require File.expand_path('../find_str_key_ios', __FILE__)
|
4
|
+
require File.expand_path('../find_str_key_result', __FILE__)
|
5
|
+
|
6
|
+
module FindStrKey
|
7
|
+
class FindStrKeyObj
|
8
|
+
attr_accessor :value, :file, :line
|
9
|
+
def initialize(value, file, line)
|
10
|
+
self.value = value
|
11
|
+
self.file = file
|
12
|
+
self.line = line
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module FindStrKey
|
18
|
+
class FindValue
|
19
|
+
attr_accessor :platform, :proj_path, :report_folder, :key
|
20
|
+
def initialize(platform, proj_path, report_folder, key)
|
21
|
+
self.platform = platform
|
22
|
+
self.proj_path = proj_path
|
23
|
+
self.report_folder = report_folder
|
24
|
+
self.key = key
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def find()
|
29
|
+
if platform == Applocale::Platform::IOS
|
30
|
+
findobj = FindStrKey::FindValueIOS.new(self.proj_path, self.key)
|
31
|
+
purekey_result_ordered, result_ordered = findobj.find
|
32
|
+
gen = FindStrKey::GenReport.new(self.proj_path, self.report_folder,purekey_result_ordered, result_ordered)
|
33
|
+
gen.gen_xlsx
|
34
|
+
gen.gen_txt
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,210 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
module FindStrKey
|
5
|
+
class FindValueIOS
|
6
|
+
attr_accessor :proj_path, :key
|
7
|
+
def initialize( proj_path, key)
|
8
|
+
self.proj_path = proj_path
|
9
|
+
self.key = key
|
10
|
+
end
|
11
|
+
|
12
|
+
def find()
|
13
|
+
arrOfObj = Array.new
|
14
|
+
files = Dir.glob("#{self.proj_path}/**/*.{swift}")
|
15
|
+
files.each do |file|
|
16
|
+
if /^Pods\/|\/Pods\//.match(file)
|
17
|
+
next
|
18
|
+
end
|
19
|
+
arr = findInFile(file)
|
20
|
+
arrOfObj.concat arr
|
21
|
+
end
|
22
|
+
resultInPureKey, result = groupResult(arrOfObj)
|
23
|
+
|
24
|
+
keysarr = resultInPureKey.keys.map { |_key| {:key => _key.downcase, :realkey => _key}}
|
25
|
+
keys_ordered = keysarr.sort_by {|value| value[:key]}
|
26
|
+
resultInPureKey_ordered = keys_ordered.map{|value| resultInPureKey[value[:realkey]]}
|
27
|
+
|
28
|
+
keysarr = result.keys.map { |_key| {:key => _key.downcase, :realkey => _key}}
|
29
|
+
keys_ordered = keysarr.sort_by {|value| value[:key]}
|
30
|
+
result_ordered = keys_ordered.map{|value| result[value[:realkey]]}
|
31
|
+
return resultInPureKey_ordered, result_ordered
|
32
|
+
end
|
33
|
+
|
34
|
+
def findInFile(file)
|
35
|
+
puts "processing #{file}"
|
36
|
+
result = Array.new
|
37
|
+
lineNum = 0
|
38
|
+
lines = IO.readlines(file).map do |line|
|
39
|
+
lineNum += 1
|
40
|
+
arrOfValue = self.getValueWithInKey(line)
|
41
|
+
if arrOfValue.length > 0
|
42
|
+
arrOfObj = arrOfValue.map { |value| FindStrKeyObj.new(value,file,lineNum)}
|
43
|
+
result.concat arrOfObj
|
44
|
+
end
|
45
|
+
end
|
46
|
+
return result
|
47
|
+
end
|
48
|
+
|
49
|
+
def getValueWithInKey(orgline)
|
50
|
+
result = Array.new
|
51
|
+
regex = /((?:[^\w]+#{self.key}\()(.*)|^(?:#{self.key}\()(.*))/
|
52
|
+
if orgline.match(regex)
|
53
|
+
matchedArr = orgline.scan(regex)
|
54
|
+
matchedArr.each do |matchedValue|
|
55
|
+
if matchedValue[1].to_s.length > 0
|
56
|
+
value, line = self.parse_token(matchedValue[1])
|
57
|
+
else
|
58
|
+
value, line = self.parse_token(matchedValue[2])
|
59
|
+
end
|
60
|
+
if value.strip.length > 0
|
61
|
+
result.push(value.strip)
|
62
|
+
end
|
63
|
+
if line.length > 0
|
64
|
+
arr = self.getValueWithInKey(line)
|
65
|
+
if arr.length > 0
|
66
|
+
result.concat arr
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
return result
|
72
|
+
end
|
73
|
+
|
74
|
+
def parse_token(line)
|
75
|
+
n = 0
|
76
|
+
in_value = false
|
77
|
+
in_quote = false
|
78
|
+
in_escape = false
|
79
|
+
value = ""
|
80
|
+
num_open = 0
|
81
|
+
|
82
|
+
for ch in line.chars
|
83
|
+
prech = ""
|
84
|
+
prech = line.chars[n-1] if n > 0
|
85
|
+
n += 1
|
86
|
+
|
87
|
+
if not in_value
|
88
|
+
if ch == "\""
|
89
|
+
in_quote = true
|
90
|
+
in_value = true
|
91
|
+
elsif ch != " " and ch != "\t"
|
92
|
+
in_value = true
|
93
|
+
value << ch
|
94
|
+
end
|
95
|
+
next
|
96
|
+
end
|
97
|
+
|
98
|
+
if in_escape
|
99
|
+
value << prech
|
100
|
+
value << ch
|
101
|
+
in_escape = false
|
102
|
+
elsif ch == "\\"
|
103
|
+
in_escape = true
|
104
|
+
elsif in_quote
|
105
|
+
if ch == "\""
|
106
|
+
in_quote = false
|
107
|
+
else
|
108
|
+
value << ch
|
109
|
+
end
|
110
|
+
else
|
111
|
+
if ch == "("
|
112
|
+
num_open += 1
|
113
|
+
elsif ch == ")"
|
114
|
+
if num_open <= 0
|
115
|
+
break
|
116
|
+
end
|
117
|
+
num_open -= 1
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
value = ""
|
122
|
+
if line.chars.length > 1
|
123
|
+
value = line[0..n-2]
|
124
|
+
end
|
125
|
+
return value, line[n..-1]
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
def groupResult(arrOfObj)
|
131
|
+
list = {}
|
132
|
+
purekeylist = {}
|
133
|
+
arrOfObj.each do |item|
|
134
|
+
value = isPureValue(item.value)
|
135
|
+
arr = Array.new
|
136
|
+
if value.nil?
|
137
|
+
value = item.value
|
138
|
+
if !list[value].nil?
|
139
|
+
arr = list[value]
|
140
|
+
end
|
141
|
+
arr.push(item)
|
142
|
+
list[value] = arr
|
143
|
+
else
|
144
|
+
item.value = value
|
145
|
+
if !purekeylist[value].nil?
|
146
|
+
arr = purekeylist[value]
|
147
|
+
end
|
148
|
+
arr.push(item)
|
149
|
+
purekeylist[value] = arr
|
150
|
+
end
|
151
|
+
end
|
152
|
+
return purekeylist, list
|
153
|
+
end
|
154
|
+
|
155
|
+
def isPureValue(aline)
|
156
|
+
n = 0
|
157
|
+
in_value = false
|
158
|
+
in_quote = false
|
159
|
+
in_escape = false
|
160
|
+
value = ""
|
161
|
+
line = aline.strip
|
162
|
+
for ch in line.chars
|
163
|
+
prech = ""
|
164
|
+
prech = line.chars[n-1] if n > 0
|
165
|
+
n += 1
|
166
|
+
|
167
|
+
if not in_value
|
168
|
+
if ch == "\""
|
169
|
+
in_quote = true
|
170
|
+
in_value = true
|
171
|
+
elsif ch != " " and ch != "\t"
|
172
|
+
return nil
|
173
|
+
end
|
174
|
+
next
|
175
|
+
end
|
176
|
+
|
177
|
+
if in_escape
|
178
|
+
value << prech
|
179
|
+
value << ch
|
180
|
+
in_escape = false
|
181
|
+
elsif ch == "\\"
|
182
|
+
in_escape = true
|
183
|
+
elsif in_quote
|
184
|
+
if ch == "\""
|
185
|
+
break
|
186
|
+
else
|
187
|
+
value << ch
|
188
|
+
end
|
189
|
+
else
|
190
|
+
value << ch
|
191
|
+
end
|
192
|
+
end
|
193
|
+
remained = line[n..-1]
|
194
|
+
if remained.strip.length > 0
|
195
|
+
return nil
|
196
|
+
else
|
197
|
+
regex = /\\\(.*\)/
|
198
|
+
if line.match(regex)
|
199
|
+
return nil
|
200
|
+
end
|
201
|
+
if line.length > 2
|
202
|
+
return line[1..n-2]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
return nil
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path('../find_str_key', __FILE__)
|
2
|
+
|
3
|
+
require 'rubyXL'
|
4
|
+
require 'colorize'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
module FindStrKey
|
8
|
+
class GenReport
|
9
|
+
DEFAULT_XLSX = 'findkey_result.xlsx'
|
10
|
+
DEFAULT_TXT = 'findkey_result.txt'
|
11
|
+
|
12
|
+
attr_accessor :proj_path, :path, :main_result, :second_result
|
13
|
+
|
14
|
+
def initialize(proj_path, path, main_result, second_result)
|
15
|
+
self.proj_path = proj_path
|
16
|
+
self.path = path
|
17
|
+
self.main_result = main_result
|
18
|
+
self.second_result = second_result
|
19
|
+
end
|
20
|
+
|
21
|
+
def gen_xlsx
|
22
|
+
xlsx_path = File.join(self.path, DEFAULT_XLSX)
|
23
|
+
File.delete(xlsx_path) if File.exist? xlsx_path
|
24
|
+
self.write_to_xlsx(xlsx_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def write_to_xlsx(xlsx_path)
|
28
|
+
puts "Start write to file: \"#{xlsx_path}\" ...".green
|
29
|
+
workbook = RubyXL::Workbook.new
|
30
|
+
worksheet = workbook.worksheets[0]
|
31
|
+
rowno = 0
|
32
|
+
keycolno = 0
|
33
|
+
self.main_result.each do |arrs|
|
34
|
+
key = arrs.first.value
|
35
|
+
worksheet.add_cell(rowno, keycolno, key)
|
36
|
+
rowno += 1
|
37
|
+
end
|
38
|
+
worksheet.add_cell(rowno, 0, '')
|
39
|
+
worksheet.change_row_fill(rowno, 'fffacd')
|
40
|
+
rowno += 1
|
41
|
+
self.second_result.each do |arrs|
|
42
|
+
key = arrs.first.value
|
43
|
+
worksheet.add_cell(rowno, keycolno, key)
|
44
|
+
rowno += 1
|
45
|
+
end
|
46
|
+
workbook.write(xlsx_path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def gen_txt
|
50
|
+
txt_path = File.join(self.path, DEFAULT_TXT)
|
51
|
+
File.delete(txt_path) if File.exist? txt_path
|
52
|
+
self.write_to_txt(txt_path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_to_txt(txt_path)
|
56
|
+
puts "Start write to file: \"#{txt_path}\" ...".green
|
57
|
+
target = open(txt_path, 'w')
|
58
|
+
|
59
|
+
self.main_result.each do |arrs|
|
60
|
+
key = arrs.first.value
|
61
|
+
target.puts("#{key} : ")
|
62
|
+
arrs.each do |obj|
|
63
|
+
rpath = Pathname.new(obj.file).relative_path_from(Pathname.new(self.proj_path)).to_s
|
64
|
+
target.puts(" line-#{obj.line}:\t#{rpath}")
|
65
|
+
end
|
66
|
+
target.puts('')
|
67
|
+
end
|
68
|
+
target.close
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|