Module: GetText::RMsgMerge

Extended by:
GetText, RMsgMerge
Included in:
RMsgMerge
Defined in:
lib/gettext/tools/rmsgmerge.rb,
lib/gettext/tools/rmsgmerge.rb,
lib/gettext/tools/rmsgmerge.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Config, Merger, PoData

Constant Summary collapse

VERSION =

constant values

GetText::VERSION
DATE =

Constants included from GetText

BOM_UTF8, MOFile

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, rgettext, rmsgfmt, rmsgmerge, set_cgi, set_current_locale, set_locale, set_output_charset, sgettext, textdomain, textdomain_to, update_pofiles, update_pofiles_org

Instance Method Details

#check_options(config) ⇒ Object



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/gettext/tools/rmsgmerge.rb', line 402

def check_options(config)
  opts = OptionParser.new
  opts.banner = _("Usage: %s def.po ref.pot [-o output.pot]") % $0
  #opts.summary_width = 80
  opts.separator("")
  opts.separator(_("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."))
  opts.separator("")
  opts.separator(_("Specific options:"))

  opts.on("-o", "--output=FILE", _("write output to specified file")) do |out|
    unless FileTest.exist? out
      config.output = out
    else
      #$stderr.puts(_("File '%s' has already existed.") % out)
      #exit 1
    end
  end

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

  opts.on_tail("--version", _("display version information and exit")) do
    puts "#{$0} #{VERSION} (#{DATE})"
  puts "#{File.join(::Config::CONFIG["bindir"], ::Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
    exit
  end

  opts.parse!(ARGV)

  if ARGV.size != 2
    puts opts.help
    exit 1
  end

  config.defpo = ARGV[0]
  config.refpot = ARGV[1]
end

#run(reference = nil, definition = nil, out = STDOUT) ⇒ Object



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/gettext/tools/rmsgmerge.rb', line 439

def run(reference = nil, definition = nil, out = STDOUT)
  config = GetText::RMsgMerge::Config.new
  config.refpot = reference
  config.defpo = definition
  config.output = out

  check_options(config)

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

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

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

  begin
    if out.is_a? String
      File.open(File.expand_path(out), "w+") do |file|
        file.write(result.generate_po)
      end
    else
      out.puts(result.generate_po)
    end
  ensure
    out.close
  end
end