class GetText::POEntry

Contains data related to the expression or sentence that is to be translated.

Constants

PARAMS

Attributes

comment[RW]
extracted_comment[RW]
flags[RW]

@return [Array<String>] The flags for this PO entry. @since 3.0.4

msgctxt[RW]
msgid[RW]
msgid_plural[RW]

Options

msgstr[RW]
previous[RW]
references[RW]
separator[RW]
translator_comment[RW]
type[R]

Required

Public Class Methods

new(type) click to toggle source

Create the object. type should be :normal, :plural, :msgctxt or :msgctxt_plural.

# File lib/gettext/po_entry.rb, line 67
def initialize(type)
  self.type = type
  @translator_comment = nil
  @extracted_comment = nil
  @references = []
  @flags = []
  @previous = nil
  @msgctxt = nil
  @msgid = nil
  @msgid_plural = nil
  @msgstr = nil
end

Public Instance Methods

==(other) click to toggle source

Checks if the self has same attributes as other.

# File lib/gettext/po_entry.rb, line 110
def ==(other)
  not other.nil? and
    type == other.type and
    msgid == other.msgid and
    msgstr == other.msgstr and
    msgid_plural == other.msgid_plural and
    separator == other.separator and
    msgctxt == other.msgctxt and
    translator_comment == other.translator_comment and
    extracted_comment == other.extracted_comment and
    references == other.references and
    flags == other.flags and
    previous == other.previous and
    comment == other.comment
end
[](number) click to toggle source
# File lib/gettext/po_entry.rb, line 212
def [](number)
  param = @param_type[number]
  raise ParseError, 'no more string parameters expected' unless param
  send param
end
add_comment(new_comment) click to toggle source

Support for extracted comments. Explanation s. www.gnu.org/software/gettext/manual/gettext.html#Names @return [void]

# File lib/gettext/po_entry.rb, line 83
def add_comment(new_comment)
  if (new_comment and ! new_comment.empty?)
    @extracted_comment ||= ""
    @extracted_comment << "\n" unless @extracted_comment.empty?
    @extracted_comment << new_comment
  end
end
flag() click to toggle source

@return [String, nil] The flag of the PO entry. @deprecated Since 3.0.4. Use {#flags} instead.

# File lib/gettext/po_entry.rb, line 93
def flag
  @flags.first
end
flag=(flag) click to toggle source

Set the new flag for the PO entry.

@param [String, nil] flag The new flag. @deprecated Since 3.0.4. Use {#flags=} instead.

# File lib/gettext/po_entry.rb, line 101
def flag=(flag)
  if flag.nil?
    @flags = []
  else
    @flags = [flag]
  end
end
fuzzy?() click to toggle source

@return true if the entry is fuzzy entry, false otherwise.

Fuzzy entry has "fuzzy" flag.
# File lib/gettext/po_entry.rb, line 201
def fuzzy?
  @flags.include?("fuzzy")
end
header?() click to toggle source

@return true if the entry is header entry, false otherwise.

Header entry is normal type and has empty msgid.
# File lib/gettext/po_entry.rb, line 189
def header?
  @type == :normal and @msgid == ""
end
merge(other) click to toggle source

Merges two translation targets with the same msgid and returns the merged result. If one is declared as plural and the other not, then the one with the plural wins.

# File lib/gettext/po_entry.rb, line 143
def merge(other)
  return self unless other
  unless mergeable?(other)
    message = "Translation targets do not match: \n" +
      "  self: #{self.inspect}\n  other: '#{other.inspect}'"
    raise ParseError, message
  end
  if other.msgid_plural && !msgid_plural
    res = other
    unless res.references.include?(references[0])
      res.references += references
      res.add_comment(extracted_comment)
    end
  else
    res = self
    unless res.references.include?(other.references[0])
      res.references += other.references
      res.add_comment(other.extracted_comment)
    end
  end
  res
end
mergeable?(other) click to toggle source

Checks if the other translation target is mergeable with the current one. Relevant are msgid and translation context (msgctxt).

# File lib/gettext/po_entry.rb, line 136
def mergeable?(other)
  other && other.msgid == self.msgid && other.msgctxt == self.msgctxt
end
msgctxt?() click to toggle source

Returns true if the type is kind of msgctxt.

# File lib/gettext/po_entry.rb, line 178
def msgctxt?
  [:msgctxt, :msgctxt_plural].include?(@type)
end
obsolete?() click to toggle source

@return true if the entry is obsolete entry, false otherwise.

Obsolete entry is normal type and has :last msgid.
# File lib/gettext/po_entry.rb, line 195
def obsolete?
  @type == :normal and @msgid == :last
end
plural?() click to toggle source

Returns true if the type is kind of plural.

# File lib/gettext/po_entry.rb, line 183
def plural?
  [:plural, :msgctxt_plural].include?(@type)
end
to_s(options={}) click to toggle source

Format the po entry in PO format.

@param [Hash] options @option options (see Formatter#initialize)

# File lib/gettext/po_entry.rb, line 170
def to_s(options={})
  raise(NoMsgidError, "msgid is nil.") unless @msgid

  formatter = Formatter.new(self, options)
  formatter.format
end
translated?() click to toggle source

@return true if the entry is translated entry, false otherwise.

# File lib/gettext/po_entry.rb, line 206
def translated?
  return false if fuzzy?
  return false if @msgstr.nil? or @msgstr.empty?
  true
end
type=(type) click to toggle source
# File lib/gettext/po_entry.rb, line 126
def type=(type)
  unless PARAMS.has_key?(type)
    raise(InvalidTypeError, "\"%s\" is invalid type." % type)
  end
  @type = type
  @param_type = PARAMS[@type]
end

Private Instance Methods

set_value(param, value) click to toggle source

sets or extends the value of a translation target params like msgid, msgctxt etc.

param is symbol with the name of param
value - new value
# File lib/gettext/po_entry.rb, line 224
def set_value(param, value)
  send "#{param}=", (send(param) || '') + value
end