cocoapods-localzedLoader 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a43a318cdb725be9246383aef2ad2fa3696633c0fdde0c9cf82eb6775929367
4
- data.tar.gz: f51de6244c21075e65cf6c5c09b3f5e060a645e4afd505a96c0571a51a2e6ada
3
+ metadata.gz: 35da642dbe713c4432282321be4a088ccc8e2506b6be79cb8379565ceb0096cf
4
+ data.tar.gz: 42d8236a2c31a5a99a2dd8d9dea3a8cbb4b4dcd8c8ebbe531c3b92c67e2a3a63
5
5
  SHA512:
6
- metadata.gz: 9f0aa67ff5ae01b846714e953187af46b73b3ce4552c59051b5007a34660471e8589adff1fbc514c7ad5df9ad54c16a2a7a0984575b3f061ec4a9464abc86ddb
7
- data.tar.gz: e70e990cd706febc2061dbd7b8241c99a6737f0d12c33a7256a04721d6bbb3a535fa6a0d7f92b64645f271d499d7519e2d41a253d630195cd1ddacd1cc1737ab
6
+ metadata.gz: adbcd572073abab951f26d0771c6b132056ed963f47d9b75637d056eb35abb251eb214c43f83361e9ab2479aa40ea64a39b9d295dfee4021090118964b3b4435
7
+ data.tar.gz: cb66b6149919c1d74bc41f169340d26a5d26a10b9d765b74be0fe4a8a21fe5e9664e32ce8f2bd40221fb3af08f4be63f8ee9475449d5603446187f40f8bb663f
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+ require 'httparty'
3
+ require 'zip'
4
+ require 'fileutils'
5
+ require 'colored2'
6
+
7
+ class LanguageDownloader
8
+
9
+ HeaderString = %Q{Accept:application/json, text/plain, */*
10
+ Accept-Encoding:gzip, deflate, br
11
+ Accept-Language:zh
12
+ Content-Length:194
13
+ Content-Type:application/json
14
+ Cookie:_ga=GA1.2.1025116346.1676013076; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%224902805f3ea41882.692841132392792065%22%2C%22first_id%22%3A%221859aeaeae8ac6-062e0ea9cca7ea-17525635-2073600-1859aeaeae9f16%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E5%BC%95%E8%8D%90%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fuc.aqara.cn%2F%22%7D%2C%22%24device_id%22%3A%221859aeaeae8ac6-062e0ea9cca7ea-17525635-2073600-1859aeaeae9f16%22%7D; Token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0OTAyODA1ZjNlYTQxODgyLjY5Mjg0MTEzMjM5Mjc5MjA2NSIsImlzcyI6Imh0dHBzOi8vYWlvdC1ycGMuYXFhcmEuY24iLCJhY2NvdW50IjoiamluZ3lhLmx1LWExMDc5QGFxYXJhLmNvbSIsImlhdEdtdDgiOjE2OTM1NzE0MDksImp0aSI6ImU4Y2YzNGMyNGRlYzQ0YWZiNzM5ODg3YzhiMGI3ZWE0YWM2OWFhNjViZmFjNDcxNWFlM2M1NmFkOGVhNDJlZGUifQ.INPHQkRwwRpXyRYpbRpNm6MfoYKUm7O4QjW7sOGNd6I; Userid=4902805f3ea41882.692841132392792065; currentSid=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0OTAyODA1ZjNlYTQxODgyLjY5Mjg0MTEzMjM5Mjc5MjA2NSIsImlzcyI6Imh0dHBzOi8vYWlvdC1ycGMuYXFhcmEuY24iLCJpYXRHbXQ4IjoxNjkzNTcxNDA5LCJqdGkiOiI4M2JmOWRkNDlmZDU0ZTUwOWVmODFjNjJhZjMwYTg4NmVjN2E1N2QzMGVkYTQ3ZTM5MDEzMGVhNWI5MWUxZTBkIn0.wHuZsMUkvTg4i-C4nHDhCpAiq-1acfl_G6KeycekIiw; currentAccount=jingya.lu-a1079@aqara.com; userInfo=%7B%22accountCategory%22%3A%220%22%2C%22company%22%3A%7B%22companyId%22%3A1%2C%22companyName%22%3A%22%E7%BB%BF%E7%B1%B3%E8%81%94%E5%88%9B%22%7D%2C%22user%22%3A%7B%22avatarUrl%22%3A%22%22%2C%22companyId%22%3A1%2C%22email%22%3A%22jingya.lu-a1079%40aqara.com%22%2C%22nickName%22%3A%22%22%2C%22userName%22%3A%22%E9%B2%81%E9%9D%99%E4%BA%9A%22%2C%22userType%22%3A0%7D%7D
15
+ Lang:zh
16
+ Nonce:980m43cn1qezpnplek4ovr8ahkg2enq1
17
+ Operate-Platform:40
18
+ Origin:https://intl-lang.aqara.com
19
+ Projectid:5
20
+ Referer:https://intl-lang.aqara.com/
21
+ Sec-Ch-Ua:"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"
22
+ Sec-Ch-Ua-Mobile:?0
23
+ Sec-Ch-Ua-Platform:"macOS"
24
+ Sec-Fetch-Dest:empty
25
+ Sec-Fetch-Mode:cors
26
+ Sec-Fetch-Site:same-origin
27
+ Time:1693571557934
28
+ Timestamp:1693571557934
29
+ User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
30
+ }
31
+
32
+ def self.makeHeader
33
+ headerArray = HeaderString.split("\n")
34
+ header = {}
35
+ headerArray.each do |str|
36
+ header[str.split(":",2)[0].strip] = str.split(":",2)[1].strip
37
+ end
38
+ header
39
+ end
40
+ def self.download
41
+
42
+ # puts makeHeader
43
+
44
+ #下载文件
45
+
46
+ params = {"projectIdList":[5],"langIds":[1,2,3,9,10,11,12,13,14,15,16,17,18],"fileTypeList":["excel"],"auditState":1,"valueState":0,"userId":"","value":"","tagIds":nil,"bizUseTagIds":nil,"pkeys":[]}
47
+ response = HTTParty.post('https://intl-lang.aqara.com/v1.0/lumi/language/file/export', body: JSON.generate(params), headers:LanguageDownloader.makeHeader)
48
+ # puts response.body
49
+ unless response.body["code"] == nil
50
+ 3.times do
51
+ puts "资源包下载失败了!!!!! code:#{response.body}".red
52
+ end
53
+ return
54
+ end
55
+ destation_path = "./localize.zip"
56
+ if File.exist? destation_path
57
+ FileUtils.rm_rf destation_path
58
+ end
59
+ File.open(destation_path,"w") do |io|
60
+ io.binmode
61
+ io.write response.body
62
+ end
63
+
64
+ # 解压缩文件到指定目录
65
+ f_path = ''
66
+
67
+ Zip::File.open(destation_path) do |zip_file|
68
+ zip_file.each do |f|
69
+ f_path = File.join('./','hit_all.xls')
70
+ File.delete f_path if File.exist? f_path
71
+ # FileUtils.mkdir_p(File.dirname(f_path))
72
+ f.extract(f_path)
73
+ end
74
+
75
+ end
76
+ if File.exist? destation_path
77
+ FileUtils.rm_rf destation_path
78
+ end
79
+
80
+ f_path
81
+ end
82
+
83
+ end
84
+
85
+ #LanguageDownloader.download
@@ -1,3 +1,5 @@
1
+
2
+ require_relative '../ios_bundle_generate'
1
3
  module Pod
2
4
  class Command
3
5
  # This is an example of a cocoapods plugin adding a top-level subcommand
@@ -18,26 +20,17 @@ module Pod
18
20
  # in the `plugins.json` file, once your plugin is released.
19
21
  #
20
22
  class Localzedloader < Command
21
- self.summary = '下载多语言包'
23
+ self.summary = 'langDownnloader for user'
22
24
 
23
25
  self.description = <<-DESC
24
- 从云端下载多语言包并更新到本地
26
+ help user downnloade language resource
25
27
  DESC
26
28
 
27
- # self.arguments = 'NAME'
28
-
29
- def initialize(argv)
30
- @name = argv.shift_argument
31
- super
32
- end
33
-
34
- def validate!
35
- super
36
- help! 'A Pod name is required.' unless @name
37
- end
29
+ self.arguments = []
38
30
 
39
31
  def run
40
- UI.puts "Add your implementation for the cocoapods-localzedLoader plugin in #{__FILE__}"
32
+ # UI.puts "Add your implementation for the cocoapods-LangDownnloader plugin in #{__FILE__}"
33
+ BundleGenerater.generate
41
34
  end
42
35
  end
43
36
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ExcelGenerate
4
+
5
+ end
@@ -1,3 +1,3 @@
1
1
  module CocoapodsLocalzedloader
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+ require_relative './LanguageDownloader'
3
+ require_relative './File_util'
4
+ require 'fileutils'
5
+ require 'colored2'
6
+
7
+ class BundleGenerater
8
+
9
+ # INFO_PLIST_ARRAY = [NSAppleMusicUsageDescription","NSLocalNetworkUsageDescription"]
10
+ INFO_PLIST_MAP = {:common_app_name=>["CFBundleDisplayName"],other_perm_camera_permission_description:["NSCameraUsageDescription"],other_perm_location_permission_description:["NSLocationAlwaysAndWhenInUseUsageDescription","NSLocationWhenInUseUsageDescription","NSLocationAlwaysUsageDescription"],other_perm_bluetooth_permission_description:["NSBluetoothPeripheralUsageDescription","NSBluetoothAlwaysUsageDescription"],access_content_permssion_storage:["NSPhotoLibraryUsageDescription"],other_perm_mic_permission_description:["NSMicrophoneUsageDescription"],other_set_permissions_homedata_desc:["NSHomeKitUsageDescription"],other_set_permissions_asr_text:["NSSpeechRecognitionUsageDescription"],device_add_device:["Add_Device_Title"],automation_add:["Add_Automation_Title"],device_create_scene:["Add_Scene_Title"]}
11
+ def self.generate
12
+ # 下载excel
13
+ f_path = LanguageDownloader.download
14
+ # unless f_path != nil
15
+ # return
16
+ # end
17
+ # f_path = "./hit_all.xls"
18
+ # 读取excel到内存
19
+ file_til = File_util.new
20
+ hash = file_til.read_excel f_path
21
+ if File.exist? f_path
22
+ FileUtils.rm_rf f_path
23
+ end
24
+ puts "一共有 #{hash.keys.size} 条文案".green
25
+
26
+ # 创建文件夹
27
+ file_til.getLangList.each do |lang|
28
+ # puts lang
29
+ localized_file = "./#{lang}.lproj/Localizable.strings"
30
+ dir = File.dirname localized_file
31
+ FileUtils.rm_rf localized_file
32
+ FileUtils.mkdir_p dir
33
+ end
34
+
35
+ #生成资源文件
36
+ hash.each do |key, stringElement|
37
+ num = 0
38
+ stringElement.langHash.each do |lang, value|
39
+ # puts "#{lang}:#{value}"
40
+ next if lang.downcase === "selfkey" or value === nil or value === " " or value === ""
41
+ value = self.handleValue value,stringElement
42
+ value.scan(/%@/) do |match|
43
+ num = match.size if num == 0
44
+ if num != match.size
45
+ puts "key:#{key}中%@ 数量不一致,请检查".red
46
+ end
47
+ end
48
+ str = %Q|"#{key}" = "#{value}";\n|
49
+ localized_file = "./#{lang}.lproj/Localizable.strings"
50
+ File.open(localized_file, "a") do |io|
51
+ io.write str
52
+ end
53
+
54
+ #如果是infoplist里的key,就写入指定的文件
55
+ if key === nil
56
+ puts "key值为空,#{stringElement.ios_list}"
57
+ elsif key === "NSAppleMusicUsageDescription" || key === "NSLocalNetworkUsageDescription"
58
+ file = "./#{lang}.lproj/InfoPlist.strings"
59
+ File.open(file, "a") do |io|
60
+ io.write str
61
+ end
62
+ elsif INFO_PLIST_MAP.has_key?(key.to_sym)
63
+ # puts "---key:#{key}"
64
+ keys = INFO_PLIST_MAP[key.to_sym]
65
+ keys.each do |info_key|
66
+ file = "./#{lang}.lproj/InfoPlist.strings"
67
+ str = %Q|"#{info_key}" = "#{value}";\n|
68
+ File.open(file, "a") do |io|
69
+ io.write str
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+
77
+ #验证导出的多语言包格式是否正确
78
+ puts '开始校验多语言包格式'.red
79
+ # puts "\e[31m 开始校验多语言包格式\e[0m"
80
+ file_til.getLangList.each do |lang|
81
+ localized_file = "./#{lang}.lproj/Localizable.strings"
82
+ file = "./#{lang}.lproj/InfoPlist.strings"
83
+ if File.exist?(file)
84
+ system("plutil #{file}")
85
+ end
86
+ system("plutil #{localized_file}")
87
+ end
88
+
89
+ #拷贝到代码仓库里
90
+ #查找bundle路径
91
+ bundPath = ""
92
+ info_plist_path = "./AqaraHome/Resource"
93
+ require 'find'
94
+ Find.find("./") do |filePath|
95
+ if filePath.end_with?("LMFramework.bundle")
96
+ bundPath = filePath
97
+ elsif filePath.end_with?("Resource")
98
+ end
99
+ end
100
+ unless bundPath != ""
101
+ puts '没有拷贝'
102
+ return
103
+ end
104
+
105
+ copy_info_plist = false
106
+ file_til.getLangList.each do |lang|
107
+ path = "./#{lang}.lproj/Localizable.strings"
108
+ dest = bundPath + "/#{lang}.lproj"
109
+ FileUtils.mkdir_p dest
110
+ FileUtils.mv("#{path}",dest,force:true)
111
+
112
+ info_plist_file = "./#{lang}.lproj/InfoPlist.strings"
113
+ # puts "path::::::#{info_plist_file}"
114
+ if File.exist? info_plist_file
115
+ copy_info_plist = true
116
+ dest = "./AqaraHome/Resource/#{lang}.lproj"
117
+ FileUtils.mkdir_p dest
118
+ FileUtils.mv("#{info_plist_file}",dest,force:true)
119
+ end
120
+ FileUtils.rm_rf (File.dirname(path))
121
+ end
122
+ puts "多语言拷贝到目录:#{bundPath}"
123
+ if copy_info_plist
124
+ puts "InfoPlist多语言拷贝到目录:#{info_plist_path}"
125
+ end
126
+ end
127
+
128
+ private
129
+ #对多语言的value进行处理
130
+ def self.handleValue(value='',stringElement = nil)
131
+ #替换{=}
132
+ value = value.gsub(/{#}/,"%@")
133
+ value = value.gsub(/""/,'"')
134
+ value = value.gsub(/\\"/,'"')
135
+ value = value.gsub(/""/,'"')
136
+ value = value.gsub(/"/,'\"')
137
+ #fix "common_time_day_with_space" = "\ day \";
138
+ if value.end_with?"\\"
139
+ value = value.chop
140
+ end
141
+ if value.end_with?"\\"
142
+ value = value.chop
143
+ end
144
+ value
145
+ end
146
+
147
+ end
148
+
149
+ # map = {:common_app_name=>["CFBundleDisplayName"]}
150
+ # if map.has_key?("common_app_name".to_sym)
151
+ # puts map[:common_app_name]
152
+ # end
153
+ # BundleGenerater.generate
154
+ # ios_list = ["%@","%d"]
155
+ # str = "{#}盏灯开着,真的吗{#}"
156
+ # i = -1
157
+ # str = str.gsub(/{#}/) do |matched|
158
+ # i+=1
159
+ # ios_list[i]
160
+ # end
161
+ #
162
+ # p str
163
+ # puts "111".green
@@ -1,5 +1,5 @@
1
1
  require 'cocoapods-localzedLoader/command'
2
- require_relative 'ios_bundle_generate'
2
+ require_relative 'cocoapods-localzedLoader/ios_bundle_generate'
3
3
  module CocoapodsGitHooks
4
4
  Pod::HooksManager.register('cocoapods-localzedLoader', :pre_install) do |context|
5
5
  BundleGenerater.generate
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-localzedLoader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeremylu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-25 00:00:00.000000000 Z
11
+ date: 2023-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -45,15 +45,16 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - lib/File_util.rb
49
- - lib/LanguageDownloader.rb
50
- - lib/StringElement.rb
51
- - lib/cocoapods-localzedLoader.rb
48
+ - lib/cocoapods-localzedLoader/File_util.rb
49
+ - lib/cocoapods-localzedLoader/LanguageDownloader.rb
50
+ - lib/cocoapods-localzedLoader/StringElement.rb
51
+ - lib/cocoapods-localzedLoader/cocoapods-localzedLoader.rb
52
52
  - lib/cocoapods-localzedLoader/command.rb
53
53
  - lib/cocoapods-localzedLoader/command/localzedLoader.rb
54
+ - lib/cocoapods-localzedLoader/excel_generate.rb
54
55
  - lib/cocoapods-localzedLoader/gem_version.rb
56
+ - lib/cocoapods-localzedLoader/ios_bundle_generate.rb
55
57
  - lib/cocoapods_plugin.rb
56
- - lib/ios_bundle_generate.rb
57
58
  homepage: https://github.com/EXAMPLE/cocoapods-localzedLoader
58
59
  licenses:
59
60
  - MIT
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'httparty'
3
- require 'zip'
4
- require 'fileutils'
5
- require 'colored2'
6
-
7
- class LanguageDownloader
8
-
9
- HeaderString = %Q{accept: application/json, text/plain, */*
10
- accept-encoding: gzip, deflate, br
11
- accept-language: zh
12
- content-length: 182
13
- content-type: application/json
14
- cookie: sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%221859aeaeae8ac6-062e0ea9cca7ea-17525635-2073600-1859aeaeae9f16%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22%24device_id%22%3A%221859aeaeae8ac6-062e0ea9cca7ea-17525635-2073600-1859aeaeae9f16%22%7D; Token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0OTAyODA1ZjNlYTQxODgyLjY5Mjg0MTEzMjM5Mjc5MjA2NSIsImlzcyI6Imh0dHBzOi8vYWlvdC1ycGMuYXFhcmEuY24iLCJhY2NvdW50IjoiamluZ3lhLmx1LWExMDc5QGFxYXJhLmNvbSIsImlhdEdtdDgiOjE2NzQ5ODM4MTMsImp0aSI6IjYxMTE3MDY3ZTRmNDQ2Mzg5YzI3Y2IxNDNjYTk5ZTRlMDdiMGZjNThmOWZlNGJjNjg5MjI2NjMxNWYwMzIxZDUifQ.AA90VKxT6zjlxnkFpaOMO9ujTXrssEXxuRp0WRhliGM; Userid=4902805f3ea41882.692841132392792065; currentSid=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0OTAyODA1ZjNlYTQxODgyLjY5Mjg0MTEzMjM5Mjc5MjA2NSIsImlzcyI6Imh0dHBzOi8vYWlvdC1ycGMuYXFhcmEuY24iLCJpYXRHbXQ4IjoxNjc0OTgzODEzLCJqdGkiOiIwZTY3NThjMjM3NGY0YmJiOWE3NjBmYzI0ZmZkY2NmODYzNGI4ODRjZGM1NTRjM2NiNTU1YzNkZjdmN2NjNWNhIn0.r7cBEpWVHWSpHH6zDX32FXNjMQ6IZN0DFBc3Oa8Tb5w; currentAccount=jingya.lu-a1079@aqara.com; userInfo=%7B%22accountCategory%22%3A%220%22%2C%22company%22%3A%7B%22companyId%22%3A1%2C%22companyName%22%3A%22%E7%BB%BF%E7%B1%B3%E8%81%94%E5%88%9B%22%7D%2C%22user%22%3A%7B%22avatarUrl%22%3A%22%22%2C%22companyId%22%3A1%2C%22email%22%3A%22jingya.lu-a1079%40aqara.com%22%2C%22nickName%22%3A%22%22%2C%22userName%22%3A%22%E9%B2%81%E9%9D%99%E4%BA%9A%22%2C%22userType%22%3A0%7D%7D; sidebarStatus=0lang: zh
15
- nonce: k9a7yh3vjjyd6vb47ktmcyh50bv3m3c2
16
- operate-platform: 40
17
- origin: https://intl-lang.aqara.com
18
- projectid: 5
19
- referer: https://intl-lang.aqara.com/
20
- sec-ch-ua: "Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"
21
- sec-ch-ua-mobile: ?0
22
- sec-ch-ua-platform: "macOS"
23
- sec-fetch-dest: empty
24
- sec-fetch-mode: cors
25
- sec-fetch-site: same-origin
26
- time: 1668061116811
27
- timestamp: 1668061116811
28
- user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
29
- }
30
- def self.makeHeader
31
- headerArray = HeaderString.split("\n")
32
- header = {}
33
- headerArray.each do |str|
34
- header[str.split(":",2)[0].strip] = str.split(":",2)[1].strip
35
- end
36
- header
37
- end
38
- def self.download
39
-
40
- # puts makeHeader
41
-
42
- #下载文件
43
-
44
- params = {"projectIdList":[5],"langIds":[1,2,3,9,10,11,12,13,14,15,16],"fileTypeList":["excel"],"auditState":1,"valueState":0,"userId":"","value":"","tagIds":nil,"bizUseTagIds":nil,"pkeys":[]}
45
- response = HTTParty.post('https://intl-lang.aqara.com/v1.0/lumi/language/file/export', body: JSON.generate(params), headers:LanguageDownloader.makeHeader)
46
- # puts response.body
47
- unless response.body["code"] == nil
48
- 3.times do
49
- puts "资源包下载失败了!!!!! code:#{response.body}".red
50
- end
51
- return
52
- end
53
- destation_path = "./localize.zip"
54
- if File.exist? destation_path
55
- FileUtils.rm_rf destation_path
56
- end
57
- File.open(destation_path,"w") do |io|
58
- io.binmode
59
- io.write response.body
60
- end
61
-
62
- # 解压缩文件到指定目录
63
- f_path = ''
64
-
65
- Zip::File.open(destation_path) do |zip_file|
66
- zip_file.each do |f|
67
- f_path = File.join('./','hit_all.xls')
68
- File.delete f_path if File.exist? f_path
69
- # FileUtils.mkdir_p(File.dirname(f_path))
70
- f.extract(f_path)
71
- end
72
-
73
- end
74
- if File.exist? destation_path
75
- FileUtils.rm_rf destation_path
76
- end
77
-
78
- f_path
79
- end
80
-
81
- end
82
-
83
-
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative './LanguageDownloader'
3
- require_relative './File_util'
4
- require 'fileutils'
5
- require 'colored2'
6
-
7
- class BundleGenerater
8
- def self.generate
9
- # 下载excel
10
- f_path = LanguageDownloader.download
11
- # unless f_path != nil
12
- # return
13
- # end
14
- # f_path = "./hit_all.xls"
15
- # 读取excel到内存
16
- file_til = File_util.new
17
- hash = file_til.read_excel f_path
18
- if File.exist? f_path
19
- FileUtils.rm_rf f_path
20
- end
21
- puts "一共有 #{hash.keys.size} 条文案".green
22
-
23
- # 创建文件夹
24
- file_til.getLangList.each do |lang|
25
- # puts lang
26
- localized_file = "./#{lang}.lproj/Localizable.strings"
27
- dir = File.dirname localized_file
28
- FileUtils.rm_rf localized_file
29
- FileUtils.mkdir_p dir
30
- end
31
-
32
- #生成资源文件
33
- hash.each do |key, stringElement|
34
- stringElement.langHash.each do |lang, value|
35
- # puts "#{lang}:#{value}"
36
- next if lang.downcase === "selfkey" or value === nil or value === " " or value === ""
37
- value = self.handleValue value,stringElement
38
- localized_file = "./#{lang}.lproj/Localizable.strings"
39
- str = %Q|"#{key}" = "#{value}";\n|
40
- File.open(localized_file, "a") do |io|
41
- io.write str
42
- end
43
- end
44
- end
45
-
46
- #验证导出的多语言包格式是否正确
47
- puts '开始校验多语言包格式'.red
48
- # puts "\e[31m 开始校验多语言包格式\e[0m"
49
- file_til.getLangList.each do |lang|
50
- localized_file = "./#{lang}.lproj/Localizable.strings"
51
- system("plutil #{localized_file}")
52
- end
53
-
54
- #拷贝到代码仓库里
55
- #查找bundle路径
56
- bundPath = ""
57
- require 'find'
58
- Find.find("./") do |filePath|
59
- if filePath.end_with?("LMFramework.bundle")
60
- bundPath = filePath
61
- break
62
- end
63
- end
64
- unless bundPath != ""
65
- puts '没有拷贝'
66
- return
67
- end
68
-
69
- file_til.getLangList.each do |lang|
70
- path = "#{lang}.lproj/Localizable.strings"
71
- dest = bundPath + "/#{lang}.lproj"
72
- FileUtils.mkdir_p dest
73
- FileUtils.mv("./#{path}",dest,force:true)
74
- FileUtils.rm_rf File.dirname("./#{path}")
75
- end
76
- puts "多语言拷贝到目录:#{bundPath}"
77
-
78
- end
79
-
80
- private
81
- #对多语言的value进行处理
82
- def self.handleValue(value='',stringElement = nil)
83
- #替换{=}
84
- value = value.gsub(/{#}/,"%@")
85
- value = value.gsub(/""/,'"')
86
- value = value.gsub(/\\"/,'"')
87
- value = value.gsub(/""/,'"')
88
- value = value.gsub(/"/,'\"')
89
- #fix "common_time_day_with_space" = "\ day \";
90
- if value.end_with?"\\"
91
- value = value.chop
92
- end
93
- if value.end_with?"\\"
94
- value = value.chop
95
- end
96
- value
97
- end
98
-
99
- end
100
- #
101
- # BundleGenerater.generate
102
- # ios_list = ["%@","%d"]
103
- # str = "{#}盏灯开着,真的吗{#}"
104
- # i = -1
105
- # str = str.gsub(/{#}/) do |matched|
106
- # i+=1
107
- # ios_list[i]
108
- # end
109
- #
110
- # p str
111
- # puts "111".green