cocoapods-aqara-localzedLoader 0.1.15 → 0.1.17

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: 0014ff7ca1b9fd3a2e93e4adede8455537da274e28704c3523fd357eebb86aab
4
+ data.tar.gz: 5066c47affcedfa80643d8fee28f85655656675063561d2de542299c753829a1
5
5
  SHA512:
6
- metadata.gz: 8c08a4b2fdf2382037e86cc0ed9d684b9e3e83cab109b4b8c2bc210bef498d8023296f47006d1103fc9708e548ebbb9c2bd144eb80b54ff0ea7540a6edbebfe0
7
- data.tar.gz: 9bbdfda02feeb90f7f88dc9fb37205bfb4b1f2008be1ed4d86f1c36d2849572ff98563a00a07ef784939d3c870f4f1665b524d0a26c2b60785a100b3670ab33f
6
+ metadata.gz: 98720fd614a55a077693d8d72fb16434d4cf494a7c8686947697d006e298c76cc7f92b40ce5dab0c4ea3c225a278a2de3af2b32519af9e2c4cf55d46a4326ab0
7
+ data.tar.gz: d62b44c11a5fa882981f5bebfb3c0c0137994b2c995916c914900df6b980c0afba617841bac64d8752a92eb6b02cc29da23a5b3532f6fb598f7d4e0f1d52f8f4
@@ -3,9 +3,7 @@ import os, sys, stat
3
3
  import time
4
4
  import requests
5
5
  import zipfile
6
- import csv
7
6
  from typing import Optional
8
- from openpyxl import Workbook
9
7
 
10
8
 
11
9
  ######### 火山多语言 #############
@@ -268,19 +266,18 @@ class CrowdinPlatform():
268
266
  os.remove(zip_path)
269
267
 
270
268
  if self.project_id == DEFAULT_LIFE_PROJECT_ID:
271
- csv_path = find_life_csv_file(output_dir)
272
- if not csv_path:
273
- raise FileNotFoundError(f"未找到 Life 项目的 CSV 文件: {output_dir}")
274
-
269
+ life_xlsx_path = os.path.join(output_dir, DEFAULT_LIFE_SOURCE_FILE_NAME)
275
270
  xlsx_path = os.path.join(output_dir, DEFAULT_TARGET_FILE_NAME)
276
- convert_csv_to_xlsx(csv_path, xlsx_path)
271
+ if not os.path.exists(life_xlsx_path):
272
+ raise FileNotFoundError(f"未找到 Life 项目的 Excel 文件: {life_xlsx_path}")
273
+ os.replace(life_xlsx_path, xlsx_path)
274
+ print(f"已将 Life 多语言文件重命名为: {xlsx_path}")
277
275
 
278
276
  print(f"多语言文件已解压到: {output_dir}APP.xlsx")
279
277
 
280
- # 默认配置(需要设置)
281
- DEFAULT_ACCESS_TOKEN = "db0506fb755d528c7b9b750e15174d3cfa483859488da978748ad6b9e34d13dc94d8716810a2f978" # 需要设置
282
278
  DEFAULT_LEGACY_PROJECT_ID = "71"
283
279
  DEFAULT_LIFE_PROJECT_ID = "85"
280
+ DEFAULT_LIFE_SOURCE_FILE_NAME = "APP_Life_APP.xlsx"
284
281
  DEFAULT_TARGET_FILE_NAME = "APP.xlsx"
285
282
 
286
283
  CROWDIN_PROJECTS = (
@@ -301,81 +298,19 @@ def resolve_crowdin_project(localizable_path: str) -> tuple[Optional[str], Optio
301
298
  return None, None
302
299
 
303
300
 
304
- def find_life_csv_file(output_dir: str) -> Optional[str]:
305
- preferred_path = os.path.join(output_dir, "APP_Life_APP.csv")
306
- if os.path.exists(preferred_path):
307
- return preferred_path
308
-
309
- fallback_csv_paths = []
310
- for root, _, file_names in os.walk(output_dir):
311
- for file_name in sorted(file_names):
312
- file_path = os.path.join(root, file_name)
313
- if file_name == "APP_Life_APP.csv":
314
- return file_path
315
- if file_name.lower().endswith(".csv"):
316
- fallback_csv_paths.append(file_path)
317
-
318
- if fallback_csv_paths:
319
- return fallback_csv_paths[0]
320
- return None
321
-
322
-
323
- def convert_csv_to_xlsx(csv_path: str, xlsx_path: str) -> None:
324
- with open(csv_path, "r", encoding="utf-8-sig", newline="") as csv_file:
325
- sample = csv_file.read(4096)
326
- csv_file.seek(0)
327
-
328
- try:
329
- dialect = csv.Sniffer().sniff(sample)
330
- except csv.Error:
331
- dialect = csv.excel
332
-
333
- reader = csv.reader(csv_file, dialect)
334
- workbook = Workbook()
335
- worksheet = workbook.active
336
-
337
- rows = list(reader)
338
- if not rows:
339
- workbook.save(xlsx_path)
340
- print(f"已将空 CSV 转换为 Excel: {xlsx_path}")
341
- return
342
-
343
- # 统一成旧项目 APP.xlsx 的列结构:
344
- # keys | source | tag | length limit | context | en-US | ...
345
- normalized_rows = []
346
- for row_index, row in enumerate(rows):
347
- normalized_row = []
348
- keys_value = row[0] if len(row) > 0 else ""
349
- source_value = row[1] if len(row) > 1 else ""
350
- context_value = row[2] if len(row) > 2 else ""
351
- remaining_values = list(row[3:]) if len(row) > 3 else []
352
-
353
- if row_index == 0:
354
- normalized_row = [
355
- "keys",
356
- "source",
357
- "tag",
358
- "length limit",
359
- "context",
360
- "en-US",
361
- ]
362
- normalized_row.extend(remaining_values[1:])
363
- else:
364
- normalized_row = [
365
- keys_value,
366
- source_value,
367
- "",
368
- "",
369
- context_value,
370
- ]
371
- normalized_row.extend(remaining_values)
372
- normalized_rows.append(normalized_row)
373
-
374
- for row in normalized_rows:
375
- worksheet.append(row)
376
-
377
- workbook.save(xlsx_path)
378
- print(f"已将 CSV 转换为 Excel: {xlsx_path}")
301
+ def resolve_crowdin_access_token(cli_token: Optional[str] = None) -> str:
302
+ access_token = (
303
+ cli_token
304
+ or os.getenv("CROWDIN_ACCESS_TOKEN")
305
+ or os.getenv("CROWDIN_TOKEN")
306
+ )
307
+ if not access_token:
308
+ raise RuntimeError(
309
+ "未找到 Crowdin token,请在 Podfile 中通过 "
310
+ "plugin 'cocoapods-aqara-localzedLoader', :crowdin_token => '...' 配置,"
311
+ "或设置 CROWDIN_ACCESS_TOKEN 环境变量"
312
+ )
313
+ return access_token
379
314
 
380
315
 
381
316
  ############################
@@ -388,6 +323,7 @@ if __name__ == '__main__':
388
323
  crowdin = False
389
324
  if len(sys.argv) > 2:
390
325
  crowdin = str_to_bool(sys.argv[2])
326
+ crowdin_access_token = sys.argv[3].strip() if len(sys.argv) > 3 else None
391
327
 
392
328
  if crowdin:
393
329
  config_path, project_id = resolve_crowdin_project(localizable_path)
@@ -395,7 +331,7 @@ if __name__ == '__main__':
395
331
  raise FileNotFoundError("未找到 crowdin.yml 或 crowdin_life.yml,无法确定 Crowdin project_id")
396
332
 
397
333
  print(f"检测到 Crowdin 配置: {config_path},project_id={project_id}")
398
- platform = CrowdinPlatform(DEFAULT_ACCESS_TOKEN, project_id)
334
+ platform = CrowdinPlatform(resolve_crowdin_access_token(crowdin_access_token), project_id)
399
335
  target_path = f"{localizable_path}/APP/"
400
336
  platform.download_and_extract_translations(target_path)
401
337
  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.17"
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.17
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-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler