pixab 1.7.1 → 1.7.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/lib/LocalizationSmartcat.rb +92 -57
- data/lib/pixab/version.rb +1 -1
- data/pixab.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84d54a1ab3a12281357538f78851d2b729803cf110e51570a17f2ee0e1c480de
|
4
|
+
data.tar.gz: 2223cb8f2541517bcde9f0490cc064061043ddfc964d42d93d4ea953eaf2e417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: feb82c51f413c5a117ef86728574aa5498f9d5a13181eef65c555fc10b525af202f94dddbbf13f08b5b56c105dbb9fa0eb7e2fa376a1d95b8706b36ee0767c62
|
7
|
+
data.tar.gz: 43ad564e1d758c1ed30bc929207af08c25e5426b33f8a59f80b731d8d055881f93afb37a0017428759ae511a37b00feaf140924c358594e15b6a3ca339b85390
|
data/lib/LocalizationSmartcat.rb
CHANGED
@@ -2,8 +2,7 @@ require 'net/http'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'zip'
|
4
4
|
require 'colored2'
|
5
|
-
require '
|
6
|
-
include REXML
|
5
|
+
require 'nokogiri'
|
7
6
|
|
8
7
|
module Pixab
|
9
8
|
|
@@ -15,6 +14,7 @@ module Pixab
|
|
15
14
|
Localization_FILE_NAME = 'Localization.zip'
|
16
15
|
|
17
16
|
Project_AirBrush = '6cd2db15-6325-43ae-9087-f78aca9bec9a'
|
17
|
+
Project_AirBrushVideo = '16cbeffd-bb6e-46e8-a32e-9c79d23a796f'
|
18
18
|
|
19
19
|
attr_accessor :projects, :tags, :platform, :collections
|
20
20
|
|
@@ -35,6 +35,14 @@ module Pixab
|
|
35
35
|
@platform = 'iOS'
|
36
36
|
@tags = 'iOS'
|
37
37
|
@collections = 'AirBrush'
|
38
|
+
when '--abv-iOS'
|
39
|
+
@projects = Project_AirBrushVideo
|
40
|
+
@platform = 'iOS'
|
41
|
+
@tags = 'iOS'
|
42
|
+
when '--abv-android'
|
43
|
+
@projects = Project_AirBrushVideo
|
44
|
+
@platform = 'android'
|
45
|
+
@tags = 'android'
|
38
46
|
end
|
39
47
|
end
|
40
48
|
|
@@ -84,17 +92,7 @@ module Pixab
|
|
84
92
|
end
|
85
93
|
|
86
94
|
# 第二步:循环尝试下载ZIP文件
|
87
|
-
def download_zip_file_with_retry(download_url, export_id, max_retries=
|
88
|
-
# 加载动画字符
|
89
|
-
spinner = Enumerator.new do |e|
|
90
|
-
loop do
|
91
|
-
e.yield '|'
|
92
|
-
e.yield '/'
|
93
|
-
e.yield '-'
|
94
|
-
e.yield '\\'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
95
|
+
def download_zip_file_with_retry(download_url, export_id, max_retries=60)
|
98
96
|
retries = 0
|
99
97
|
while retries < max_retries
|
100
98
|
uri = URI("#{download_url}/#{export_id}")
|
@@ -109,13 +107,11 @@ module Pixab
|
|
109
107
|
File.open(Localization_FILE_NAME, "wb") { |file| file.write(response.body) }
|
110
108
|
return true
|
111
109
|
else
|
112
|
-
# 等待1秒后重试
|
113
|
-
# 打印动画字符
|
114
|
-
print "\r#{spinner.next}"
|
115
|
-
sleep 0.5
|
116
|
-
print "\r#{spinner.next}"
|
117
|
-
sleep 0.5
|
118
110
|
retries += 1
|
111
|
+
dots = '.' * retries
|
112
|
+
print "\r#{dots}"
|
113
|
+
# 等待1秒后重试
|
114
|
+
sleep 1
|
119
115
|
end
|
120
116
|
end
|
121
117
|
|
@@ -145,10 +141,12 @@ module Pixab
|
|
145
141
|
f_path = extract_localization_file_path(f.name)
|
146
142
|
FileUtils.mkdir_p(File.dirname(f_path))
|
147
143
|
content = f.get_input_stream.read
|
148
|
-
|
149
|
-
|
144
|
+
if projects == Project_AirBrush
|
145
|
+
content = content.gsub(/=\s*".*";/) do |match|
|
146
|
+
match.gsub('%s', '%@')
|
147
|
+
end
|
150
148
|
end
|
151
|
-
File.write(f_path,
|
149
|
+
File.write(f_path, content)
|
152
150
|
end
|
153
151
|
end
|
154
152
|
|
@@ -160,16 +158,13 @@ module Pixab
|
|
160
158
|
f_path = extract_localization_file_path(f.name)
|
161
159
|
FileUtils.mkdir_p(File.dirname(f_path))
|
162
160
|
content = f.get_input_stream.read
|
163
|
-
document =
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
169
|
-
# 将修改后的XML内容写入新文件
|
170
|
-
File.open(f_path, 'w') do |file|
|
171
|
-
document.write(file)
|
161
|
+
document = Nokogiri::XML(content)
|
162
|
+
document.traverse do |node|
|
163
|
+
if node.text?
|
164
|
+
node.content = node.content.gsub(/['"]/, '\\\\\0')
|
165
|
+
end
|
172
166
|
end
|
167
|
+
File.write(f_path, document.to_xml)
|
173
168
|
end
|
174
169
|
end
|
175
170
|
|
@@ -187,7 +182,11 @@ module Pixab
|
|
187
182
|
template = nil
|
188
183
|
if platform == 'android'
|
189
184
|
format = 'android-xml'
|
190
|
-
|
185
|
+
if projects == Project_AirBrush
|
186
|
+
template = '{LOCALE:ANDROID}/strings_ph.xml'
|
187
|
+
else
|
188
|
+
template = '{LOCALE:ANDROID}/strings.xml'
|
189
|
+
end
|
191
190
|
else
|
192
191
|
format = 'ios-strings'
|
193
192
|
template = '{LOCALE:IOS}.lproj/Localizable.strings'
|
@@ -204,39 +203,75 @@ module Pixab
|
|
204
203
|
end
|
205
204
|
|
206
205
|
def extract_localization_file_path(zip_file_path)
|
207
|
-
|
208
|
-
|
209
|
-
|
206
|
+
case projects
|
207
|
+
when Project_AirBrush
|
208
|
+
if platform.nil? || platform != 'android'
|
209
|
+
return zip_file_path
|
210
|
+
end
|
210
211
|
|
211
|
-
|
212
|
-
path = File.dirname(zip_file_path)
|
213
|
-
localization = ''
|
214
|
-
case path
|
215
|
-
when 'en'
|
212
|
+
path = File.dirname(zip_file_path)
|
216
213
|
localization = ''
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
214
|
+
case path
|
215
|
+
when 'en'
|
216
|
+
localization = ''
|
217
|
+
when 'fr'
|
218
|
+
localization = '-fr-rFR'
|
219
|
+
when 'ru'
|
220
|
+
localization = '-ru-rRU'
|
221
|
+
when 'zh-rHans'
|
222
|
+
localization = '-zh-rCN'
|
223
|
+
when 'tr'
|
224
|
+
localization = '-tr-rTR'
|
225
|
+
when 'pt-rBR'
|
226
|
+
localization = '-pt'
|
227
|
+
else
|
228
|
+
localization = "-#{path}"
|
229
|
+
end
|
230
|
+
return "values#{localization}/#{File.basename(zip_file_path)}"
|
231
|
+
|
232
|
+
when Project_AirBrushVideo
|
233
|
+
if platform.nil?
|
234
|
+
return zip_file_path
|
235
|
+
end
|
236
|
+
|
237
|
+
case platform
|
238
|
+
when 'android'
|
239
|
+
path = File.dirname(zip_file_path)
|
240
|
+
localization = ''
|
241
|
+
case path
|
242
|
+
when 'en'
|
243
|
+
localization = ''
|
244
|
+
when 'zh-rHans'
|
245
|
+
localization = '-zh-rCN'
|
246
|
+
when 'zh-rHant'
|
247
|
+
localization = '-zh-rHK'
|
248
|
+
else
|
249
|
+
localization = "-#{path}"
|
250
|
+
end
|
251
|
+
return "values#{localization}/#{File.basename(zip_file_path)}"
|
252
|
+
when 'iOS'
|
253
|
+
path = File.dirname(zip_file_path)
|
254
|
+
localization = zip_file_path
|
255
|
+
case path
|
256
|
+
when 'pt-PT.lproj'
|
257
|
+
localization = File.join('pt.lproj', File.basename(zip_file_path))
|
258
|
+
end
|
259
|
+
return localization
|
260
|
+
end
|
229
261
|
end
|
230
|
-
|
262
|
+
|
231
263
|
end
|
232
264
|
|
233
265
|
def is_ignored_file_path(file_path)
|
234
|
-
|
235
|
-
|
266
|
+
case projects
|
267
|
+
when Project_AirBrush
|
268
|
+
return false unless platform == 'android'
|
269
|
+
|
270
|
+
path = File.dirname(file_path)
|
271
|
+
return path == 'zh-rHant' ? true : false
|
236
272
|
end
|
237
273
|
|
238
|
-
|
239
|
-
return path == 'zh-rHant' ? true : false
|
274
|
+
return false
|
240
275
|
end
|
241
276
|
|
242
277
|
end
|
data/lib/pixab/version.rb
CHANGED
data/pixab.gemspec
CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
# Uncomment to register a new dependency of your gem
|
36
36
|
spec.add_dependency "colored2"
|
37
37
|
spec.add_dependency 'rubyzip'
|
38
|
+
spec.add_dependency 'nokogiri'
|
38
39
|
|
39
40
|
# For more information and examples about making a new gem, check out our
|
40
41
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 廖再润
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored2
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: Write a longer description or delete this line.
|
42
56
|
email:
|
43
57
|
- lzr3@us.meitu.com
|