applocale 0.1.6 → 0.2.0

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: d8a3d2e9639b64d0195e08d56c8eb4bddad5047e
4
- data.tar.gz: bf35772ae682f62e3d25a1306ccb35846a99ca0a
3
+ metadata.gz: 03973ae877a51412ba43c0d8c8aa988c851f5e08
4
+ data.tar.gz: 1eebce14afd82cd736edc82df57aef6534ba371c
5
5
  SHA512:
6
- metadata.gz: b832d97fbca33447d720741edc8b6f49cedfe66e1d5fb0ce2329085c593c924ba117b31b83a5eef4efb5d24aedeba7bd53acb97cd331a978531a88595f39a82b
7
- data.tar.gz: 953267d9af703d35d4ec785441deec78b1766fec7edca5e9af97d5f80b6bb3b4f28c5f69e9104f85da7dead678924fa3245e93ea151e2c55451731a847ab9e1b
6
+ metadata.gz: 7d4a6eb16589ed4841d480442e0bb37566e51ac24b1cc6467ac3e89e2f54cf6c19517024edf28065b2b0b8bc5d08cf3bf30f4fec90ef7a801656d452ae0e0c03
7
+ data.tar.gz: 8500bdebd7a1a510482ed8488db26f96bad97d8cbec273885f60be7154c4da6a19b4a18efbce7bab87c671a96cbbd07bdfc1262a856237e03827d94ce8e33992
@@ -6,4 +6,6 @@ module Applocale
6
6
  # Your code goes here...
7
7
  end
8
8
 
9
- Applocale::Command::Init.start(ARGV)
9
+ if ARGV.length > 0
10
+ Applocale::Command::Init.start(ARGV)
11
+ end
@@ -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
- if platform.nil?
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 :local, :desc => "Convert local xlsx file to localization string file"
22
+ option :path, :desc => "Project dir path"
41
23
  def update()
42
- is_local = !options[:local].nil?
43
- Applocale.start_update(is_local)
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
- ConfigUtil.load_and_validate_localefile_to_xlsx()
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
- GoogleHelper.reset_loginacc
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
+