Class: GetText::POEntry::Formatter
- Inherits:
-
Object
- Object
- GetText::POEntry::Formatter
- Includes:
- GetText::POFormat
- Defined in:
- lib/gettext/po_entry.rb
Constant Summary collapse
- DEFAULT_MAX_LINE_WIDTH =
78
Constants included from GetText::POFormat
GetText::POFormat::EXTRACTED_COMMENT_MARK, GetText::POFormat::FLAG_MARK, GetText::POFormat::PREVIOUS_COMMENT_MARK, GetText::POFormat::REFERENCE_COMMENT_MARK, GetText::POFormat::TRANSLATOR_COMMENT_MARK
Class Method Summary collapse
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(entry, options = {}) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(entry, options = {}) ⇒ Formatter
Returns a new instance of Formatter.
269 270 271 272 |
# File 'lib/gettext/po_entry.rb', line 269 def initialize(entry, ={}) @entry = entry = () end |
Class Method Details
.escape(string) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/gettext/po_entry.rb', line 224 def escape(string) return "" if string.nil? string.gsub(/([\\"\t\n])/) do special_character = $1 case special_character when "\t" "\\t" when "\n" "\\n" else "\\#{special_character}" end end end |
Instance Method Details
#format ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/gettext/po_entry.rb', line 274 def format if @entry.obsolete? return format_obsolete_comment(@entry.comment) end str = format_comments # msgctxt, msgid, msgstr if @entry.msgctxt? if @entry.msgctxt.nil? = "This POEntry is a kind of msgctxt " + "but the msgctxt property is nil. " + "msgid: #{@entry.msgid}" raise(NoMsgctxtError, ) end str << "msgctxt " << (@entry.msgctxt) end str << "msgid " << (@entry.msgid) if @entry.plural? if @entry.msgid_plural.nil? = "This POEntry is a kind of plural " + "but the msgid_plural property is nil. " + "msgid: #{@entry.msgid}" raise(NoMsgidPluralError, ) end str << "msgid_plural " << (@entry.msgid_plural) if @entry.msgstr.nil? str << "msgstr[0] \"\"\n" str << "msgstr[1] \"\"\n" else msgstrs = @entry.msgstr.split("\000", -1) msgstrs.each_with_index do |msgstr, index| str << "msgstr[#{index}] " << (msgstr) end end else str << "msgstr " str << (@entry.msgstr) end encode(str) end |