Class: GetText::Tools::MsgMerge

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

Defined Under Namespace

Classes: Config, Merger, PoData

Constant Summary collapse

VERSION =

constant values

GetText::VERSION

Constants included from GetText

BOM_UTF8, MOFile

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GetText

#N_, #Nn_, #bindtextdomain, #bindtextdomain_to, #cgi, #cgi=, #create_mofiles, #create_mofiles_org, #gettext, included, #locale, #msgmerge, #ngettext, #npgettext, #nsgettext, #output_charset, #pgettext, #remove_bom, #set_cgi, #set_current_locale, #set_locale, #set_output_charset, #sgettext, #textdomain, #textdomain_to, #update_pofiles, #update_pofiles_org

Class Method Details

.run(*arguments) ⇒ void

This method returns an undefined value.

Merge a po-file inluding translated messages and a new pot-file.

Parameters:

  • arguments (Array<String>)

    arguments for rmsgfmt.



432
433
434
# File 'lib/gettext/tools/msgmerge.rb', line 432

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

Instance Method Details

#check_command_line_options(*options) ⇒ Object

:nodoc:



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/gettext/tools/msgmerge.rb', line 444

def check_command_line_options(*options) #:nodoc:
  options, output = parse_arguments(*options)

  config = Config.new
  config.output = output
  config.defpo = options[0]
  config.refpot = options[1]

  if config.defpo.nil?
    raise ArgumentError, _("definition po is not given.")
  elsif config.refpot.nil?
    raise ArgumentError, _("reference pot is not given.")
  end

  config
end

#parse_arguments(*options) ⇒ Object

:nodoc:



461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/gettext/tools/msgmerge.rb', line 461

def parse_arguments(*options) #:nodoc:
  parser = OptionParser.new
  parser.banner = _("Usage: %s def.po ref.pot [-o output.pot]") % $0
  #parser.summary_width = 80
  parser.separator("")
  description = _("Merges two Uniforum style .po files together. " +
                    "The def.po file is an existing PO file with " +
                    "translations. The ref.pot file is the last " +
                    "created PO file with up-to-date source " +
                    "references. ref.pot is generally created by " +
                    "rgettext.")
  parser.separator(description)
  parser.separator("")
  parser.separator(_("Specific options:"))

  output = nil

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

  #parser.on("-F", "--fuzzy-matching")

  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(VERSION)
    exit(true)
  end

  parser.parse!(options)

  [options, output]
end

#run(*options) ⇒ Object

:nodoc:



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/gettext/tools/msgmerge.rb', line 500

def run(*options) #:nodoc:
  config = check_command_line_options(*options)

  parser = PoParser.new
  parser.ignore_fuzzy = false
  defpo = parser.parse_file(config.defpo, PoData.new)
  refpot = parser.parse_file(config.refpot, PoData.new)

  merger = Merger.new
  result = merger.merge(defpo, refpot)
  p result if $DEBUG
  print result.generate_po if $DEBUG

  if config.output.is_a?(String)
    File.open(File.expand_path(config.output), "w+") do |file|
      file.write(result.generate_po)
    end
  else
    puts(result.generate_po)
  end
end