Parent

Included Modules

GetText::POEntry::Formatter

Public Class Methods

escape(string) click to toggle source
# File lib/gettext/po_entry.rb, line 230
def escape(string)
  return "" if string.nil?

  string.gsub(/([\\"\t\n])/) do
    special_character = $1
    case special_character
    when "\t"
      "\\t"
    when "\n"
      "\\n"
    else
      "\\#{special_character}"
    end
  end
end
new(entry, options={}) click to toggle source

@param [POEntry] entry The entry to be formatted. @param [Hash] options @option options [Bool] :include_translator_comment (true)

Includes translator comments in formatted string if true.

@option options [Bool] :include_extracted_comment (true)

Includes extracted comments in formatted string if true.

@option options [Bool] :include_reference_comment (true)

Includes reference comments in formatted string if true.

@option options [Bool] :include_flag_comment (true)

Includes flag comments in formatted string if true.

@option options [Bool] :include_previous_comment (true)

Includes previous comments in formatted string if true.

@option options [Bool] :include_all_comments (true)

Includes all comments in formatted string if true.
Other specific `:include_XXX` options get preference over
this option.
You can remove all comments by specifying this option as
false and omitting other `:include_XXX` options.

@option options [Integer] :max_line_width (78)

Wraps long lines that is longer than the `:max_line_width`.
Don't break long lines if `:max_line_width` is less than 0
such as `-1`.

@option options [Encoding] :encoding (nil)

Encodes to the specific encoding.
# File lib/gettext/po_entry.rb, line 275
def initialize(entry, options={})
  @entry = entry
  @options = normalize_options(options)
end

Public Instance Methods

format() click to toggle source
# File lib/gettext/po_entry.rb, line 280
def format
  if @entry.obsolete?
    return format_obsolete_comment(@entry.comment)
  end

  str = format_comments

  # msgctxt, msgid, msgstr
  if @entry.msgctxt?
    if @entry.msgctxt.nil?
      no_msgctxt_message = "This POEntry is a kind of msgctxt " +
                             "but the msgctxt property is nil. " +
                             "msgid: #{@entry.msgid}"
      raise(NoMsgctxtError, no_msgctxt_message)
    end
    str << "msgctxt " << format_message(@entry.msgctxt)
  end

  str << "msgid " << format_message(@entry.msgid)
  if @entry.plural?
    if @entry.msgid_plural.nil?
      no_plural_message = "This POEntry is a kind of plural " +
                            "but the msgid_plural property is nil. " +
                            "msgid: #{@entry.msgid}"
      raise(NoMsgidPluralError, no_plural_message)
    end

    str << "msgid_plural " << format_message(@entry.msgid_plural)

    if @entry.msgstr.nil?
      str << "msgstr[0] \"\"\n"
      str << "msgstr[1] \"\"\n"
    else
      msgstrs = @entry.msgstr.split("\0000", -1)
      msgstrs.each_with_index do |msgstr, index|
        str << "msgstr[#{index}] " << format_message(msgstr)
      end
    end
  else
    str << "msgstr "
    str << format_message(@entry.msgstr)
  end

  encode(str)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.