class GetText::POEntry
Contains data related to the expression or sentence that is to be translated.
Constants
- PARAMS
Attributes
@return [Array<String>] The flags for this PO entry. @since 3.0.4
Options
Required
Public Class Methods
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
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
# 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
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
@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
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
@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
@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
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
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
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
@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
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
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
@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
# 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
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