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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5948996583d83aa8a72956d07acff0109ab3d72967c56fb7ced1824fe98d14e8
4
- data.tar.gz: eeb047467d631e9aaf3816ff82176429ff753b6f6ac90b0c10ee7d07b52a16b5
3
+ metadata.gz: c557d47179504b09a3ce83e5249bc53770e57e8381afc9083fa98d3536787b44
4
+ data.tar.gz: e27468da9cb5661d6b3c386b80086795331739e98cff87f4969064c25d0692a9
5
5
  SHA512:
6
- metadata.gz: 4ff0b6b2062358e45fb3d3c804f1aff3bfe0d2e2b5abf4ee8a0c302ec5921057fd83fa30651b913cab235594d26735409fd8ce88cdc0ca6c13039c47cbf0129a
7
- data.tar.gz: c70258231afbf89737ee7c6accddea47b62c655d548be43f2f9f6bb9b6e3b04d5c20097043f6ea8f59fa089d0f1320b10ecd568eb833ae5e1679d2f87c2d88cd
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(DEFAULT_ACCESS_TOKEN, project_id)
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:
@@ -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 db0506fb755d528c7b9b750e15174d3cfa483859488da978748ad6b9e34d13dc94d8716810a2f978",
15
+ "Authorization" => "Bearer #{@access_token}",
14
16
  "Content-Type" => "application/json"
15
17
  }
16
18
  end
@@ -1,3 +1,3 @@
1
1
  module Localzedloader
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.16"
3
3
  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}/AqaraHome/Common/#{config_name}"
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.downloadxls(project_path, crowdin=false)
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
- system "cd #{File.dirname(__FILE__)};python3 DownloadNewLanguage.py #{project_path} #{crowdin_arg}"
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 = "./AqaraHome/Resource"
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 = "./AqaraHome/Resource/#{lang}.lproj"
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 = "./AqaraHome/Resource/#{lang}.lproj"
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
@@ -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 |context|
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.14
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-04-10 00:00:00.000000000 Z
11
+ date: 2026-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler