Class: GetText::POEntry
- Inherits:
-
Object
- Object
- GetText::POEntry
- Defined in:
- lib/gettext/po_entry.rb
Overview
Contains data related to the expression or sentence that is to be translated.
Defined Under Namespace
Classes: Formatter, InvalidTypeError, NoMsgctxtError, NoMsgidError, NoMsgidPluralError
Constant Summary collapse
- PARAMS =
{ :normal => [:msgid, :separator, :msgstr], :plural => [:msgid, :msgid_plural, :separator, :msgstr], :msgctxt => [:msgctxt, :msgid, :msgstr], :msgctxt_plural => [:msgctxt, :msgid, :msgid_plural, :msgstr] }
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#extracted_comment ⇒ Object
Returns the value of attribute extracted_comment.
-
#flags ⇒ Array<String>
The flags for this PO entry.
-
#msgctxt ⇒ Object
Returns the value of attribute msgctxt.
-
#msgid ⇒ Object
Returns the value of attribute msgid.
-
#msgid_plural ⇒ Object
Options.
-
#msgstr ⇒ Object
Returns the value of attribute msgstr.
-
#previous ⇒ Object
Returns the value of attribute previous.
-
#references ⇒ Object
["file1:line1", "file2:line2", ...].
-
#separator ⇒ Object
Returns the value of attribute separator.
-
#translator_comment ⇒ Object
Returns the value of attribute translator_comment.
-
#type ⇒ Object
Required.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Checks if the self has same attributes as other.
- #[](number_or_param) ⇒ Object
- #[]=(number_or_param, value) ⇒ Object
-
#add_comment(new_comment) ⇒ void
Support for extracted comments.
-
#flag ⇒ String?
deprecated
Deprecated.
Since 3.0.4. Use #flags instead.
-
#flag=(flag) ⇒ Object
deprecated
Deprecated.
Since 3.0.4. Use #flags= instead.
-
#fuzzy? ⇒ Boolean
True if the entry is fuzzy entry, false otherwise.
-
#header? ⇒ Boolean
True if the entry is header entry, false otherwise.
-
#initialize(type) ⇒ POEntry
constructor
Create the object.
-
#merge(other) ⇒ Object
Merges two translation targets with the same msgid and returns the merged result.
-
#mergeable?(other) ⇒ Boolean
Checks if the other translation target is mergeable with the current one.
-
#msgctxt? ⇒ Boolean
Returns true if the type is kind of msgctxt.
-
#obsolete? ⇒ Boolean
True if the entry is obsolete entry, false otherwise.
-
#plural? ⇒ Boolean
Returns true if the type is kind of plural.
-
#to_s(options = {}) ⇒ Object
Format the po entry in PO format.
-
#translated? ⇒ Boolean
True if the entry is translated entry, false otherwise.
Constructor Details
#initialize(type) ⇒ POEntry
Create the object. +type+ should be :normal, :plural, :msgctxt or :msgctxt_plural.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gettext/po_entry.rb', line 66 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 |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
63 64 65 |
# File 'lib/gettext/po_entry.rb', line 63 def comment @comment end |
#extracted_comment ⇒ Object
Returns the value of attribute extracted_comment.
58 59 60 |
# File 'lib/gettext/po_entry.rb', line 58 def extracted_comment @extracted_comment end |
#flags ⇒ Array<String>
Returns The flags for this PO entry.
61 62 63 |
# File 'lib/gettext/po_entry.rb', line 61 def flags @flags end |
#msgctxt ⇒ Object
Returns the value of attribute msgctxt.
55 56 57 |
# File 'lib/gettext/po_entry.rb', line 55 def msgctxt @msgctxt end |
#msgid ⇒ Object
Returns the value of attribute msgid.
50 51 52 |
# File 'lib/gettext/po_entry.rb', line 50 def msgid @msgid end |
#msgid_plural ⇒ Object
Options
53 54 55 |
# File 'lib/gettext/po_entry.rb', line 53 def msgid_plural @msgid_plural end |
#msgstr ⇒ Object
Returns the value of attribute msgstr.
51 52 53 |
# File 'lib/gettext/po_entry.rb', line 51 def msgstr @msgstr end |
#previous ⇒ Object
Returns the value of attribute previous.
62 63 64 |
# File 'lib/gettext/po_entry.rb', line 62 def previous @previous end |
#references ⇒ Object
["file1:line1", "file2:line2", ...]
56 57 58 |
# File 'lib/gettext/po_entry.rb', line 56 def references @references end |
#separator ⇒ Object
Returns the value of attribute separator.
54 55 56 |
# File 'lib/gettext/po_entry.rb', line 54 def separator @separator end |
#translator_comment ⇒ Object
Returns the value of attribute translator_comment.
57 58 59 |
# File 'lib/gettext/po_entry.rb', line 57 def translator_comment @translator_comment end |
#type ⇒ Object
Required
49 50 51 |
# File 'lib/gettext/po_entry.rb', line 49 def type @type end |
Instance Method Details
#==(other) ⇒ Object
Checks if the self has same attributes as other.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/gettext/po_entry.rb', line 109 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_or_param) ⇒ Object
211 212 213 |
# File 'lib/gettext/po_entry.rb', line 211 def [](number_or_param) __send__(resolve_param(number_or_param)) end |
#[]=(number_or_param, value) ⇒ Object
215 216 217 |
# File 'lib/gettext/po_entry.rb', line 215 def []=(number_or_param, value) __send__("#{resolve_param(number_or_param)}=", value) end |
#add_comment(new_comment) ⇒ void
This method returns an undefined value.
Support for extracted comments. Explanation s. http://www.gnu.org/software/gettext/manual/gettext.html#Names
82 83 84 85 86 87 88 |
# File 'lib/gettext/po_entry.rb', line 82 def add_comment(new_comment) if (new_comment and ! new_comment.empty?) @extracted_comment ||= String.new @extracted_comment << "\n" unless @extracted_comment.empty? @extracted_comment << new_comment end end |
#flag ⇒ String?
Since 3.0.4. Use #flags instead.
Returns The flag of the PO entry.
92 93 94 |
# File 'lib/gettext/po_entry.rb', line 92 def flag @flags.first end |
#flag=(flag) ⇒ Object
Since 3.0.4. Use #flags= instead.
Set the new flag for the PO entry.
100 101 102 103 104 105 106 |
# File 'lib/gettext/po_entry.rb', line 100 def flag=(flag) if flag.nil? @flags = [] else @flags = [flag] end end |
#fuzzy? ⇒ Boolean
Returns true if the entry is fuzzy entry, false otherwise. Fuzzy entry has "fuzzy" flag.
200 201 202 |
# File 'lib/gettext/po_entry.rb', line 200 def fuzzy? @flags.include?("fuzzy") end |
#header? ⇒ Boolean
Returns true if the entry is header entry, false otherwise. Header entry is normal type and has empty msgid.
188 189 190 |
# File 'lib/gettext/po_entry.rb', line 188 def header? @type == :normal and @msgid == "" end |
#merge(other) ⇒ Object
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.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/gettext/po_entry.rb', line 142 def merge(other) return self unless other unless mergeable?(other) = "Translation targets do not match: \n" + " self: #{self.inspect}\n other: '#{other.inspect}'" raise ParseError, 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) ⇒ Boolean
Checks if the other translation target is mergeable with the current one. Relevant are msgid and translation context (msgctxt).
135 136 137 |
# File 'lib/gettext/po_entry.rb', line 135 def mergeable?(other) other && other.msgid == self.msgid && other.msgctxt == self.msgctxt end |
#msgctxt? ⇒ Boolean
Returns true if the type is kind of msgctxt.
177 178 179 |
# File 'lib/gettext/po_entry.rb', line 177 def msgctxt? [:msgctxt, :msgctxt_plural].include?(@type) end |
#obsolete? ⇒ Boolean
Returns true if the entry is obsolete entry, false otherwise. Obsolete entry is normal type and has :last msgid.
194 195 196 |
# File 'lib/gettext/po_entry.rb', line 194 def obsolete? @type == :normal and @msgid == :last end |
#plural? ⇒ Boolean
Returns true if the type is kind of plural.
182 183 184 |
# File 'lib/gettext/po_entry.rb', line 182 def plural? [:plural, :msgctxt_plural].include?(@type) end |
#to_s(options = {}) ⇒ Object
Format the po entry in PO format.
169 170 171 172 173 174 |
# File 'lib/gettext/po_entry.rb', line 169 def to_s(={}) raise(NoMsgidError, "msgid is nil.") unless @msgid formatter = Formatter.new(self, ) formatter.format end |
#translated? ⇒ Boolean
Returns true if the entry is translated entry, false otherwise.
205 206 207 208 209 |
# File 'lib/gettext/po_entry.rb', line 205 def translated? return false if fuzzy? return false if @msgstr.nil? or @msgstr.empty? true end |