OSDN Git Service

2aa428c553c90728a589f33ae130e4318e45b3ec
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / gettext-2.1.0 / lib / gettext / tools / rmsgfmt.rb
1 =begin
2   rmsgfmt.rb - Generate a .mo
3
4   Copyright (C) 2003-2009 Masao Mutoh
5
6   You may redistribute it and/or modify it under the same
7   license terms as Ruby or LGPL.
8 =end
9
10 require 'optparse'
11 require 'fileutils'
12 require 'gettext'
13 require 'gettext/tools/poparser'
14 require 'rbconfig'
15
16 module GetText
17
18   module RMsgfmt  #:nodoc:
19     extend GetText
20     extend self
21
22     bindtextdomain "rgettext"
23
24     def run(targetfile = nil, output_path = nil) # :nodoc:
25       unless targetfile
26         targetfile, output_path = check_options
27       end
28       unless targetfile
29         raise ArgumentError, _("no input files")
30       end
31       unless output_path
32         output_path = "messages.mo"
33       end
34
35       parser = PoParser.new
36       data = MOFile.new
37
38       parser.parse_file(targetfile, data)
39       data.save_to_file(output_path)
40     end
41
42     def check_options # :nodoc:
43       output = nil
44
45       opts = OptionParser.new
46       opts.banner = _("Usage: %s input.po [-o output.mo]" % $0)
47       opts.separator("")
48       opts.separator(_("Generate binary message catalog from textual translation description."))
49       opts.separator("")
50       opts.separator(_("Specific options:"))
51
52       opts.on("-o", "--output=FILE", _("write output to specified file")) do |out|
53         output = out
54       end
55
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}]"
59         exit
60       end
61       opts.parse!(ARGV)
62
63       if ARGV.size == 0
64         puts opts.help
65         exit 1
66       end
67
68       [ARGV[0], output]
69     end
70   end
71   
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)
79   end
80 end
81
82 if $0 == __FILE__ then
83   GetText.rmsgfmt
84 end