Class: GetText::Tools::MsgFmt

Inherits:
Object
  • Object
show all
Includes:
GetText
Defined in:
lib/gettext/tools/msgfmt.rb

Overview

:nodoc:

Constant Summary

Constants included from GetText

VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GetText

#N_, #Nn_, #bindtextdomain, #bindtextdomain_to, #cgi, #cgi=, #gettext, included, #locale, #ngettext, #npgettext, #nsgettext, #output_charset, #pgettext, #set_cgi, #set_current_locale, #set_locale, #set_output_charset, #sgettext, #textdomain, #textdomain_to

Constructor Details

#initializeMsgFmt

Returns a new instance of MsgFmt.



46
47
48
49
# File 'lib/gettext/tools/msgfmt.rb', line 46

def initialize
  @input_file = nil
  @output_file = nil
end

Class Method Details

.run(*arguments) ⇒ Object



37
38
39
# File 'lib/gettext/tools/msgfmt.rb', line 37

def run(*arguments)
  new.run(*arguments)
end

Instance Method Details

#initialize_arguments(*options) ⇒ Object

:nodoc:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gettext/tools/msgfmt.rb', line 61

def initialize_arguments(*options) # :nodoc:
  input_file, output_file = parse_commandline_options(*options)

  if input_file.nil?
    raise(ArgumentError, _("no input files specified."))
  end

  if output_file.nil?
    output_file = "messages.mo"
  end

  @input_file = input_file
  @output_file = output_file
end

#parse_commandline_options(*options) ⇒ Object



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
# File 'lib/gettext/tools/msgfmt.rb', line 76

def parse_commandline_options(*options)
  output_file = nil

  parser = OptionParser.new
  parser.banner = _("Usage: %s input.po [-o output.mo]" % $0)
  parser.separator("")
  description = _("Generate binary message catalog from textual " +
                    "translation description.")
  parser.separator(description)
  parser.separator("")
  parser.separator(_("Specific options:"))

  parser.on("-o", "--output=FILE",
          _("write output to specified file")) do |out|
    output_file = out
  end

  parser.on_tail("--version", _("display version information and exit")) do
    puts(VERSION)
    exit(true)
  end
  parser.parse!(options)

  input_file = options[0]
  [input_file, output_file]
end

#run(*options) ⇒ Object

:nodoc:



51
52
53
54
55
56
57
58
59
# File 'lib/gettext/tools/msgfmt.rb', line 51

def run(*options) # :nodoc:
  initialize_arguments(*options)

  parser = POParser.new
  data = MO.new

  parser.parse_file(@input_file, data)
  data.save_to_file(@output_file)
end