mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2025-02-26 08:22:31 +00:00
dev tools: add_po support for Qt .ts and .qm files
This commit is contained in:
parent
6bf5f77c64
commit
36f9dd2819
@ -2,6 +2,7 @@
|
||||
# coding: utf-8
|
||||
|
||||
require "fileutils"
|
||||
require "pathname"
|
||||
require "shellwords"
|
||||
require "tmpdir"
|
||||
|
||||
@ -50,11 +51,56 @@ module AddPo
|
||||
fail "bsdtar failed for #{file_name}" unless $?.exitstatus == 0
|
||||
end
|
||||
|
||||
def self.handle_qm file_name
|
||||
Dir.mktmpdir do |dir|
|
||||
tm_name = Pathname.new(file_name).basename.sub_ext(".tm").to_s
|
||||
system "lconvert -i #{Shellwords.escape(file_name)} -o #{Shellwords.escape(tm_name)}"
|
||||
|
||||
fail "lconvert failed for #{file_name}" unless $?.exitstatus == 0
|
||||
|
||||
handle_ts tm_name
|
||||
|
||||
File.unlink file_name
|
||||
end
|
||||
end
|
||||
|
||||
def self.handle_ts file_name, language = nil
|
||||
content = IO.
|
||||
readlines(file_name).
|
||||
map(&:chomp)
|
||||
|
||||
language = content.
|
||||
map { |line| /<TS [^>]* language="([a-z_@]+)"/ix.match(line) ? $1 : nil }.
|
||||
compact.
|
||||
first
|
||||
|
||||
if !language
|
||||
language = ENV['TS'] if ENV['TS'] && !ENV['TS'].empty?
|
||||
language = $1 if !language && /qtbase_([a-zA-Z_@]+)/.match(file_name)
|
||||
end
|
||||
|
||||
fail "Unknown language for Qt TS file #{file_name} (set TS)" if !language
|
||||
|
||||
target = "#{$po_dir}/qt/qtbase_#{language}.ts"
|
||||
|
||||
if !FileTest.exists?(target) && /^([a-z]+)_[a-z]+/i.match(language)
|
||||
target = "#{$po_dir}/qt/qtbase_#{$1}.ts"
|
||||
end
|
||||
|
||||
fail "target file does not exist yet: #{target} (wrong language?)" if !FileTest.exists?(target)
|
||||
|
||||
File.open(target, "w") { |file| file.puts content.map(&:chomp).join("\n") }
|
||||
File.unlink file_name
|
||||
File.chmod 0644, target
|
||||
end
|
||||
|
||||
def self.handle_archive file_name, archive_type
|
||||
Dir.mktmpdir do |dir|
|
||||
Dir.chdir(dir) do
|
||||
send "unpack_#{archive_type}".to_sym, file_name
|
||||
Dir["**/*.po"].each { |unpacked_file| handle_po unpacked_file }
|
||||
Dir["**/*.qm"].each { |unpacked_file| handle_qm unpacked_file }
|
||||
Dir["**/*.ts"].each { |unpacked_file| handle_ts unpacked_file }
|
||||
end
|
||||
end
|
||||
|
||||
@ -67,6 +113,8 @@ module AddPo
|
||||
return handle_archive(file_name, :p7z) if /\.7z$/i.match file_name
|
||||
return handle_archive(file_name, :tar) if /\.tar(?:\.(?:gz|bz2|xz))?$/i.match file_name
|
||||
return handle_po(file_name) if /\.po$/i.match file_name
|
||||
return handle_qm(file_name) if /\.qm$/i.match file_name
|
||||
return handle_ts(file_name) if /\.ts$/i.match file_name
|
||||
fail "Don't know how to handle #{file_name}"
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user