class GetText::Tools::MsgMerge::Config

@private

Attributes

backup[RW]

update mode options

definition_po[RW]
enable_fuzzy_matching[W]
order[RW]
output[RW]
output_obsolete_entries[W]
po_format_options[RW]
reference_pot[RW]
suffix[RW]

update mode options

update[RW]

Public Class Methods

new() click to toggle source

The result is written back to def.po.

--backup=CONTROL        make a backup of def.po
--suffix=SUFFIX         override the usual backup suffix

The version control method may be selected via the –backup option or through the VERSION_CONTROL environment variable. Here are the values:

none, off       never make backups (even if --backup is given)
numbered, t     make numbered backups
existing, nil   numbered if numbered backups exist, simple otherwise
simple, never   always make simple backups

The backup suffix is ‘~’, unless set with –suffix or the SIMPLE_BACKUP_SUFFIX environment variable.

# File lib/gettext/tools/msgmerge.rb, line 304
def initialize
  @definition_po = nil
  @reference_po = nil
  @update = false
  @output = nil
  @order = :reference
  @po_format_options = {
    max_line_width: POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
    use_one_line_per_reference: false,
  }
  @enable_fuzzy_matching = true
  @update = nil
  @report_warning = true
  @output_obsolete_entries = true
  @backup = ENV["VERSION_CONTROL"]
  @suffix = ENV["SIMPLE_BACKUP_SUFFIX"] || "~"
  @input_dirs = ["."]
end

Public Instance Methods

enable_fuzzy_matching?() click to toggle source

@return [Bool] true if fuzzy matching is enabled, false otherwise.

# File lib/gettext/tools/msgmerge.rb, line 337
def enable_fuzzy_matching?
  @enable_fuzzy_matching
end
output_obsolete_entries?() click to toggle source

@return [Bool] true if outputting obsolete entries is

enabled, false otherwise.
# File lib/gettext/tools/msgmerge.rb, line 349
def output_obsolete_entries?
  @output_obsolete_entries
end
parse(command_line) click to toggle source
# File lib/gettext/tools/msgmerge.rb, line 323
def parse(command_line)
  parser = create_option_parser
  rest = parser.parse(command_line)

  if rest.size != 2
    puts(parser.help)
    exit(false)
  end

  @definition_po, @reference_pot = rest
  @output = @definition_po if @update
end
report_warning?() click to toggle source

@return [Bool] true if reporting warning is enabled,

false otherwise.
# File lib/gettext/tools/msgmerge.rb, line 343
def report_warning?
  @report_warning
end

Private Instance Methods

create_option_parser() click to toggle source
# File lib/gettext/tools/msgmerge.rb, line 354
def create_option_parser
  parser = OptionParser.new
  parser.banner =
    _("Usage: %s [OPTIONS] definition.po reference.pot") % $0
  #parser.summary_width = 80
  parser.separator("")
  description = _("Merges two Uniforum style .po files together. " +
                    "The definition.po file is an existing PO file " +
                    "with translations. The reference.pot file is " +
                    "the last created PO file with up-to-date source " +
                    "references. The reference.pot is generally " +
                    "created by rxgettext.")
  parser.separator(description)
  parser.separator("")
  parser.separator(_("Specific options:"))

  parser.on("-U", "--[no-]update",
            _("Update definition.po")) do |update|
    @update = update
  end

  parser.on("-o", "--output=FILE",
            _("Write output to specified file")) do |output|
    @output = output
  end

  parser.on("--[no-]sort-output",
            _("Sort output by msgid"),
            _("It is same as --sort-by-msgid"),
            _("Just for GNU gettext's msgcat compatibility")) do |sort|
    @order = sort ? :msgid : nil
  end

  parser.on("--sort-by-file",
            _("Sort output by location"),
            _("It is same as --sort-by-location"),
            _("Just for GNU gettext's msgcat compatibility")) do
    @order = :reference
  end

  parser.on("--sort-by-location",
            _("Sort output by location")) do
    @order = :reference
  end

  parser.on("--sort-by-msgid",
            _("Sort output by msgid")) do
    @order = :msgid
  end

  parser.on("--[no-]location",
            _("Preserve '#: FILENAME:LINE' lines")) do |location|
    @po_format_options[:include_reference_comment] = location
  end

  parser.on("--width=WIDTH", Integer,
            _("Set output page width"),
            "(#{@po_format_options[:max_line_width]})") do |width|
    @po_format_options[:max_line_width] = width
  end

  parser.on("--[no-]wrap",
            _("Break long message lines, longer than the output page width, into several lines"),
            "(#{@po_format_options[:max_line_width] >= 0})") do |wrap|
    if wrap
      max_line_width = POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH
    else
      max_line_width = -1
    end
    @po_format_options[:max_line_width] = max_line_width
  end

  parser.on("--[no-]use-one-line-per-reference",
            _("Use one line for each reference comment"),
            "(#{@po_format_options[:use_one_line_per_reference]})") do |use|
    @po_format_options[:use_one_line_per_reference] = use
  end

  parser.on("--[no-]fuzzy-matching",
            _("Disable fuzzy matching"),
            _("(enable)")) do |boolean|
    @enable_fuzzy_matching = boolean
  end

  parser.on("--no-report-warning",
            _("Don't report warning messages")) do |report_warning|
    @report_warning = report_warning
  end

  parser.on("--no-obsolete-entries",
            _("Don't output obsolete entries")) do |boolean|
    @output_obsolete_entries = boolean
  end

  parser.on("-h", "--help", _("Display this help and exit")) do
    puts(parser.help)
    exit(true)
  end

  parser.on_tail("--version",
                 _("Display version information and exit")) do
    puts(GetText::VERSION)
    exit(true)
  end

  parser
end