Parent

Included Modules

GetText::PoMessage

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

Constants

PARAMS

Attributes

type[RW]

Required

msgid[RW]
msgid_plural[RW]

Options

msgctxt[RW]
sources[RW]
comment[RW]

Public Class Methods

max_line_length() click to toggle source

Gets the max line length.

    # File lib/gettext/tools/pomessage.rb, line 23
23:     def self.max_line_length
24:       @@max_line_length
25:     end
max_line_length=(len) click to toggle source

Sets the max line length.

    # File lib/gettext/tools/pomessage.rb, line 18
18:     def self.max_line_length=(len)
19:       @@max_line_length = len
20:     end
new(type) click to toggle source

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

    # File lib/gettext/tools/pomessage.rb, line 37
37:     def initialize(type)
38:       @type = type
39:       @sources = []
40:       @param_type = PARAMS[@type]
41:     end
new(type) click to toggle source
     # File lib/gettext/tools/parser/ruby.rb, line 104
104:     def initialize(type)
105:       initialize_old(type)
106:       init_param
107:     end
Also aliased as: initialize_old
new_from_ary(ary) click to toggle source

For backward comatibility. This doesn’t support “comment”. ary = [msgid1, “file1:line1”, “file2:line”]

     # File lib/gettext/tools/pomessage.rb, line 160
160:     def self.new_from_ary(ary)
161:       ary = ary.dup
162:       msgid = ary.shift
163:       sources = ary
164:       type = :normal
165:       msgctxt = nil
166:       msgid_plural = nil
167:       
168:       if msgid.include? "\0004"
169:         msgctxt, msgid = msgid.split(/\0004/)
170:         type = :msgctxt
171:       end
172:       if msgid.include? "\0000"
173:         ids = msgid.split(/\0000/)
174:         msgid = ids[0]
175:         msgid_plural = ids[1]
176:         if type == :msgctxt
177:           type = :msgctxt_plural
178:         else
179:           type = :plural
180:         end
181:       end
182:       ret = self.new(type)
183:       ret.msgid = msgid
184:       ret.sources = sources
185:       ret.msgctxt = msgctxt
186:       ret.msgid_plural = msgid_plural
187:       ret
188:     end

Public Instance Methods

==(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/tools/pomessage.rb, line 62
62:     def ==(other)
63:       other.msgid == self.msgid && other.msgctxt == self.msgctxt
64:     end
[](number) click to toggle source
     # File lib/gettext/tools/pomessage.rb, line 190
190:     def [](number)
191:       param = @param_type[number]
192:       raise ParseError, 'no more string parameters expected' unless param
193:       send param
194:     end
add_comment(new_comment) click to toggle source

Support for extracted comments. Explanation s. www.gnu.org/software/gettext/manual/gettext.html#Names

    # File lib/gettext/tools/pomessage.rb, line 45
45:     def add_comment(new_comment)
46:       if (new_comment and ! new_comment.empty?)
47:         @comment ||= ""
48:         @comment += new_comment
49:       end
50:       to_s
51:     end
escaped(param_name) click to toggle source

Returns a parameter representation suitable for po-files and other purposes.

    # File lib/gettext/tools/pomessage.rb, line 55
55:     def escaped(param_name)
56:       orig = self.send param_name
57:       orig.gsub(/"/, '\"').gsub(/\r/, '')
58:     end
initialize_old(type) click to toggle source
Alias for: new
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/tools/pomessage.rb, line 69
69:     def merge(other)
70:       return self unless other
71:       raise ParseError, "Translation targets do not match: \n"        "  self: #{self.inspect}\n  other: '#{other.inspect}'" unless self == other
72:       if other.msgid_plural && !self.msgid_plural
73:         res = other
74:         unless (res.sources.include? self.sources[0])
75:           res.sources += self.sources
76:           res.add_comment(self.comment)
77:         end
78:       else
79:         res = self
80:         unless (res.sources.include? other.sources[0])
81:           res.sources += other.sources
82:           res.add_comment(other.comment)
83:         end
84:       end
85:       res
86:     end
msgctxt?() click to toggle source

Returns true if the type is kind of msgctxt. And if this is a kind of msgctxt and msgctxt property is nil, then raise an RuntimeException.

     # File lib/gettext/tools/pomessage.rb, line 130
130:     def msgctxt?
131:       if [:msgctxt, :msgctxt_plural].include? @type
132:         raise "This PoMessage is a kind of msgctxt but the msgctxt property is nil. msgid: #{msgid}" unless @msgctxt
133:         true
134:       end
135:     end
plural?() click to toggle source

Returns true if the type is kind of plural. And if this is a kind of plural and msgid_plural property is nil, then raise an RuntimeException.

     # File lib/gettext/tools/pomessage.rb, line 140
140:     def plural?
141:       if [:plural, :msgctxt_plural].include? @type
142:         raise "This PoMessage is a kind of plural but the msgid_plural property is nil. msgid: #{msgid}" unless @msgid_plural
143:         true
144:       end
145:     end
to_po_str() click to toggle source

Output the po message for the po-file.

     # File lib/gettext/tools/pomessage.rb, line 90
 90:     def to_po_str
 91:       raise "msgid is nil." unless @msgid
 92:       raise "sources is nil." unless @sources
 93: 
 94:       str = ""
 95:       # extracted comments
 96:       if comment
 97:         comment.split("\n").each do |comment_line|
 98:           str << "\n#. #{comment_line.strip}"
 99:         end
100:       end
101: 
102:       # references
103:       curr_pos = @@max_line_length
104:       sources.each do |e|
105:         if curr_pos + e.size > @@max_line_length
106:           str << "\n#:"
107:           curr_pos = 3
108:         else
109:           curr_pos += (e.size + 1)
110:         end
111:         str << " " << e
112:       end
113: 
114:       # msgctxt, msgid, msgstr
115:       str << "\nmsgctxt \"" << msgctxt << "\"" if msgctxt?
116:       str << "\nmsgid \"" << escaped(:msgid) << "\"\n"
117:       if plural?
118:         str << "msgid_plural \"" << escaped(:msgid_plural) << "\"\n"
119:         str << "msgstr[0] \"\"\n"
120:         str << "msgstr[1] \"\"\n"
121:       else
122:         str << "msgstr \"\"\n"
123:       end
124:       str
125:     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/tools/pomessage.rb, line 153
153:     def set_value(param, value)
154:       send "#{param}=", (send(param) || '') + value.gsub(/\n/, '\n')
155:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.