cocoapods-localzedLoader 0.1.0 → 0.1.1

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: 7a43a318cdb725be9246383aef2ad2fa3696633c0fdde0c9cf82eb6775929367
4
- data.tar.gz: f51de6244c21075e65cf6c5c09b3f5e060a645e4afd505a96c0571a51a2e6ada
3
+ metadata.gz: 4e1adfbe18a0ab61631028fbfb160cbdd9a68c5f363b2d33e52e132a701f845b
4
+ data.tar.gz: baf34df02655976e699afddeefaf175d4ca483182b4c93403df0ff0e6dac277d
5
5
  SHA512:
6
- metadata.gz: 9f0aa67ff5ae01b846714e953187af46b73b3ce4552c59051b5007a34660471e8589adff1fbc514c7ad5df9ad54c16a2a7a0984575b3f061ec4a9464abc86ddb
7
- data.tar.gz: e70e990cd706febc2061dbd7b8241c99a6737f0d12c33a7256a04721d6bbb3a535fa6a0d7f92b64645f271d499d7519e2d41a253d630195cd1ddacd1cc1737ab
6
+ metadata.gz: 95b18128410916003488e6dbaeb36882e83a7ae8ddc51b6aa073c5fc9dd218f2f1f84eec606b7d63e411e8560a22c74831991279005b6157d4d8f93dd3a8902f
7
+ data.tar.gz: 35d01e3c95d386a1900e88dcd7a6da73d07b5c7b491d8c0db6d37eea94c3935caa329dac40bef90576e3d427d8d2ca1fbcf89a373d471a148f3ff2b439c2690f
@@ -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.1"
3
3
  end
@@ -0,0 +1,161 @@
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 === "NSAppleMusicUsageDescription" || key === "NSLocalNetworkUsageDescription"
56
+ file = "./#{lang}.lproj/InfoPlist.strings"
57
+ File.open(file, "a") do |io|
58
+ io.write str
59
+ end
60
+ elsif INFO_PLIST_MAP.has_key?(key.to_sym)
61
+ # puts "---key:#{key}"
62
+ keys = INFO_PLIST_MAP[key.to_sym]
63
+ keys.each do |info_key|
64
+ file = "./#{lang}.lproj/InfoPlist.strings"
65
+ str = %Q|"#{info_key}" = "#{value}";\n|
66
+ File.open(file, "a") do |io|
67
+ io.write str
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+
75
+ #验证导出的多语言包格式是否正确
76
+ puts '开始校验多语言包格式'.red
77
+ # puts "\e[31m 开始校验多语言包格式\e[0m"
78
+ file_til.getLangList.each do |lang|
79
+ localized_file = "./#{lang}.lproj/Localizable.strings"
80
+ file = "./#{lang}.lproj/InfoPlist.strings"
81
+ if File.exist?(file)
82
+ system("plutil #{file}")
83
+ end
84
+ system("plutil #{localized_file}")
85
+ end
86
+
87
+ #拷贝到代码仓库里
88
+ #查找bundle路径
89
+ bundPath = ""
90
+ info_plist_path = "./AqaraHome/Resource"
91
+ require 'find'
92
+ Find.find("./") do |filePath|
93
+ if filePath.end_with?("LMFramework.bundle")
94
+ bundPath = filePath
95
+ elsif filePath.end_with?("Resource")
96
+ end
97
+ end
98
+ unless bundPath != ""
99
+ puts '没有拷贝'
100
+ return
101
+ end
102
+
103
+ copy_info_plist = false
104
+ file_til.getLangList.each do |lang|
105
+ path = "./#{lang}.lproj/Localizable.strings"
106
+ dest = bundPath + "/#{lang}.lproj"
107
+ FileUtils.mkdir_p dest
108
+ FileUtils.mv("#{path}",dest,force:true)
109
+
110
+ info_plist_file = "./#{lang}.lproj/InfoPlist.strings"
111
+ # puts "path::::::#{info_plist_file}"
112
+ if File.exist? info_plist_file
113
+ copy_info_plist = true
114
+ dest = "./AqaraHome/Resource/#{lang}.lproj"
115
+ FileUtils.mkdir_p dest
116
+ FileUtils.mv("#{info_plist_file}",dest,force:true)
117
+ end
118
+ FileUtils.rm_rf (File.dirname(path))
119
+ end
120
+ puts "多语言拷贝到目录:#{bundPath}"
121
+ if copy_info_plist
122
+ puts "InfoPlist多语言拷贝到目录:#{info_plist_path}"
123
+ end
124
+ end
125
+
126
+ private
127
+ #对多语言的value进行处理
128
+ def self.handleValue(value='',stringElement = nil)
129
+ #替换{=}
130
+ value = value.gsub(/{#}/,"%@")
131
+ value = value.gsub(/""/,'"')
132
+ value = value.gsub(/\\"/,'"')
133
+ value = value.gsub(/""/,'"')
134
+ value = value.gsub(/"/,'\"')
135
+ #fix "common_time_day_with_space" = "\ day \";
136
+ if value.end_with?"\\"
137
+ value = value.chop
138
+ end
139
+ if value.end_with?"\\"
140
+ value = value.chop
141
+ end
142
+ value
143
+ end
144
+
145
+ end
146
+
147
+ # map = {:common_app_name=>["CFBundleDisplayName"]}
148
+ # if map.has_key?("common_app_name".to_sym)
149
+ # puts map[:common_app_name]
150
+ # end
151
+ # BundleGenerater.generate
152
+ # ios_list = ["%@","%d"]
153
+ # str = "{#}盏灯开着,真的吗{#}"
154
+ # i = -1
155
+ # str = str.gsub(/{#}/) do |matched|
156
+ # i+=1
157
+ # ios_list[i]
158
+ # end
159
+ #
160
+ # p str
161
+ # 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.1
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-05-18 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,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