pixab 2.3.4 → 2.4.0

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: a8bde21c80d31a7f727a34a67e6fdd26c3a6264f52dd2cd2c58e903667bee606
4
- data.tar.gz: ec05ecc1d60ccd9c91e5e5abf26c32dbbbbb92afcee0ffcecc11772d917f0985
3
+ metadata.gz: 857301e3eb6ed6a88bd64b764698de017088e1d7cabb7eb5ddefbd9161fcb904
4
+ data.tar.gz: e2e740a5b16c665a23c9b909bdf30c910356c69f59141b3ac0296d8c07c1271b
5
5
  SHA512:
6
- metadata.gz: 12c0ebd459f0ce193fc5075891ace6ed00c73f7d6b9115243f5fc2573ce31941d3a9af174799d63b555fb16c40ff2380e647f34880eb160889cfd663cfaa1fdd
7
- data.tar.gz: d0fdddf97e5c9a98da5d74355ec514c21072a92d55cf433bfaf3119ed75b6f2479c82d004dc62779f50f38b55a5ec0b9000bb15caddec876e54f4169cc36cd1a
6
+ metadata.gz: a8441858d9f113240a710bde966e5332c9d3e50850e9c4f07302548a70503181f175cba76b326d9048b5ed20a29b3f3a2e664d81606b0e929e2d0d1f036a7ef3
7
+ data.tar.gz: c6ed08f5fffe019e9c159c0e1f5573541f6e5559d66349d87e268655f1115b2620a126c81f7093c7a3389a4a8755662bdf3b0bd76a615127c4b54ccdee9df3be
data/exe/pixab CHANGED
@@ -7,9 +7,9 @@ require_relative '../lib/MergeRequest.rb'
7
7
  require_relative '../lib/ComponentSynchronizer.rb'
8
8
  require_relative '../lib/Localization.rb'
9
9
  require_relative '../lib/Package.rb'
10
- require_relative '../lib/LocalizationSmartcat.rb'
11
- require_relative '../lib/LocalizationSmartcatImport.rb'
12
- require_relative '../lib/LocalizationSmartcatMerge.rb'
10
+ require_relative '../lib/localization/smartcat/LocalizationSmartcat.rb'
11
+ require_relative '../lib/localization/smartcat/LocalizationSmartcatImport.rb'
12
+ require_relative '../lib/localization/smartcat/LocalizationSmartcatMerge.rb'
13
13
  require_relative '../lib/mbox/Mbox.rb'
14
14
  require_relative '../lib/gitlab/GitlabMRManager.rb'
15
15
  require_relative '../lib/feature/Feature.rb'
@@ -0,0 +1,21 @@
1
+ module Pixab
2
+
3
+ class FileMode
4
+
5
+ attr_reader :mode
6
+
7
+ def initialize(mode)
8
+ @mode = mode
9
+ end
10
+
11
+ def is_add
12
+ @mode.start_with?('a')
13
+ end
14
+
15
+ def is_replace
16
+ @mode.start_with?('w')
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -4,6 +4,7 @@ require 'zip'
4
4
  require 'colored2'
5
5
  require 'nokogiri'
6
6
  require_relative './LocalizationSmartcatInfo.rb'
7
+ require_relative '../../Utilities/FileMode.rb'
7
8
 
8
9
  module Pixab
9
10
 
@@ -16,6 +17,7 @@ module Pixab
16
17
  def initialize()
17
18
  @projects = LocalizationSmartcatInfo::Project_AirBrush
18
19
  @collections = 'main'
20
+ @file_mode = FileMode.new('w')
19
21
  end
20
22
 
21
23
  def run(commands = nil)
@@ -60,6 +62,8 @@ module Pixab
60
62
  @format = commands[index + 1]
61
63
  when '--output'
62
64
  @output = commands[index + 1]
65
+ when '--mode'
66
+ @file_mode = FileMode.new(commands[index + 1])
63
67
  end
64
68
  end
65
69
 
@@ -67,14 +71,13 @@ module Pixab
67
71
  export_params = generate_export_params
68
72
  download_url = 'https://smartcat.com/api/integration/v1/document/export'
69
73
 
70
- puts "\n》》》》》正在导出本地化文案 》》》》》》》》》》\n".green
74
+ puts "\n🚀 正在导出#{@collections}文案...".green
71
75
  export_id = fetch_export_id(export_url, export_params)
72
76
  export_id = export_id.tr('"','')
73
- puts "\n》》》》》正在下载本地化文案 》》》》》》》》》》\n".green
77
+ puts "\n📥 正在下载#{@collections}文案...".green
74
78
  if download_zip_file_with_retry(download_url, export_id)
75
- puts "\n》》》》》正在替换本地化文案 》》》》》》》》》》\n".green
76
79
  unzip_file(Localization_FILE_NAME)
77
- puts "\n》》》》》本地化文案更新已完成 》》》》》》》》》》\n".green
80
+ puts "\n #{@collections}文案更新已完成!".green
78
81
  end
79
82
 
80
83
  end
@@ -161,7 +164,12 @@ module Pixab
161
164
  match.gsub('%s', '%@')
162
165
  end
163
166
  end
164
- File.write(f_path, content)
167
+
168
+ if @file_mode.is_replace
169
+ File.write(f_path, content)
170
+ else
171
+ File.write(f_path, content, mode: @file_mode.mode)
172
+ end
165
173
  end
166
174
  end
167
175
 
@@ -179,10 +187,26 @@ module Pixab
179
187
  node.content = node.content.gsub(/['"]/, '\\\\\0')
180
188
  end
181
189
  end
190
+
191
+ if @file_mode.is_add
192
+ document = merge_xml_content(document, f_path)
193
+ end
194
+
182
195
  File.write(f_path, document.to_xml)
183
196
  end
184
197
  end
185
198
 
199
+ def merge_xml_content(new_document, file_path)
200
+ return new_document unless File.exist?(file_path)
201
+
202
+ old_document = Nokogiri::XML(File.read(file_path))
203
+ new_document.root.children.each do |node|
204
+ old_document.root.add_child(node)
205
+ end
206
+
207
+ return old_document
208
+ end
209
+
186
210
  def generate_export_params()
187
211
 
188
212
  export_params = {
@@ -0,0 +1,29 @@
1
+ require 'colored2'
2
+ require_relative './SmartcatCollections.rb'
3
+ require_relative './LocalizationSmartcat.rb'
4
+
5
+ module Pixab
6
+
7
+ class SmartcatBatch
8
+
9
+ def run(commands = nil)
10
+ collections = Pixab::SmartcatCollections.collections
11
+ if collections.nil?
12
+ puts "Collections为空".red
13
+ return
14
+ end
15
+
16
+ smartcat = Pixab::LocalizationSmartcat.new
17
+ new_commands = commands.nil? ? [] : commands
18
+ collections.each_with_index do |collection, index|
19
+ new_commands.push('--collections', collection)
20
+ if index > 0
21
+ new_commands.push('--mode', 'a')
22
+ end
23
+ smartcat.run(new_commands)
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,48 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'colored2'
5
+ require_relative './LocalizationSmartcatInfo.rb'
6
+
7
+ module Pixab
8
+
9
+ class SmartcatCollections
10
+
11
+ def self.collections
12
+ # 构建 URI
13
+ uri = URI.parse("https://smartcat.com/api/integration/v1/project/#{LocalizationSmartcatInfo::Project_AirBrush}")
14
+
15
+ # 创建 HTTP 请求
16
+ request = Net::HTTP::Get.new(uri)
17
+ request.basic_auth(LocalizationSmartcatInfo::USERNAME, LocalizationSmartcatInfo::PASSWORD)
18
+ request['Content-Type'] = 'application/json'
19
+
20
+ # 发送请求
21
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
22
+ http.request(request)
23
+ end
24
+
25
+ # 处理响应
26
+ if response.code.to_i == 200
27
+ project_info = JSON.parse(response.body)
28
+ if project_info.nil?
29
+ puts "请求失败,响应为空".red
30
+ return
31
+ end
32
+
33
+ documents = project_info["documents"]
34
+ if documents.nil?
35
+ puts "请求失败,documents为空".red
36
+ return
37
+ end
38
+
39
+ collections = documents.map { |document| document['name'] }.uniq
40
+ else
41
+ puts "请求失败,状态码: #{response.code}, 响应: #{response.body}".red
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
48
+ end
data/lib/pixab/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pixab
4
- VERSION = "2.3.4"
4
+ VERSION = "2.4.0"
5
5
  end
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: 2.3.4
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 廖再润
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-28 00:00:00.000000000 Z
11
+ date: 2025-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -99,15 +99,12 @@ files:
99
99
  - lib/GitUtils.rb
100
100
  - lib/Localization.rb
101
101
  - lib/LocalizationPlatform.rb
102
- - lib/LocalizationSmartcat.rb
103
- - lib/LocalizationSmartcatImport.rb
104
- - lib/LocalizationSmartcatInfo.rb
105
- - lib/LocalizationSmartcatMerge.rb
106
102
  - lib/MergeRequest.rb
107
103
  - lib/Package.rb
108
104
  - lib/Platform.rb
109
105
  - lib/RepoManager.rb
110
106
  - lib/Utilities.rb
107
+ - lib/Utilities/FileMode.rb
111
108
  - lib/Utilities/UserInfo.rb
112
109
  - lib/feature/Feature.rb
113
110
  - lib/feature/FeatureCopy.rb
@@ -117,6 +114,12 @@ files:
117
114
  - lib/gitlab/GitlabInfo.rb
118
115
  - lib/gitlab/GitlabMR.rb
119
116
  - lib/gitlab/GitlabMRManager.rb
117
+ - lib/localization/smartcat/LocalizationSmartcat.rb
118
+ - lib/localization/smartcat/LocalizationSmartcatImport.rb
119
+ - lib/localization/smartcat/LocalizationSmartcatInfo.rb
120
+ - lib/localization/smartcat/LocalizationSmartcatMerge.rb
121
+ - lib/localization/smartcat/SmartcatBatch.rb
122
+ - lib/localization/smartcat/SmartcatCollections.rb
120
123
  - lib/mbox/AirBrushProjectInfo.rb
121
124
  - lib/mbox/Mbox.rb
122
125
  - lib/mbox/MboxAdd.rb