forked from mutoh/gettext
/
rmsgfmt.rb
86 lines (68 loc) · 2.09 KB
/
rmsgfmt.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
# encoding: utf-8
=begin
rmsgfmt.rb - Generate a .mo
Copyright (C) 2003-2009 Masao Mutoh
You may redistribute it and/or modify it under the same
license terms as Ruby or LGPL.
=end
require 'optparse'
require 'fileutils'
require 'gettext'
require 'gettext/tools/poparser'
require 'rbconfig'
module GetText
module RMsgfmt #:nodoc:
extend GetText
extend self
bindtextdomain "rgettext"
def run(targetfile = nil, output_path = nil) # :nodoc:
unless targetfile
targetfile, output_path = check_options
end
unless targetfile
raise ArgumentError, _("no input files")
end
unless output_path
output_path = "messages.mo"
end
parser = PoParser.new
data = MOFile.new
parser.parse_file(targetfile, data)
data.save_to_file(output_path)
end
def check_options # :nodoc:
output = nil
opts = OptionParser.new
opts.banner = _("Usage: %s input.po [-o output.mo]" % $0)
opts.separator("")
opts.separator(_("Generate binary message catalog from textual translation description."))
opts.separator("")
opts.separator(_("Specific options:"))
opts.on("-o", "--output=FILE", _("write output to specified file")) do |out|
output = out
end
opts.on_tail("--version", _("display version information and exit")) do
puts "#{$0} #{GetText::VERSION}"
puts "#{File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
exit
end
opts.parse!(ARGV)
if ARGV.size == 0
puts opts.help
exit 1
end
[ARGV[0], output]
end
end
# Creates a mo-file from a targetfile(po-file), then output the result to out.
# If no parameter is set, it behaves same as command line tools(rmsgfmt).
# * targetfile: An Array of po-files or nil.
# * output_path: output path.
# * Returns: the MOFile object.
def rmsgfmt(targetfile = nil, output_path = nil)
RMsgfmt.run(targetfile, output_path)
end
end
if $0 == __FILE__ then
GetText.rmsgfmt
end