2 rmsgfmt.rb - Generate a .mo
4 Copyright (C) 2003-2009 Masao Mutoh
6 You may redistribute it and/or modify it under the same
7 license terms as Ruby or LGPL.
13 require 'gettext/tools/poparser'
18 module RMsgfmt #:nodoc:
22 bindtextdomain "rgettext"
24 def run(targetfile = nil, output_path = nil) # :nodoc:
26 targetfile, output_path = check_options
29 raise ArgumentError, _("no input files")
32 output_path = "messages.mo"
38 parser.parse_file(targetfile, data)
39 data.save_to_file(output_path)
42 def check_options # :nodoc:
45 opts = OptionParser.new
46 opts.banner = _("Usage: %s input.po [-o output.mo]" % $0)
48 opts.separator(_("Generate binary message catalog from textual translation description."))
50 opts.separator(_("Specific options:"))
52 opts.on("-o", "--output=FILE", _("write output to specified file")) do |out|
56 opts.on_tail("--version", _("display version information and exit")) do
57 puts "#{$0} #{GetText::VERSION}"
58 puts "#{File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
72 # Creates a mo-file from a targetfile(po-file), then output the result to out.
73 # If no parameter is set, it behaves same as command line tools(rmsgfmt).
74 # * targetfile: An Array of po-files or nil.
75 # * output_path: output path.
76 # * Returns: the MOFile object.
77 def rmsgfmt(targetfile = nil, output_path = nil)
78 RMsgfmt.run(targetfile, output_path)
82 if $0 == __FILE__ then