Class: GetText::Tools::MsgMerge

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

Defined Under Namespace

Classes: Config, Merger, PoData

Constant Summary collapse

VERSION =

constant values

GetText::VERSION

Constants included from GetText

BOM_UTF8, MOFile, MoFile, PoParser

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.



441
442
443
# File 'lib/gettext/tools/msgmerge.rb', line 441

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

Instance Method Details

#check_command_line_options(*options) ⇒ Object

:nodoc:



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/gettext/tools/msgmerge.rb', line 453

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:



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
499
500
501
502
503
504
505
506
507
# File 'lib/gettext/tools/msgmerge.rb', line 470

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:



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/gettext/tools/msgmerge.rb', line 509

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

  parser = POParser.new
  parser.ignore_fuzzy = false
  defpo = parser.parse_file(config.defpo, PO.new)
  refpot = parser.parse_file(config.refpot, PO.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.to_s)
    end
  else
    puts(result.to_s)
  end
end