-
Notifications
You must be signed in to change notification settings - Fork 21
/
maker.rb
executable file
·118 lines (109 loc) · 3.33 KB
/
maker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env ruby
require "zip"
require "net/http"
require "open3"
Zip.setup do |c|
c.on_exists_proc = true
c.continue_on_exists_proc = true
c.unicode_names = true
c.default_compression = Zlib::BEST_COMPRESSION
c.force_entry_names_encoding = "UTF-8"
end
build_version = ENV["TRAVIS_BUILD_NUMBER"]
log_url = ENV["TRAVIS_JOB_WEB_URL"]
TARGET_VERSION = File.read("VERSION").chomp
# language = "zh"
pwd = Dir.pwd
Dir.mkdir("dist") unless Dir.exist?("dist")
package_name = "Chinese_Translation_zh-CN.ts3_translation"
def make_release
case RUBY_PLATFORM
when /ix/i, /ux/i, /gnu/i, /bsd/i
# "unix"
lrelease = `which lrelease`.split[0]
when /win/i, /ming/i
# "windows"
lrelease = `where lrelease`.split[0]
else
# "other"
exit(1)
end
translated_count = 0
total_count = 0
translated = /(?:Generated|生成)\s(\d+)\s(?:translation|条翻译)/
untranslated = /(?:Ignored|忽略)\s(\d+)\s(?:untranslated|条未翻译源文本)/
Dir.glob("src/*_zh.ts") do |file|
puts file
output = "dist/#{file[4...-3]}.qm"
stdin, stdout, stderr = Open3.popen3(lrelease, file, "-qm", output)
index = 0
stdout.each_line do |line|
unless /qt_zh/.match?(file)
if index == 1
translated_count += translated.match(line)[1].to_i
total_count += translated.match(line)[1].to_i
end
if index == 2
total_count += untranslated.match(line)[1].to_i
end
end
puts line
index += 1
end
stdout.close
unless stderr.nil?
stderr.each_line { |line| puts line }
stderr.close
end
puts "" # new line
end
# send_progress(translated_count, total_count)
end
def send_progress(done, total)
percentage = Rational(done * 100, total).round(2).to_f
info = "当前进度:\n#{done}/#{total}\n#{percentage}%\n".freeze
puts info
telegram_push(info) unless ARGV[0] == "debug"
end
def telegram_push(string)
tg_api = ENV["TG_API"]
group_id = ENV["TG_GROUP_ID"]
uri = URI("https://api.telegram.org/bot#{tg_api}/sendMessage")
querystring = {chat_id: group_id, text: string}
uri.query = URI.encode_www_form(querystring)
res = Net::HTTP.get_response(uri)
puts (res.code == "200") ? "\n推送成功" : "\n推送失败"
end
def make_package(zipfile_name, build_version = nil, log_url = nil)
File.open("dist/package.ini", "w") do |file|
package_info = [
"Name = TeamSpeak 3 简体中文汉化包 目标软件版本: #{TARGET_VERSION}",
"Type = Translation",
"Author = 寂听 & EdisonJwa",
"Version = snapshot##{build_version}",
"Platforms = ",
"Description = 源代码: https://github.com/jitingcn/TS3-Translation_zh-CN" +
" 构建日志: #{log_url unless log_url.nil?}"
]
file.write(package_info.join("\n"))
end
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
qm_files = Dir.glob("dist/*.qm")
qm_files.each do |file|
file = file.split("/")
zipfile.add("translations/" + file[1], File.join(file))
end
zipfile.add("package.ini", File.join(["dist", "package.ini"]))
end
end
def debug
case RUBY_PLATFORM
when /ix/i, /ux/i, /gnu/i, /bsd/i
FileUtils.cp Dir.glob("dist/*.qm"), "#{Dir.home}/.ts3client/translations", verbose: true
else
exit
end
end
make_release
make_package(package_name) unless ARGV[0] == "debug"
debug if ARGV[0] == "debug"