Module: GetText::RMsgMerge

Extended by:
GetText
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

Class 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, p_, pgettext, remove_bom, rgettext, rmsgfmt, rmsgmerge, set_cgi, set_locale, set_output_charset, sgettext, textdomain, update_pofiles, update_pofiles_org

Class Method Details

.check_options(config) ⇒ Object



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

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



438
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
474
475
476
# File 'lib/gettext/tools/rmsgmerge.rb', line 438

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
  defstr = nil
  refstr = nil      
  File.open(config.defpo){|f| defstr = f.read}
  File.open(config.refpot){|f| refstr = f.read}
  defpo = parser.parse(defstr, PoData.new, false)
  refpot = parser.parse(refstr, 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