cocoapods-aqara-localzedLoader 0.1.14 → 0.1.16
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/cocoapods-aqara-localzedLoader/DownloadNewLanguage.py +17 -3
- data/lib/cocoapods-aqara-localzedLoader/__pycache__/DownloadNewLanguage.cpython-310.pyc +0 -0
- data/lib/cocoapods-aqara-localzedLoader/command/localzedLoader.rb +4 -2
- data/lib/cocoapods-aqara-localzedLoader/crowdin_util.rb +4 -2
- data/lib/cocoapods-aqara-localzedLoader/gem_version.rb +1 -1
- data/lib/cocoapods-aqara-localzedLoader/ios_bundle_generate.rb +31 -9
- data/lib/cocoapods_plugin.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c557d47179504b09a3ce83e5249bc53770e57e8381afc9083fa98d3536787b44
|
|
4
|
+
data.tar.gz: e27468da9cb5661d6b3c386b80086795331739e98cff87f4969064c25d0692a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf0d7310384c515dc492b01409b9fae7fe2f52f90bd9410713edacce678130e5428cc1a36ba041fae7d96feada5fee9cb52400635311ee4611788c7b49b4e97e
|
|
7
|
+
data.tar.gz: 2324c2bf0ae30d9c31bfb049698b6314d5233a40f81bcde8319c57629591093bd73e1d7e658d42ce5bd4d1d3d9c9123c7718dfd1c08925e456e4f4d6b2d3c8ea
|
|
@@ -277,8 +277,6 @@ class CrowdinPlatform():
|
|
|
277
277
|
|
|
278
278
|
print(f"多语言文件已解压到: {output_dir}APP.xlsx")
|
|
279
279
|
|
|
280
|
-
# 默认配置(需要设置)
|
|
281
|
-
DEFAULT_ACCESS_TOKEN = "db0506fb755d528c7b9b750e15174d3cfa483859488da978748ad6b9e34d13dc94d8716810a2f978" # 需要设置
|
|
282
280
|
DEFAULT_LEGACY_PROJECT_ID = "71"
|
|
283
281
|
DEFAULT_LIFE_PROJECT_ID = "85"
|
|
284
282
|
DEFAULT_TARGET_FILE_NAME = "APP.xlsx"
|
|
@@ -301,6 +299,21 @@ def resolve_crowdin_project(localizable_path: str) -> tuple[Optional[str], Optio
|
|
|
301
299
|
return None, None
|
|
302
300
|
|
|
303
301
|
|
|
302
|
+
def resolve_crowdin_access_token(cli_token: Optional[str] = None) -> str:
|
|
303
|
+
access_token = (
|
|
304
|
+
cli_token
|
|
305
|
+
or os.getenv("CROWDIN_ACCESS_TOKEN")
|
|
306
|
+
or os.getenv("CROWDIN_TOKEN")
|
|
307
|
+
)
|
|
308
|
+
if not access_token:
|
|
309
|
+
raise RuntimeError(
|
|
310
|
+
"未找到 Crowdin token,请在 Podfile 中通过 "
|
|
311
|
+
"plugin 'cocoapods-aqara-localzedLoader', :crowdin_token => '...' 配置,"
|
|
312
|
+
"或设置 CROWDIN_ACCESS_TOKEN 环境变量"
|
|
313
|
+
)
|
|
314
|
+
return access_token
|
|
315
|
+
|
|
316
|
+
|
|
304
317
|
def find_life_csv_file(output_dir: str) -> Optional[str]:
|
|
305
318
|
preferred_path = os.path.join(output_dir, "APP_Life_APP.csv")
|
|
306
319
|
if os.path.exists(preferred_path):
|
|
@@ -388,6 +401,7 @@ if __name__ == '__main__':
|
|
|
388
401
|
crowdin = False
|
|
389
402
|
if len(sys.argv) > 2:
|
|
390
403
|
crowdin = str_to_bool(sys.argv[2])
|
|
404
|
+
crowdin_access_token = sys.argv[3].strip() if len(sys.argv) > 3 else None
|
|
391
405
|
|
|
392
406
|
if crowdin:
|
|
393
407
|
config_path, project_id = resolve_crowdin_project(localizable_path)
|
|
@@ -395,7 +409,7 @@ if __name__ == '__main__':
|
|
|
395
409
|
raise FileNotFoundError("未找到 crowdin.yml 或 crowdin_life.yml,无法确定 Crowdin project_id")
|
|
396
410
|
|
|
397
411
|
print(f"检测到 Crowdin 配置: {config_path},project_id={project_id}")
|
|
398
|
-
platform = CrowdinPlatform(
|
|
412
|
+
platform = CrowdinPlatform(resolve_crowdin_access_token(crowdin_access_token), project_id)
|
|
399
413
|
target_path = f"{localizable_path}/APP/"
|
|
400
414
|
platform.download_and_extract_translations(target_path)
|
|
401
415
|
else:
|
|
Binary file
|
|
@@ -31,6 +31,7 @@ module Pod
|
|
|
31
31
|
super
|
|
32
32
|
# puts "初始化:#{argv}"
|
|
33
33
|
project_directory = argv.option('project-directory')
|
|
34
|
+
@crowdin_token = argv.option('crowdin-token') || ENV['CROWDIN_ACCESS_TOKEN']
|
|
34
35
|
puts project_directory
|
|
35
36
|
project_directory = Dir.pwd if project_directory.nil?
|
|
36
37
|
puts project_directory
|
|
@@ -40,12 +41,13 @@ module Pod
|
|
|
40
41
|
end
|
|
41
42
|
def self.options
|
|
42
43
|
[
|
|
43
|
-
['--project-directory=/project/dir/', 'The path to the root of the project directory']
|
|
44
|
+
['--project-directory=/project/dir/', 'The path to the root of the project directory'],
|
|
45
|
+
['--crowdin-token=TOKEN', 'Crowdin access token for downloading translations']
|
|
44
46
|
].concat(super)
|
|
45
47
|
end
|
|
46
48
|
def run
|
|
47
49
|
UI.puts "项目路径 #{@project_directory}"
|
|
48
|
-
BundleGenerater.generate(@project_directory)
|
|
50
|
+
BundleGenerater.generate(@project_directory, @crowdin_token)
|
|
49
51
|
end
|
|
50
52
|
end
|
|
51
53
|
end
|
|
@@ -4,13 +4,15 @@ require "uri"
|
|
|
4
4
|
require "json"
|
|
5
5
|
class CrowdinUtil
|
|
6
6
|
|
|
7
|
-
def initialize(project_id = "71")
|
|
7
|
+
def initialize(project_id = "71", access_token = nil)
|
|
8
8
|
@project_id = project_id
|
|
9
|
+
@access_token = access_token || ENV["CROWDIN_ACCESS_TOKEN"] || ENV["CROWDIN_TOKEN"]
|
|
10
|
+
raise "未找到 Crowdin token,无法发布 OTA Release" if @access_token.to_s.empty?
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def crowdin_headers
|
|
12
14
|
{
|
|
13
|
-
"Authorization" => "Bearer
|
|
15
|
+
"Authorization" => "Bearer #{@access_token}",
|
|
14
16
|
"Content-Type" => "application/json"
|
|
15
17
|
}
|
|
16
18
|
end
|
|
@@ -10,6 +10,10 @@ class BundleGenerater
|
|
|
10
10
|
"crowdin_life.yml" => "85",
|
|
11
11
|
"crowdin.yml" => "71"
|
|
12
12
|
}.freeze
|
|
13
|
+
PROJECT_APP_DIRS = {
|
|
14
|
+
"85" => "AqaraLife",
|
|
15
|
+
"71" => "AqaraHome"
|
|
16
|
+
}.freeze
|
|
13
17
|
|
|
14
18
|
|
|
15
19
|
# INFO_PLIST_ARRAY = [NSAppleMusicUsageDescription","NSLocalNetworkUsageDescription"]
|
|
@@ -57,11 +61,16 @@ class BundleGenerater
|
|
|
57
61
|
|
|
58
62
|
@@download_Count = 1
|
|
59
63
|
|
|
64
|
+
def self.app_dir_name(project_id)
|
|
65
|
+
PROJECT_APP_DIRS.fetch(project_id, "AqaraHome")
|
|
66
|
+
end
|
|
67
|
+
|
|
60
68
|
def self.resolve_crowdin_project(project_path)
|
|
61
69
|
CROWDIN_PROJECTS.each do |config_name, project_id|
|
|
70
|
+
app_dir = self.app_dir_name(project_id)
|
|
62
71
|
[
|
|
63
72
|
"#{project_path}/#{config_name}",
|
|
64
|
-
"#{project_path}/
|
|
73
|
+
"#{project_path}/#{app_dir}/Common/#{config_name}"
|
|
65
74
|
].each do |config_path|
|
|
66
75
|
next unless File.exist?(config_path)
|
|
67
76
|
|
|
@@ -80,7 +89,14 @@ class BundleGenerater
|
|
|
80
89
|
}
|
|
81
90
|
end
|
|
82
91
|
|
|
83
|
-
def self.
|
|
92
|
+
def self.resolve_crowdin_token(crowdin_token)
|
|
93
|
+
token = crowdin_token || ENV["CROWDIN_ACCESS_TOKEN"] || ENV["CROWDIN_TOKEN"]
|
|
94
|
+
return token unless token.to_s.empty?
|
|
95
|
+
|
|
96
|
+
raise "未找到 Crowdin token,请在 Podfile 中通过 plugin 'cocoapods-aqara-localzedLoader', :crowdin_token => '...' 配置,或设置 CROWDIN_ACCESS_TOKEN 环境变量"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def self.downloadxls(project_path, crowdin=false, crowdin_token=nil)
|
|
84
100
|
if @@download_Count > 10
|
|
85
101
|
puts "当前无网络,程序即将退出。"
|
|
86
102
|
exit(1)
|
|
@@ -93,27 +109,33 @@ class BundleGenerater
|
|
|
93
109
|
end
|
|
94
110
|
puts "当前进行第#{@@download_Count}次尝试下载多语言文件"
|
|
95
111
|
crowdin_arg = crowdin ? "true" : "false"
|
|
96
|
-
|
|
112
|
+
env = {}
|
|
113
|
+
env["CROWDIN_ACCESS_TOKEN"] = crowdin_token if crowdin_token && !crowdin_token.to_s.empty?
|
|
114
|
+
Dir.chdir(File.dirname(__FILE__)) do
|
|
115
|
+
system(env, "python3", "DownloadNewLanguage.py", project_path.to_s, crowdin_arg)
|
|
116
|
+
end
|
|
97
117
|
@@download_Count = @@download_Count + 1
|
|
98
118
|
end
|
|
99
119
|
|
|
100
|
-
def self.generate(project_path)
|
|
120
|
+
def self.generate(project_path, crowdin_token=nil)
|
|
101
121
|
# 下载excel
|
|
102
122
|
puts "开始下载多语言文件...".green
|
|
103
123
|
|
|
104
124
|
crowdin_info = self.resolve_crowdin_project(project_path)
|
|
105
125
|
crowdin = crowdin_info[:enabled]
|
|
126
|
+
app_dir = self.app_dir_name(crowdin_info[:project_id])
|
|
106
127
|
|
|
107
128
|
f_path = "#{project_path}/download.xlsx"
|
|
108
129
|
if crowdin
|
|
109
130
|
puts "检测到 Crowdin 配置: #{crowdin_info[:config_path]},project_id=#{crowdin_info[:project_id]}"
|
|
131
|
+
crowdin_token = self.resolve_crowdin_token(crowdin_token)
|
|
110
132
|
f_path = "#{project_path}/APP/APP.xlsx"
|
|
111
133
|
end
|
|
112
134
|
|
|
113
135
|
puts f_path
|
|
114
136
|
|
|
115
137
|
until File.exist?(f_path)
|
|
116
|
-
self.downloadxls(project_path, crowdin)
|
|
138
|
+
self.downloadxls(project_path, crowdin, crowdin_token)
|
|
117
139
|
end
|
|
118
140
|
# 读取excel到内存
|
|
119
141
|
file_til = File_util.new
|
|
@@ -221,7 +243,7 @@ class BundleGenerater
|
|
|
221
243
|
#拷贝到代码仓库里
|
|
222
244
|
#查找bundle路径
|
|
223
245
|
bundPath = ""
|
|
224
|
-
info_plist_path = "
|
|
246
|
+
info_plist_path = "./#{app_dir}/Resource"
|
|
225
247
|
require 'find'
|
|
226
248
|
Find.find("./") do |filePath|
|
|
227
249
|
if filePath.end_with?("LMFramework.bundle")
|
|
@@ -238,7 +260,7 @@ class BundleGenerater
|
|
|
238
260
|
file_til.getLangList.each do |lang|
|
|
239
261
|
path = "./#{lang}.lproj/Localizable.strings"
|
|
240
262
|
dest = bundPath + "/#{lang}.lproj"
|
|
241
|
-
dest2 = "
|
|
263
|
+
dest2 = "./#{app_dir}/Resource/#{lang}.lproj"
|
|
242
264
|
FileUtils.mkdir_p dest
|
|
243
265
|
FileUtils.cp(path,dest2)
|
|
244
266
|
FileUtils.mv("#{path}",dest,force:true)
|
|
@@ -247,7 +269,7 @@ class BundleGenerater
|
|
|
247
269
|
# puts "path::::::#{info_plist_file}"
|
|
248
270
|
if File.exist? info_plist_file
|
|
249
271
|
copy_info_plist = true
|
|
250
|
-
dest = "
|
|
272
|
+
dest = "./#{app_dir}/Resource/#{lang}.lproj"
|
|
251
273
|
FileUtils.mkdir_p dest
|
|
252
274
|
FileUtils.mv("#{info_plist_file}",dest,force:true)
|
|
253
275
|
end
|
|
@@ -266,7 +288,7 @@ class BundleGenerater
|
|
|
266
288
|
Process.wait(pid)
|
|
267
289
|
|
|
268
290
|
if $?.success?
|
|
269
|
-
crowdin_util = CrowdinUtil.new(crowdin_info[:project_id])
|
|
291
|
+
crowdin_util = CrowdinUtil.new(crowdin_info[:project_id], crowdin_token)
|
|
270
292
|
crowdin_util.release_distribution
|
|
271
293
|
end
|
|
272
294
|
end
|
data/lib/cocoapods_plugin.rb
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
require 'cocoapods-aqara-localzedLoader/command'
|
|
2
2
|
require_relative 'cocoapods-aqara-localzedLoader/ios_bundle_generate'
|
|
3
3
|
module Pod
|
|
4
|
-
Pod::HooksManager.register('cocoapods-aqara-localzedLoader', :pre_install) do |
|
|
4
|
+
Pod::HooksManager.register('cocoapods-aqara-localzedLoader', :pre_install) do |_, options|
|
|
5
|
+
crowdin_token = options && (
|
|
6
|
+
options[:crowdin_token] ||
|
|
7
|
+
options[:crowdinToken] ||
|
|
8
|
+
options[:access_token] ||
|
|
9
|
+
options[:token]
|
|
10
|
+
)
|
|
5
11
|
args = ['download', "--project-directory=#{Config.instance.installation_root}"]
|
|
12
|
+
args << "--crowdin-token=#{crowdin_token}" if crowdin_token && !crowdin_token.to_s.empty?
|
|
6
13
|
Pod::Command.run(args)
|
|
7
14
|
end
|
|
8
15
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cocoapods-aqara-localzedLoader
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- zhaoxifan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-07-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|