cocoapods-aomi-bin 0.0.7 → 0.1.3

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: b7481159dec769eae8103bda57cb36e305af85b987f1ef0599efe8d195d0d710
4
- data.tar.gz: 51db4957eafd463de1746a986f66cf4e3e0c59dde020c16adfcff1facdf22b8e
3
+ metadata.gz: 761d8708d5a6a58529721f57a03176cc6b304a299d73786da206eb2a891b55d6
4
+ data.tar.gz: b74e89002309aa292a591e0a37af7cc2f02bb0064ee517d12cd86cfc03e17936
5
5
  SHA512:
6
- metadata.gz: 2ffb92c51c36a24ea08db92b8d6e17b30536bb273f726e0f6a93b1e94326f51c07dcf975199c38e0ae397825fe5fdf25ca18a848355ecea4cda9845adc8b52e5
7
- data.tar.gz: 2efcd36bbb1c8103b9cc7da90f6b2aa69939bcd5fa4d63c418c0e3da1867abcaf3a9ea7df601223790a4bfdbb267368f8cfc4cd04356d1a02eefc3485e002909
6
+ metadata.gz: 9a7eddbb8207315d61bda960964b0c051903f8d54c851959383a073a32786b2738a1b0eaf3e2c52ccf56db59fb6869f118b77ea4296ad0b71529f69966f8036f
7
+ data.tar.gz: d7e57971be1d7f009f5699c43ebd72a9191949cc30c051e3776592d72f5ec831bc0cb568933c4991bb746832079b36db1dcb15ad3f5212b3ab617d0e316136dc
@@ -7,6 +7,8 @@ require 'cocoapods-lhj-bin/command/bin/update'
7
7
  require 'cocoapods-lhj-bin/command/bin/install'
8
8
  require 'cocoapods-lhj-bin/command/bin/import'
9
9
  require 'cocoapods-lhj-bin/command/bin/local'
10
+ require 'cocoapods-lhj-bin/command/bin/trans'
11
+ require 'cocoapods-lhj-bin/command/bin/fetch'
10
12
  require 'cocoapods-lhj-bin/command/bin/lhj'
11
13
  require 'cocoapods-lhj-bin/command/bin/config/push'
12
14
  require 'cocoapods-lhj-bin/command/bin/oss/list'
@@ -17,6 +17,11 @@ module Pod
17
17
  push
18
18
  end
19
19
 
20
+ def push_cn_hk
21
+ file = File.expand_path("#{Pod::Config.instance.home_dir}/zh2hant.yml")
22
+ CBin::OSS::Helper.instance.upload('zh2hant.yml', file)
23
+ end
24
+
20
25
  def push
21
26
  file = File.expand_path("#{Pod::Config.instance.home_dir}/bin_dev.yml")
22
27
  CBin::OSS::Helper.instance.upload('bin_dev.yml', file)
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+
5
+ module Pod
6
+ class Command
7
+ class Bin < Command
8
+ class Fetch < Bin
9
+ self.summary = '提取源码的中文字符串,并生成中英文对照csv文件'
10
+
11
+ def self.options
12
+ [
13
+ %w[--file-type 从文件扩展名中查找中文字符串,默认为m,h],
14
+ %w[--file-name 生成csv文件名,默认为gen_cn_key.csv]
15
+ ]
16
+ end
17
+
18
+ def initialize(argv)
19
+ @current_path = argv.shift_argument || Dir.pwd
20
+ @file_type = argv.option('file-type', 'm,h')
21
+ @file_name = argv.option('file-name', 'gen_cn_key.csv')
22
+ @cn_keys = []
23
+ super
24
+ end
25
+
26
+ def run
27
+ handle_files
28
+ gen_csv
29
+ end
30
+
31
+ def gen_csv
32
+ file = File.join(@current_path, @file_name)
33
+ FileUtils.rm_rf(file) if File.exist?(file)
34
+ CSV.open(file, 'wb:utf-8') do |csv|
35
+ csv << %w[国际化key 中文 英文 原字符 所在文件 文件路径]
36
+ @cn_keys.each do |k|
37
+ csv << [k[:key], k[:cn], k[:en], k[:str], k[:fname], k[:dirname]]
38
+ end
39
+ end
40
+ UI.puts "生成csv文件完成.\n文件路径:#{File.absolute_path(file)}".green
41
+ end
42
+
43
+ def handle_files
44
+ Dir.glob("#{@current_path}/**/*.{#{@file_type}}").each do |f|
45
+ handle_file f
46
+ end
47
+ end
48
+
49
+ def handle_file(file)
50
+ File.open(file, 'r') do |f|
51
+ f.each_line do |line|
52
+ handle_line(file, line) if line =~ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
53
+ end
54
+ end
55
+ end
56
+
57
+ def handle_line(file, line)
58
+ reg = /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
59
+ ma = reg.match(line)
60
+ str = ma[0]
61
+ key = "#{File.basename(file, '.*')}.#{rand(36**8).to_s(36)}"
62
+ @cn_keys << { key: key, cn: str[2, str.length - 3], en: '', str: str, dirname: File.dirname(file),
63
+ fname: File.basename(file) }
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,38 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'csv'
4
+ require 'cocoapods-lhj-bin/helpers/trans_helper'
4
5
 
5
6
  module Pod
6
7
  class Command
7
8
  class Bin < Command
8
9
  class Local < Bin
9
- self.summary = '生成国际化文件'
10
+ self.summary = '根据中英文对照csv文件,生成国际化配置, 及批量更新源码(使用国际化写法)'
10
11
 
11
12
  def self.options
12
13
  [
13
- %w[--key Key在csv中第几列,默认为0],
14
- %w[--cn 中文在csv中第几列,默认为1],
15
- %w[--en 英文文在csv中第几列,默认为2]
14
+ %w[--key-col 国际化key在csv中第几列,默认为0],
15
+ %w[--cn-col 中文在csv中第几列,默认为1],
16
+ %w[--en-col 英文在csv中第几列,默认为2],
17
+ %w[--csv-file csv文件名,默认为当前目录下所有csv文件],
18
+ %w[--gen-file 生成配置文件名,默认名为: Localizable.strings],
19
+ %w[--modify-source 修改源码,使用国际化key代替中文字符串],
20
+ %w[--modify-file-type 需要修改源码的文件类型,默认为m,h],
21
+ %w[--modify-format-string 修改为国际化后的字符格式,默认为NSLocalizedString(%s, @"")]
16
22
  ]
17
23
  end
18
24
 
19
25
  def initialize(argv)
20
26
  @current_path = argv.shift_argument || Dir.pwd
21
- @key_col = argv.option('key').to_i || 0
22
- @cn_col = argv.option('cn').to_i || 1
23
- @en_col = argv.option('en').to_i || 2
27
+ @key_col = argv.option('key-col', 0).to_i
28
+ @cn_col = argv.option('cn-col', 1).to_i
29
+ @en_col = argv.option('en-col', 2).to_i
30
+ @csv_file = argv.option('csv-file', '*')
31
+ @gen_file_name = argv.option('gen-file', 'Localizable.strings')
32
+ @modify_source_flag = argv.flag?('modify-source', false)
33
+ @modify_file_type = argv.option('modify-file-type', 'm,h')
34
+ @modify_format_string = argv.option('modify-format-string', 'NSLocalizedString(%s, @"")')
24
35
  @key_map = {}
25
- @trans_map = {}
26
- @trans_map_invert = {}
27
36
  super
28
37
  end
29
38
 
30
39
  def run
31
- load_trans_map
32
40
  read_csv_file
33
- write_en_strings
34
- write_zh_cn_strings
35
- write_zh_hk_strings
41
+ if @key_map.keys.length.positive?
42
+ # write_en_strings
43
+ # write_zh_cn_strings
44
+ # write_zh_hk_strings
45
+ handle_modify_source if @modify_source_flag
46
+ else
47
+ UI.puts "获取中英文映射文件失败, 检查参数--csv-file=xx是否正常\n".red
48
+ end
36
49
  end
37
50
 
38
51
  def en_dir_name
@@ -48,34 +61,67 @@ module Pod
48
61
  end
49
62
 
50
63
  def generate_file_name
51
- 'Localizable.strings'
64
+ @gen_file_name
52
65
  end
53
66
 
54
- def yaml_file
55
- File.join(Pod::Config.instance.home_dir, 'zh2hant.yml')
67
+ def handle_modify_source
68
+ UI.puts '开始修改源码开始'
69
+ Dir.glob("#{@current_path}/**/*.{#{@modify_file_type}}").each do |f|
70
+ handle_modify_file f if File.stat(f).writable?
71
+ end
72
+ UI.puts '开始修改源码结束'
56
73
  end
57
74
 
58
- def load_trans_map
59
- require 'yaml'
60
- down_load_yaml unless File.exist?(yaml_file)
61
- contents = YAML.safe_load(File.open(yaml_file))
62
- @trans_map = contents.to_hash
63
- @trans_map_invert = @trans_map.invert
75
+ def handle_modify_file(file)
76
+ str = modify_file_string(file)
77
+ File.open(file, 'w+') do |f|
78
+ f.write(str)
79
+ end
64
80
  end
65
81
 
66
- def down_load_yaml
67
- require 'open-uri'
68
- UI.puts "开始下载简繁配置文件...\n"
69
- URI.open('http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/zh2hant.yml') do |i|
70
- File.open(yaml_file, 'w+') do |f|
71
- f.write(i.read)
82
+ def modify_file_string(file)
83
+ str = ''
84
+ File.open(file, 'r') do |f|
85
+ f.each_line do |line|
86
+ str += modify_format_string(f, line)
72
87
  end
73
88
  end
89
+ str
90
+ end
91
+
92
+ def modify_format_string(file, line)
93
+ result = line
94
+ result = handle_modify_line line if line =~ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
95
+ result
96
+ end
97
+
98
+ def handle_modify_line(line)
99
+ result = line
100
+ reg = /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
101
+ ma = reg.match(line)
102
+ key = find_key_by_cn_val(ma[0])
103
+ if key
104
+ val = format(@modify_format_string, "@\"#{key}\"")
105
+ result = line.gsub(ma[0], val)
106
+ end
107
+ result
108
+ end
109
+
110
+ def find_key_by_cn_val(val)
111
+ cn_key = val[2, val.length - 3]
112
+ index = @key_map.values.find_index do |obj|
113
+ /^#{cn_key}$/ =~ obj[:zh]
114
+ end
115
+ @key_map.values[index][:key] if index
74
116
  end
75
117
 
76
118
  def read_csv_file
77
- Dir.glob("#{@current_path}/**/*.csv").each do |p|
78
- CSV.foreach(p) { |row| @key_map[row[@key_col]] = { zh: row[@cn_col], en: row[@en_col] } unless row[0] =~ /[\u4e00-\u9fa5]/ }
119
+ path = "#{@current_path}/#{@csv_file}.csv"
120
+ Dir.glob(path).each do |p|
121
+ CSV.foreach(p) do |row|
122
+ key = row[@key_col]
123
+ @key_map[key] = { key: key, zh: row[@cn_col], en: row[@en_col] } unless key =~ /[\u4e00-\u9fa5]/
124
+ end
79
125
  end
80
126
  end
81
127
 
@@ -85,31 +131,15 @@ module Pod
85
131
  val = v[type]
86
132
  case area
87
133
  when :hk
88
- val = trans_zh_hk_str val
134
+ val = CBin::Trans::Helper.instance.trans_zh_hk_str val
89
135
  when :cn
90
- val = trans_zh_cn_str val
136
+ val = CBin::Trans::Helper.instance.trans_zh_cn_str val
91
137
  end
92
138
  str += "\"#{k}\" = \"#{val}\";\n"
93
139
  end
94
140
  str
95
141
  end
96
142
 
97
- def trans_zh_cn_str(input)
98
- out = []
99
- input.each_char do |c|
100
- out << (@trans_map_invert[c] || c)
101
- end
102
- out.join('')
103
- end
104
-
105
- def trans_zh_hk_str(input)
106
- out = []
107
- input.each_char do |c|
108
- out << (@trans_map[c] || c)
109
- end
110
- out.join('')
111
- end
112
-
113
143
  def write_to_file(file, contents)
114
144
  FileUtils.rm_rf(file) if File.exist?(file)
115
145
  FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(File.dirname(file))
@@ -126,17 +156,20 @@ module Pod
126
156
  def write_en_strings
127
157
  file = File.join(@current_path, en_dir_name, generate_file_name)
128
158
  generate_file(file, :en)
159
+ UI.puts "生成英文配置完成.文件路径:#{File.absolute_path(file)}\n".green
129
160
  end
130
161
 
131
162
  def write_zh_cn_strings
132
163
  file = File.join(@current_path, zh_cn_dir_name, generate_file_name)
133
164
  generate_file(file, :zh)
165
+ UI.puts "生成简体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
134
166
  end
135
167
 
136
168
  def write_zh_hk_strings
137
169
  file = File.join(@current_path, zh_hk_dir_name, generate_file_name)
138
170
  content = format_str(:zh, :hk)
139
171
  write_to_file(file, content)
172
+ UI.puts "生成繁体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
140
173
  end
141
174
  end
142
175
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+ require 'cocoapods-lhj-bin/helpers/trans_helper'
3
+
4
+ module Pod
5
+ class Command
6
+ class Bin < Command
7
+ class Trans < Bin
8
+ self.summary = '源码中的简繁体转换'
9
+
10
+ def self.options
11
+ [
12
+ %w[--file-type 文件扩展名,默认为m,h,pch,xib],
13
+ %w[--zh-cn 转成简体中文,默认转成繁体]
14
+ ]
15
+ end
16
+
17
+ def initialize(argv)
18
+ @current_path = argv.shift_argument || Dir.pwd
19
+ @file_type = argv.option('file-type', 'm,h,pch,xib')
20
+ @zh_cn = argv.flag?('zh-cn', false)
21
+ super
22
+ end
23
+
24
+ def run
25
+ handler_files
26
+ end
27
+
28
+ def handler_files
29
+ Dir.glob("#{@current_path}/**/*.{#{@file_type}}").each do |f|
30
+ handler_file f
31
+ end
32
+ end
33
+
34
+ def handler_file(file)
35
+ str = format_file_string(file)
36
+ File.open(file, 'w+') do |f|
37
+ f.write(str)
38
+ end
39
+ end
40
+
41
+ def format_file_string(file)
42
+ str = ''
43
+ File.open(file, 'r+') do |f|
44
+ f.each_line do |line|
45
+ str += format_line_string(line)
46
+ end
47
+ end
48
+ str
49
+ end
50
+
51
+ def format_line_string(line)
52
+ result = line
53
+ if line =~ /[\u4e00-\u9fa5]/
54
+ result = CBin::Trans::Helper.instance.trans_zh_cn_str(line) if @zh_cn
55
+ result = CBin::Trans::Helper.instance.trans_zh_hk_str(line) unless @zh_cn
56
+ end
57
+ result
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,5 +1,5 @@
1
1
  module CBin
2
- VERSION = '0.0.7'
2
+ VERSION = '0.1.3'
3
3
  end
4
4
 
5
5
  module Pod
@@ -0,0 +1,49 @@
1
+
2
+ module CBin
3
+ class Trans
4
+ class Helper
5
+
6
+ def self.instance
7
+ @instance ||= new
8
+ end
9
+
10
+ def yaml_file
11
+ File.join(Pod::Config.instance.home_dir, 'zh2hant.yml')
12
+ end
13
+
14
+ def load_trans_map
15
+ require 'yaml'
16
+ down_load_yaml unless File.exist?(yaml_file)
17
+ contents = YAML.safe_load(File.open(yaml_file))
18
+ contents.to_hash
19
+ end
20
+
21
+ def down_load_yaml
22
+ require 'open-uri'
23
+ URI.open('http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/zh2hant.yml') do |i|
24
+ File.open(yaml_file, 'w+') do |f|
25
+ f.write(i.read)
26
+ end
27
+ end
28
+ end
29
+
30
+ def trans_zh_cn_str(input)
31
+ @trans_map_invert ||= load_trans_map.invert
32
+ out = []
33
+ input.each_char do |c|
34
+ out << (@trans_map_invert[c] || c)
35
+ end
36
+ out.join('')
37
+ end
38
+
39
+ def trans_zh_hk_str(input)
40
+ @trans_map ||= load_trans_map
41
+ out = []
42
+ input.each_char do |c|
43
+ out << (@trans_map[c] || c)
44
+ end
45
+ out.join('')
46
+ end
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-aomi-bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-13 00:00:00.000000000 Z
11
+ date: 2021-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: parallel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.20.1
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.20.1
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: aliyun-sdk
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -111,6 +111,7 @@ files:
111
111
  - lib/cocoapods-lhj-bin/command/bin/code.rb
112
112
  - lib/cocoapods-lhj-bin/command/bin/config/push.rb
113
113
  - lib/cocoapods-lhj-bin/command/bin/dup.rb
114
+ - lib/cocoapods-lhj-bin/command/bin/fetch.rb
114
115
  - lib/cocoapods-lhj-bin/command/bin/import.rb
115
116
  - lib/cocoapods-lhj-bin/command/bin/init.rb
116
117
  - lib/cocoapods-lhj-bin/command/bin/initHotKey.rb
@@ -123,6 +124,7 @@ files:
123
124
  - lib/cocoapods-lhj-bin/command/bin/repo/update.rb
124
125
  - lib/cocoapods-lhj-bin/command/bin/spec/create.rb
125
126
  - lib/cocoapods-lhj-bin/command/bin/spec/push.rb
127
+ - lib/cocoapods-lhj-bin/command/bin/trans.rb
126
128
  - lib/cocoapods-lhj-bin/command/bin/update.rb
127
129
  - lib/cocoapods-lhj-bin/config/config.rb
128
130
  - lib/cocoapods-lhj-bin/config/config_asker.rb
@@ -143,6 +145,7 @@ files:
143
145
  - lib/cocoapods-lhj-bin/helpers/spec_creator.rb
144
146
  - lib/cocoapods-lhj-bin/helpers/spec_files_helper.rb
145
147
  - lib/cocoapods-lhj-bin/helpers/spec_source_creator.rb
148
+ - lib/cocoapods-lhj-bin/helpers/trans_helper.rb
146
149
  - lib/cocoapods-lhj-bin/helpers/upload_helper.rb
147
150
  - lib/cocoapods-lhj-bin/native.rb
148
151
  - lib/cocoapods-lhj-bin/native/acknowledgements.rb