Class: GetText::RMsgMerge::PoData
- Inherits:
-
Object
- Object
- GetText::RMsgMerge::PoData
- Defined in:
- lib/gettext/tools/rmsgmerge.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#msgids ⇒ Object
readonly
Returns the value of attribute msgids.
Instance Method Summary collapse
- #[](msgid) ⇒ Object
- #[]=(msgid, msgstr) ⇒ Object
- #__conv(str) ⇒ Object
- #comment(msgid) ⇒ Object
- #each_msgid ⇒ Object
- #generate_po ⇒ Object
- #generate_po_entry(msgid) ⇒ Object
- #generate_po_header ⇒ Object
-
#initialize ⇒ PoData
constructor
A new instance of PoData.
- #msgid?(msgid) ⇒ Boolean
- #msgstr(msgid) ⇒ Object
- #nplural ⇒ Object
-
#search_msgid_fuzzy(msgid, used_msgids) ⇒ Object
Is it necessary to implement this method?.
- #set_comment(msgid_or_sym, comment) ⇒ Object
Constructor Details
#initialize ⇒ PoData
Returns a new instance of PoData.
24 25 26 27 28 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 24 def initialize @msgid2msgstr = {} @msgid2comment = {} @msgids = [] end |
Instance Attribute Details
#msgids ⇒ Object (readonly)
Returns the value of attribute msgids.
22 23 24 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 22 def msgids @msgids end |
Instance Method Details
#[](msgid) ⇒ Object
42 43 44 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 42 def [](msgid) @msgid2msgstr[msgid] end |
#[]=(msgid, msgstr) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 46 def []=(msgid, msgstr) # Retain the order unless @msgid2msgstr[msgid] @msgids << msgid end @msgid2msgstr[msgid] = msgstr end |
#__conv(str) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 139 def __conv(str) s = '' if str.count("\n") > 1 s << '""' << "\n" s << str.gsub(/^(.*)$/, '"\1\n"') else s << '"' << str.sub("\n", "\\n") << '"' end s.rstrip end |
#comment(msgid) ⇒ Object
38 39 40 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 38 def comment(msgid) @msgid2comment[msgid] end |
#each_msgid ⇒ Object
55 56 57 58 59 60 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 55 def each_msgid arr = @msgids.delete_if{|i| Symbol === i or i == ''} arr.each do |i| yield i end end |
#generate_po ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 84 def generate_po str = '' str << generate_po_header self.each_msgid do |id| str << self.generate_po_entry(id) end str << @msgid2comment[:last] str end |
#generate_po_entry(msgid) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 110 def generate_po_entry(msgid) str = "" str << @msgid2comment[msgid] if str[-1] != "\n"[0] str << "\n" end id = msgid.gsub(/"/, '\"').gsub(/\r/, '') msgstr = @msgid2msgstr[msgid].gsub(/"/, '\"').gsub(/\r/, '') if id.include?("\000") ids = id.split(/\000/) str << "msgid " << __conv(ids[0]) << "\n" ids[1..-1].each do |single_id| str << "msgid_plural " << __conv(single_id) << "\n" end msgstr.split("\000").each_with_index do |m, n| str << "msgstr[#{n}] " << __conv(m) << "\n" end else str << "msgid " << __conv(id) << "\n" str << "msgstr " << __conv(msgstr) << "\n" end str << "\n" str end |
#generate_po_header ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 96 def generate_po_header str = "" str << @msgid2comment[''].strip << "\n" str << 'msgid ""' << "\n" str << 'msgstr ""' << "\n" msgstr = @msgid2msgstr[''].gsub(/"/, '\"').gsub(/\r/, '') msgstr = msgstr.gsub(/^(.*)$/, '"\1\n"') str << msgstr str << "\n" str end |
#msgid?(msgid) ⇒ Boolean
62 63 64 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 62 def msgid?(msgid) !(Symbol === msgid) and @msgid2msgstr[msgid] and (msgid != '') end |
#msgstr(msgid) ⇒ Object
34 35 36 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 34 def msgstr(msgid) @msgid2msgstr[msgid] end |
#nplural ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 71 def nplural unless @msgid2msgstr[''] return 0 else if /\s*nplural\s*=\s*(\d+)/ =~ @msgid2msgstr[''] return $1.to_i else return 0 end end end |
#search_msgid_fuzzy(msgid, used_msgids) ⇒ Object
Is it necessary to implement this method?
67 68 69 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 67 def search_msgid_fuzzy(msgid, used_msgids) nil end |
#set_comment(msgid_or_sym, comment) ⇒ Object
30 31 32 |
# File 'lib/gettext/tools/rmsgmerge.rb', line 30 def set_comment(msgid_or_sym, comment) @msgid2comment[msgid_or_sym] = comment end |