Class: Pod::Command::Bin::Trans
Class Method Summary
collapse
Instance Method Summary
collapse
#validate!
#binary_spec, #binary_spec_files, #binary_template_spec, #binary_template_spec_file, #binary_template_spec_files, #clear_binary_spec_file_if_needed, #code_spec, #code_spec_files, #create_binary_spec_file, #find_spec_file, #spec_files
#binary_source, #code_source, #sources_manager, #sources_option, #valid_sources
Constructor Details
#initialize(argv) ⇒ Trans
Returns a new instance of Trans.
17
18
19
20
21
22
|
# File 'lib/cocoapods-lhj-bin/command/bin/trans.rb', line 17
def initialize(argv)
@current_path = argv.shift_argument || Dir.pwd
@file_type = argv.option('file-type', 'm,h,pch,xib')
@zh_cn = argv.flag?('zh-cn', false)
super
end
|
Class Method Details
.options ⇒ Object
10
11
12
13
14
15
|
# File 'lib/cocoapods-lhj-bin/command/bin/trans.rb', line 10
def self.options
[
%w[--file-type 文件扩展名,默认为m,h,pch,xib],
%w[--zh-cn 转成简体中文,默认转成繁体]
]
end
|
Instance Method Details
41
42
43
44
45
46
47
48
49
|
# File 'lib/cocoapods-lhj-bin/command/bin/trans.rb', line 41
def format_file_string(file)
str = ''
File.open(file, 'r+') do |f|
f.each_line do |line|
str += format_line_string(line)
end
end
str
end
|
51
52
53
54
55
56
57
58
|
# File 'lib/cocoapods-lhj-bin/command/bin/trans.rb', line 51
def format_line_string(line)
result = line
if line =~ /[\u4e00-\u9fa5]/
result = CBin::Trans::Helper.instance.trans_zh_cn_str(line) if @zh_cn
result = CBin::Trans::Helper.instance.trans_zh_hk_str(line) unless @zh_cn
end
result
end
|
#handler_file(file) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/cocoapods-lhj-bin/command/bin/trans.rb', line 34
def handler_file(file)
str = format_file_string(file)
File.open(file, 'w+') do |f|
f.write(str)
end
end
|
#handler_files ⇒ Object
28
29
30
31
32
|
# File 'lib/cocoapods-lhj-bin/command/bin/trans.rb', line 28
def handler_files
Dir.glob("#{@current_path}/**/*.{#{@file_type}}").each do |f|
handler_file f
end
end
|
#run ⇒ Object
24
25
26
|
# File 'lib/cocoapods-lhj-bin/command/bin/trans.rb', line 24
def run
handler_files
end
|