cocoapods-aqara-localzedLoader 0.1.15 → 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: ee5cec583ea6486b9bc763ec3912c302c0b225343718451ca8f60e283bb9d611
4
- data.tar.gz: 759da241c72963c6fb91df5682e896b0c359b33ef66591ee3c23ca6709ef91af
3
+ metadata.gz: c557d47179504b09a3ce83e5249bc53770e57e8381afc9083fa98d3536787b44
4
+ data.tar.gz: e27468da9cb5661d6b3c386b80086795331739e98cff87f4969064c25d0692a9
5
5
  SHA512:
6
- metadata.gz: 8c08a4b2fdf2382037e86cc0ed9d684b9e3e83cab109b4b8c2bc210bef498d8023296f47006d1103fc9708e548ebbb9c2bd144eb80b54ff0ea7540a6edbebfe0
7
- data.tar.gz: 9bbdfda02feeb90f7f88dc9fb37205bfb4b1f2008be1ed4d86f1c36d2849572ff98563a00a07ef784939d3c870f4f1665b524d0a26c2b60785a100b3670ab33f
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.15"
2
+ VERSION = "0.1.16"
3
3
  end
@@ -89,7 +89,14 @@ class BundleGenerater
89
89
  }
90
90
  end
91
91
 
92
- 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)
93
100
  if @@download_Count > 10
94
101
  puts "当前无网络,程序即将退出。"
95
102
  exit(1)
@@ -102,11 +109,15 @@ class BundleGenerater
102
109
  end
103
110
  puts "当前进行第#{@@download_Count}次尝试下载多语言文件"
104
111
  crowdin_arg = crowdin ? "true" : "false"
105
- 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
106
117
  @@download_Count = @@download_Count + 1
107
118
  end
108
119
 
109
- def self.generate(project_path)
120
+ def self.generate(project_path, crowdin_token=nil)
110
121
  # 下载excel
111
122
  puts "开始下载多语言文件...".green
112
123
 
@@ -117,13 +128,14 @@ class BundleGenerater
117
128
  f_path = "#{project_path}/download.xlsx"
118
129
  if crowdin
119
130
  puts "检测到 Crowdin 配置: #{crowdin_info[:config_path]},project_id=#{crowdin_info[:project_id]}"
131
+ crowdin_token = self.resolve_crowdin_token(crowdin_token)
120
132
  f_path = "#{project_path}/APP/APP.xlsx"
121
133
  end
122
134
 
123
135
  puts f_path
124
136
 
125
137
  until File.exist?(f_path)
126
- self.downloadxls(project_path, crowdin)
138
+ self.downloadxls(project_path, crowdin, crowdin_token)
127
139
  end
128
140
  # 读取excel到内存
129
141
  file_til = File_util.new
@@ -276,7 +288,7 @@ class BundleGenerater
276
288
  Process.wait(pid)
277
289
 
278
290
  if $?.success?
279
- crowdin_util = CrowdinUtil.new(crowdin_info[:project_id])
291
+ crowdin_util = CrowdinUtil.new(crowdin_info[:project_id], crowdin_token)
280
292
  crowdin_util.release_distribution
281
293
  end
282
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.15
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