Class: GetText::Tools::XGetText

### Home Classes Methods

### In Files

- lib/gettext/tools/xgettext.rb

### Parent

Object

### Methods

- ::add_parser
- ::run
- #add_parser

### Included Modules

- GetText

### Class/Module Index

Quicksearch

- GetText
- GetText::ClassInfo
- GetText::ErbParser
- GetText::GladeParser
- GetText::LocalePath
- GetText::MO
- GetText::MO::HeaderRev1
- GetText::MO::InvalidFormat
- GetText::NoboundTextDomainError
- GetText::PO
- GetText::PO::NonExistentEntryError
- GetText::POEntry
- GetText::POEntry::InvalidTypeError
- GetText::POEntry::NoMsgctxtError
- GetText::POEntry::NoMsgidError
- GetText::POEntry::NoMsgidPluralError
- GetText::POEntryForRubyParser
- GetText::POParser
- GetText::ParseError
- GetText::RubyParser
- GetText::TextDomain
- GetText::TextDomainGroup
- GetText::TextDomainManager
- GetText::Tools
- GetText::Tools::MsgInit
- GetText::Tools::MsgInit::ArgumentError
- GetText::Tools::MsgInit::Error
- GetText::Tools::MsgInit::ValidationError
- GetText::Tools::MsgMerge
- GetText::Tools::Task
- GetText::Tools::XGetText

No matching classes.

# GetText::Tools::XGetText

### Attributes

parse_options[R]

@return [Hash<Symbol, Object>] Options for parsing. Options

    are depend on each parser.

@see RubyParser#parse @see ErbParser#parse

### Public Class Methods

add_parser(parser) click to toggle source

Adds a parser to the default parser list.

@param (see add_parser) @return [void]

@see add_parser

    # File lib/gettext/tools/xgettext.rb, line 41
    def add_parser(parser)
      @@default_parsers.unshift(parser)
    end

run(*arguments) click to toggle source

    # File lib/gettext/tools/xgettext.rb, line 31
    def run(*arguments)
      new.run(*arguments)
    end

### Public Instance Methods

add_parser(parser) click to toggle source

The parser object requires to have target?(path) and parse(path) method.

@example How to add your parser

    require "gettext/tools/xgettext"
    class FooParser
      def target?(path)
        File.extname(path) == ".foo"  # *.foo file only.
      end
      def parse(path, options={})
        po = []
        # Simple entry
        entry = POEntry.new(:normal)
        entry.msgid = "hello"
        entry.references = ["foo.rb:200", "bar.rb:300"]
        entry.add_comment("Comment for the entry")
        po << entry
        # Plural entry
        entry = POEntry.new(:plural)
        entry.msgid = "An apple"
        entry.msgid_plural = "Apples"
        entry.references = ["foo.rb:200", "bar.rb:300"]
        po << entry
        # Simple entry with the entry context
        entry = POEntry.new(:msgctxt)
        entry.msgctxt = "context"
        entry.msgid = "hello"
        entry.references = ["foo.rb:200", "bar.rb:300"]
        po << entry
        # Plural entry with the message context.
        entry = POEntry.new(:msgctxt_plural)
        entry.msgctxt = "context"
        entry.msgid = "An apple"
        entry.msgid_plural = "Apples"
        entry.references = ["foo.rb:200", "bar.rb:300"]
        po << entry
        return po
      end
    end

    GetText::Tools::XGetText.add_parser(FooParser.new)

@param [target?, parse] parser

    It parses target file and extracts translate target entries from the
    target file. If there are multiple target files, parser.parse is
    called multiple times.

@return [void]

    # File lib/gettext/tools/xgettext.rb, line 136
    def add_parser(parser)
      @parsers.unshift(parser)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.