cocoapods-localzedLoader 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 05a7af28fc44ec65b1771212c189e7b86ea289f1405ecc03a9d1eb59b6bb916e
4
+ data.tar.gz: 51939fa9a827d8f57c8f91c58d8592c556748aa95028ac7e893992312849b1c7
5
+ SHA512:
6
+ metadata.gz: 37dc15c4aa3bcd90eea0109ecc2365790e9d13110af6341aafdbd93b60ba610b2fe3a44dfe82df75d76fe7735305ed6a15bbe8b9a7dfc5103c5ccff7e0137bb9
7
+ data.tar.gz: 7b6941a85d52a6ae30b6f72da4934432bd5feb008cc67f73d01ae81cb4ac78358408b92b4bbeac4a1e5e0338d5ead7f49cf729b69ac51a2419a90a2cdb08326c
data/lib/File_util.rb ADDED
@@ -0,0 +1,94 @@
1
+
2
+ # require 'file'
3
+ $LOAD_PATH << '.'
4
+ # -*- coding: UTF-8 -*-
5
+ require 'rubyXL'
6
+ require_relative './StringElement'
7
+
8
+ class File_util
9
+
10
+ attr_accessor :keys_hash
11
+ #读取excel 返回StringElement数组
12
+ def read_excel(filename)
13
+ unless filename != nil
14
+ puts "读取的excel为空"
15
+ return
16
+ end
17
+
18
+ workbook = RubyXL::Parser.parse filename
19
+ worksheet = workbook[0]
20
+ row1 = worksheet[0]
21
+ @key_hash = getkeyHash(row1)
22
+ lang_hash = {}
23
+ worksheet.each_with_index do |row|
24
+ ele = StringElement.new
25
+ self_key = ''
26
+ # 设置StringElement的值
27
+ row.cells.each_with_index do |cell, i|
28
+
29
+ next unless cell
30
+ case i
31
+ when 0
32
+
33
+ when 1
34
+ self_key = cell.value
35
+ else
36
+ key = @key_hash[i]
37
+ ele.langHash[key] = (cell.value || '')
38
+ end
39
+ end
40
+
41
+ lang_hash[self_key] = ele
42
+ end
43
+ lang_hash
44
+ end
45
+
46
+ #根据第一行来获取当前cell的key
47
+ # return {1:selfkey,2:en,3:zh....} 方便excel取
48
+ # Command+Option+L 对齐快捷键
49
+ def getkeyHash(row1,ios:true)
50
+ keys_hash = {}
51
+ row1.cells.each_with_index do |cell, i|
52
+ next unless cell
53
+ if i > 1
54
+ result = cell.value.scan(/.*?\[(.*)\]/)
55
+ key = result[0][0]
56
+ case key
57
+ when /zh_HK/
58
+ key="zh-HK"
59
+ when /zh_TW/
60
+ key ="zh-Hant-TW"
61
+ when /zh/
62
+ key ="zh-Hans"
63
+ when /fr.*/
64
+ key ="fr"
65
+ when /it.*/
66
+ key="it"
67
+ when /ger.*/
68
+ key ="de"
69
+ else
70
+ key
71
+ end
72
+ keys_hash[i] = key
73
+ elsif i == 1
74
+ keys_hash[i] = cell.value
75
+ end
76
+ end
77
+ keys_hash
78
+ end
79
+
80
+ def getLangList
81
+ list = @key_hash.values
82
+ list.delete_if{|item| item.downcase === "selfkey"}
83
+ list
84
+ end
85
+ end
86
+
87
+ # hash = File_util.read_excel"hit_all.xls"
88
+ # puts hash.keys.size
89
+ # hash.each do |key,value|
90
+ # puts value
91
+ # end
92
+
93
+ # p "sssssssss中文[zh]".scan(/.*?\[(.*)\]/)
94
+
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+ require 'httparty'
3
+ require 'zip'
4
+ require 'fileutils'
5
+
6
+ class LanguageDownloader
7
+
8
+ HeaderString = %Q{accept: application/json, text/plain, */*
9
+ accept-encoding: gzip, deflate, br
10
+ accept-language: zh
11
+ content-length: 182
12
+ content-type: application/json
13
+ cookie: experimentation_subject_id=ImNhNTFhZTQ4LTVjNWItNDBmOS05ZmY3LTY5ZjgwMjE2YzU3ZCI%3D--adfdeb4234398bb82727d204df565baf4fcb9e02; __gads=ID=330a8bae159ec1c5-224c3fce10d50039:T=1657179992:RT=1657179992:S=ALNI_MbFcfcws4Qph_vMu9ocv_uTUODlsQ; _gcl_au=1.1.1930354128.1661415060; _fbp=fb.1.1661415060137.191157889; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22e81e719330108226.642068199734845441%22%2C%22first_id%22%3A%2217f2542445d8d6-0c4aee16f19597-37677a09-1484784-17f2542445e707%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%2217f2542445d8d6-0c4aee16f19597-37677a09-1484784-17f2542445e707%22%7D; __gpi=UID=00000770b0955020:T=1657179992:RT=1667284690:S=ALNI_Max_O1qEORw1S9hsg1OFkW2uV7oQg; _ga=GA1.2.283585764.1638366289; _ga_3EMB6JL0XV=GS1.1.1667298252.19.1.1667299119.60.0.0; Hm_lvt_2df419cadb3951597d5f6df3a9e563d1=1667528944; Hm_lpvt_2df419cadb3951597d5f6df3a9e563d1=1667547607; Token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJlODFlNzE5MzMwMTA4MjI2LjY0MjA2ODE5OTczNDg0NTQ0MSIsImlzcyI6Imh0dHBzOi8vYWlvdC1ycGMuYXFhcmEuY24iLCJhY2NvdW50IjoieGlmYW4uemhhb0BhcWFyYS5jb20iLCJpYXRHbXQ4IjoxNjY3ODE3OTU1LCJqdGkiOiIxY2JkZjc4YzU2MzI0N2Q4OTJkZjIwYzZlZmY1YTdiZTY4MWZiMzc1YjIxYTQzNzQ5YjNlMDkyZDY0NjY5Zjc2In0.HO1YbsvUp50GFAXfYDwpbpW8rwaiSI2_PTp38CmhQbU; Userid=e81e719330108226.642068199734845441; currentSid=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJlODFlNzE5MzMwMTA4MjI2LjY0MjA2ODE5OTczNDg0NTQ0MSIsImlzcyI6Imh0dHBzOi8vYWlvdC1ycGMuYXFhcmEuY24iLCJpYXRHbXQ4IjoxNjY3ODE3OTU1LCJqdGkiOiJhZDZjZmMyYTBmZDk0OGIwODkzN2MxMzgzZDQwNGRkYTlmNmExMDFkNjUzNDQ1ZWU5NjM0Yzc2MjIzODYzZWJhIn0.WHEe5H6ImH5FbGA9MByXhSIB6Y3sP1ltmlVsdmtg6kY; currentAccount=xifan.zhao@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%22xifan.zhao%40aqara.com%22%2C%22nickName%22%3A%22%22%2C%22userType%22%3A0%7D%7D; sidebarStatus=0
14
+ lang: 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],"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["code"]
47
+ # unless response.body["code"] === 0
48
+ # puts "资源包下载失败 code:#{response.body}"
49
+ # return
50
+ # end
51
+ destation_path = "./localize.zip"
52
+ if File.exist? destation_path
53
+ FileUtils.rm_rf destation_path
54
+ end
55
+ File.open(destation_path,"w") do |io|
56
+ io.binmode
57
+ io.write response.body
58
+ end
59
+
60
+ # 解压缩文件到指定目录
61
+ f_path = ''
62
+
63
+ Zip::File.open(destation_path) do |zip_file|
64
+ zip_file.each do |f|
65
+ f_path = File.join('./','hit_all.xls')
66
+ File.delete f_path if File.exist? f_path
67
+ # FileUtils.mkdir_p(File.dirname(f_path))
68
+ f.extract(f_path)
69
+ end
70
+
71
+ end
72
+ if File.exist? destation_path
73
+ FileUtils.rm_rf destation_path
74
+ end
75
+
76
+ f_path
77
+ end
78
+
79
+ end
80
+
81
+
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StringElement
4
+ attr_accessor :langHash
5
+ attr_accessor :ios_list
6
+ attr_accessor :android_list
7
+
8
+ def initialize
9
+ @langHash = {}
10
+ @ios_list = []
11
+ @android_list = []
12
+ end
13
+
14
+ def to_s
15
+ @langHash.to_s
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ module Pod
2
+ class Command
3
+ # This is an example of a cocoapods plugin adding a top-level subcommand
4
+ # to the 'pod' command.
5
+ #
6
+ # You can also create subcommands of existing or new commands. Say you
7
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
8
+ # (e.g. `pod list deprecated`), there are a few things that would need
9
+ # to change.
10
+ #
11
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
12
+ # the class to exist in the the Pod::Command::List namespace
13
+ # - change this class to extend from `List` instead of `Command`. This
14
+ # tells the plugin system that it is a subcommand of `list`.
15
+ # - edit `lib/cocoapods_plugins.rb` to require this file
16
+ #
17
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
18
+ # in the `plugins.json` file, once your plugin is released.
19
+ #
20
+ class Localzedloader < Command
21
+ self.summary = 'Short description of cocoapods-localzedLoader.'
22
+
23
+ self.description = <<-DESC
24
+ Longer description of cocoapods-localzedLoader.
25
+ DESC
26
+
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
38
+
39
+ def run
40
+ UI.puts "Add your implementation for the cocoapods-localzedLoader plugin in #{__FILE__}"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-localzedLoader/command/localzedLoader'
@@ -0,0 +1,3 @@
1
+ module CocoapodsLocalzedloader
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-localzedLoader/gem_version'
@@ -0,0 +1,10 @@
1
+ require 'cocoapods-localzedLoader/command'
2
+ require_relative 'ios_bundle_generate'
3
+ module CocoapodsGitHooks
4
+ Pod::HooksManager.register('cocoapods-localzedLoader', :pre_install) do |context|
5
+ BundleGenerater.generate
6
+ end
7
+ Pod::HooksManager.register('cocoapods-localzedLoader', :pre_update) do |context|
8
+ BundleGenerater.generate
9
+ end
10
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+ require_relative './LanguageDownloader'
3
+ require_relative './File_util'
4
+ require 'fileutils'
5
+
6
+ class BundleGenerater
7
+ def self.generate
8
+ # 下载excel
9
+ f_path = LanguageDownloader.download
10
+ # unless f_path != nil
11
+ # return
12
+ # end
13
+ # f_path = "./hit_all.xls"
14
+ # 读取excel到内存
15
+ file_til = File_util.new
16
+ hash = file_til.read_excel f_path
17
+ if File.exist? f_path
18
+ FileUtils.rm_rf f_path
19
+ end
20
+ puts "一共有 #{hash.keys.size} 条文案"
21
+
22
+ # 创建文件夹
23
+ file_til.getLangList.each do |lang|
24
+ # puts lang
25
+ localized_file = "./#{lang}.lproj/Localizable.strings"
26
+ dir = File.dirname localized_file
27
+ FileUtils.rm_rf localized_file
28
+ FileUtils.mkdir_p dir
29
+ end
30
+
31
+ #生成资源文件
32
+ hash.each do |key, stringElement|
33
+ stringElement.langHash.each do |lang, value|
34
+ # puts "#{lang}:#{value}"
35
+ next if lang.downcase === "selfkey"
36
+ value = self.handleValue value,stringElement
37
+ localized_file = "./#{lang}.lproj/Localizable.strings"
38
+ str = %Q|"#{key}" = "#{value}";\n|
39
+ File.open(localized_file, "a") do |io|
40
+ io.write str
41
+ end
42
+ end
43
+ end
44
+
45
+ #验证导出的多语言包格式是否正确
46
+ puts "\e[31m 开始校验多语言包格式\e[0m"
47
+ file_til.getLangList.each do |lang|
48
+ localized_file = "./#{lang}.lproj/Localizable.strings"
49
+ system("plutil #{localized_file}")
50
+ end
51
+
52
+ #拷贝到代码仓库里
53
+ #查找bundle路径
54
+ bundPath = ""
55
+ require 'find'
56
+ Find.find("./") do |filePath|
57
+ if filePath.end_with?("LMFramework.bundle")
58
+ bundPath = filePath
59
+ break
60
+ end
61
+ end
62
+ unless bundPath != ""
63
+ puts '没有拷贝'
64
+ return
65
+ end
66
+
67
+ file_til.getLangList.each do |lang|
68
+ path = "/#{lang}.lproj/Localizable.strings"
69
+ FileUtils.mv(".#{path}",bundPath+path)
70
+ FileUtils.rm_rf File.dirname ".#{path}"
71
+ end
72
+ puts "多语言拷贝到目录:#{bundPath}"
73
+
74
+ end
75
+
76
+ private
77
+ #对多语言的value进行处理
78
+ def self.handleValue(value='',stringElement = nil)
79
+ #替换{=}
80
+ value = value.gsub(/{#}/,"%@")
81
+ value = value.gsub(/""/,'"')
82
+ value = value.gsub(/\\"/,'"')
83
+ value = value.gsub(/""/,'"')
84
+ value = value.gsub(/"/,'\"')
85
+ #fix "common_time_day_with_space" = "\ day \";
86
+ if value.end_with?"\\"
87
+ value = value.chop
88
+ end
89
+ if value.end_with?"\\"
90
+ value = value.chop
91
+ end
92
+ value
93
+ end
94
+
95
+ end
96
+ #
97
+ # BundleGenerater.generate
98
+ # ios_list = ["%@","%d"]
99
+ # str = "{#}盏灯开着,真的吗{#}"
100
+ # i = -1
101
+ # str = str.gsub(/{#}/) do |matched|
102
+ # i+=1
103
+ # ios_list[i]
104
+ # end
105
+ #
106
+ # p str
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-localzedLoader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - jeremylu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A short description of cocoapods-localzedLoader.
42
+ email:
43
+ - 1509028992@qq.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/File_util.rb
49
+ - lib/LanguageDownloader.rb
50
+ - lib/StringElement.rb
51
+ - lib/cocoapods-localzedLoader.rb
52
+ - lib/cocoapods-localzedLoader/command.rb
53
+ - lib/cocoapods-localzedLoader/command/localzedLoader.rb
54
+ - lib/cocoapods-localzedLoader/gem_version.rb
55
+ - lib/cocoapods_plugin.rb
56
+ - lib/ios_bundle_generate.rb
57
+ homepage: https://github.com/EXAMPLE/cocoapods-localzedLoader
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.3.26
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A longer description of cocoapods-localzedLoader.
80
+ test_files: []