Contains data related to the expression or sentence that is to be translated.
Options
Required
Create the object. type
should be :normal, :plural, :msgctxt
or :msgctxt_plural.
# File lib/gettext/po_entry.rb, line 65 def initialize(type) self.type = type @translator_comment = nil @extracted_comment = nil @references = [] @flag = nil @previous = nil @msgctxt = nil @msgid = nil @msgid_plural = nil @msgstr = nil end
Checks if the self has same attributes as other.
# File lib/gettext/po_entry.rb, line 90 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 flag == other.flag and previous == other.previous and comment == other.comment end
# File lib/gettext/po_entry.rb, line 167 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 81 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
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 123 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 116 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 158 def msgctxt? [:msgctxt, :msgctxt_plural].include?(@type) end
Returns true if the type is kind of plural.
# File lib/gettext/po_entry.rb, line 163 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 150 def to_s(options={}) raise(NoMsgidError, "msgid is nil.") unless @msgid formatter = Formatter.new(self, options) formatter.format end
# File lib/gettext/po_entry.rb, line 106 def type=(type) unless PARAMS.has_key?(type) raise(InvalidTypeError, "\"%s\" is invalid type." % type) end @type = type @param_type = PARAMS[@type] end
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 179 def set_value(param, value) send "#{param}=", (send(param) || '') + value end