lhj-tools 0.2.71 → 0.2.72

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: e9f34207902253cd7e343b132210af875a99f7b0cbc17a14f811e4044af781ce
4
- data.tar.gz: c85d8572ea5c1e480753aa2a1f8f842882ae6ef374cb869f98789583adbea7fb
3
+ metadata.gz: 860185cadd542b509b1d85d198c0a3ca6c7ec7bb2188dda3b26b2f7521f6ace0
4
+ data.tar.gz: 674170f9e7b21c43965218b22a349b4cd49a706513ec1cbd486662a9d23e2c40
5
5
  SHA512:
6
- metadata.gz: ee0d0dce1b75b11a7d7894d24e161698e03e438c1d61f60058c3acda029cccc7f1cbf0e02352fa49cee03c7ec94b8658a407bf5a14a1b8514b00bd78718619ce
7
- data.tar.gz: f7f2d0d2f5d4916b3b363aeedb588c00814f7b4ae89fb1264841b226365d5574a8743b7468b9f63aad57d9139cf0ea938684c16143b0b789e5086cc4adfd4d49
6
+ metadata.gz: 18ce56d41b9fa74f995c137f10f5e5608b95e709e1dc88c07dc6f92791f2e5a1937ed0f556fd5aadde9a4561b58f2bc14d2d2848de6c2932a132ac7d5a16c82f
7
+ data.tar.gz: 93e29e58679ed49389f7dae92badcd7ae738dec2bc56e93bdb301950f9d9f7708466f8f1d9bd891f209a30d9f9c358159ee925c373505079c82e9e15821657e6
@@ -44,8 +44,8 @@ module Lhj
44
44
  def gen_csv
45
45
  file = File.join(@current_path, csv_file_name)
46
46
  FileUtils.rm_rf(file) if File.exist?(file)
47
- CSV.open(file, 'wb:utf-8') do |csv|
48
- csv << %w[国际化key 中文 英文 所在文件 文件路径 行号]
47
+ header = %w[国际化key 中文 英文 所在文件 文件路径 行号]
48
+ CSV.open(file, 'wb:utf-8', headers: true, converters: :numeric, header_converters: :symbol) do |csv|
49
49
  @cn_keys.each do |k|
50
50
  csv << [k[:key], k[:cn], k[:en], k[:fname], k[:dirname], k[:idx]]
51
51
  end
@@ -56,8 +56,8 @@ module Lhj
56
56
  def gen_csv_unique
57
57
  file = File.join(@current_path, unique_csv_file_name)
58
58
  FileUtils.rm_rf(file) if File.exist?(file)
59
- CSV.open(file, 'wb:utf-8') do |csv|
60
- csv << %w[国际化key 中文 英文 所在文件 文件路径 行号]
59
+ header = %w[国际化key 中文 英文 所在文件 文件路径 行号]
60
+ CSV.open(file, 'wb:utf-8', headers: true, write_headers: header) do |csv|
61
61
  @cn_keys.uniq { |k| k[:cn] }.each do |k|
62
62
  csv << [k[:key], k[:cn], k[:en], k[:fname], k[:dirname], k[:idx]]
63
63
  end
@@ -27,7 +27,7 @@ module Lhj
27
27
  write_zh_cn_strings
28
28
  handle_modify_source if @modify_source_flag
29
29
  else
30
- puts "获取中英文映射文件失败, 检查参数--read-csv-file=xx是否正常\n"
30
+ puts "获取中英文映射文件失败\n"
31
31
  end
32
32
  end
33
33
 
@@ -45,7 +45,11 @@ module Lhj
45
45
  en_col = @cli.ask('中英对应照csv<<英文>>所在的列, 默认为2: '.yellow, Integer) do |q|
46
46
  q.default = 2
47
47
  end
48
- read_csv_file(csv_file, key_col, cn_col, en_col)
48
+ begin
49
+ read_csv_file(csv_file, key_col, cn_col, en_col)
50
+ rescue ArgumentError => e
51
+ puts e.message.red
52
+ end
49
53
  need_add_other = @cli.ask('是否继续添加csv文件yes?: '.yellow, ->(yn) { yn.downcase[0] == 'y' }) do |q|
50
54
  q.default = false
51
55
  end
@@ -58,23 +62,23 @@ module Lhj
58
62
  time = Time.now.strftime('%Y%m%d_%H%M')
59
63
  q.default = "Localizable_#{time}.strings"
60
64
  end
61
- @en_dir_name = @cli.ask('生成英文.strings文件对应路径: '.yellow, String) do |q|
65
+ @en_dir_name = @cli.ask('存放英文的文件夹: '.yellow, String) do |q|
62
66
  q.default = 'MacauLife/en.lproj'
63
67
  end
64
- @zh_hk_dir_name = @cli.ask('生成繁体.strings文件对应路径: '.yellow, String) do |q|
68
+ @zh_hk_dir_name = @cli.ask('存放繁体的文件夹: '.yellow, String) do |q|
65
69
  q.default = 'MacauLife/zh-Hant.lproj'
66
70
  end
67
- @zh_cn_dir_name = @cli.ask('生成简体.strings文件对应路径: '.yellow, String) do |q|
71
+ @zh_cn_dir_name = @cli.ask('存放简体的文件夹: '.yellow, String) do |q|
68
72
  q.default = 'MacauLife/zh-Hans.lproj'
69
73
  end
70
74
  @modify_source_flag = @cli.agree(HighLine.color('是否要修改源码yes?:', :red))
71
- if @modify_source_flag
72
- @modify_file_type = @cli.ask('需要修改源码的文件类型: '.yellow, String) do |q|
73
- q.default = 'm,h'
74
- end
75
- @modify_format_string = @cli.ask('修改为国际化后的字符格式: '.yellow, String) do |q|
76
- q.default = 'MLLocalizedString(%s)'
77
- end
75
+ return unless @modify_source_flag
76
+
77
+ @modify_file_type = @cli.ask('源码的文件类型: '.yellow, String) do |q|
78
+ q.default = 'm,h'
79
+ end
80
+ @modify_format_string = @cli.ask('国际化字符格式: '.yellow, String) do |q|
81
+ q.default = 'MLLocalizedString(%s)'
78
82
  end
79
83
  end
80
84
 
@@ -88,17 +92,22 @@ module Lhj
88
92
  end
89
93
 
90
94
  def read_csv_file(file, key_c, cn_c, en_c)
91
- # trans_hk = false
92
- # trans_cn = true
93
- CSV.foreach(file) do |row|
94
- if row.length > 2
95
- key = row[key_c]
96
- cn_str = row[cn_c]
97
- hk_str = row[cn_c]
98
- # cn_str = Lhj::Trans::Helper.instance.trans_zh_cn_str(cn_str) if trans_cn
99
- hk_str = Lhj::Trans::Helper.instance.trans_zh_hk_str(hk_str) if hk_str&.length&.positive?
100
- @key_map[key] = { key: key, cn: cn_str, hk: hk_str, en: row[en_c] } unless key =~ /[\u4e00-\u9fa5]/
95
+ begin
96
+ current_row = nil
97
+ CSV.foreach(file, quote_char: ',') do |row|
98
+ current_row = row
99
+ if row.length > 2
100
+ key = row[key_c]
101
+ cn_str = row[cn_c]
102
+ hk_str = row[cn_c]
103
+ # cn_str = Lhj::Trans::Helper.instance.trans_zh_cn_str(cn_str) if trans_cn
104
+ hk_str = Lhj::Trans::Helper.instance.trans_zh_hk_str(hk_str) if hk_str&.length&.positive?
105
+ @key_map[key] = { key: key, cn: cn_str, hk: hk_str, en: row[en_c] } unless key =~ /[\u4e00-\u9fa5]/
106
+ end
101
107
  end
108
+ rescue CSV::MalformedCSVError => e
109
+ error = "读取csv异常,文件中的第#{e.line_number}行格式有误!! \n 上一行信息#{current_row}"
110
+ raise ArgumentError, error
102
111
  end
103
112
  end
104
113
 
data/lib/lhj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lhj
4
- VERSION = '0.2.71'
4
+ VERSION = '0.2.72'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.71
4
+ version: 0.2.72
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-02 00:00:00.000000000 Z
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj