4 Sections
= %w(Headers Source Translated
)
5 attr_accessor
:status, :src, :dest, :prev, :type, :location
13 text
.split(/\n/).each
do |lin
|
16 if lin
=~
/^#(.) ([^:]*)(?::(.*))?/
21 @status = 'fuzzy' if type
== ',' and field
== 'fuzzy'
22 @type = value
if type
== '.' and field
== 'type'
23 @location = {:file => field
, :line => value
} if type
== ':'
25 if field
=~
/^msgid "(.*)"/
27 elsif field
=~
/^"(.*)"$/
31 elsif lin
=~
/^msgid "(.*)"/
35 boom(section
, lin
, text
)
42 elsif lin
=~
/^msgstr "(.*)"/
46 boom(section
, lin
, text
)
54 boom(section
, lin
, text
)
60 def boom(section
, line
, text
)
61 raise RuntimeError
, "Unexpected string in %s:\n %s\n\nFull text: %s" %
62 [Sections
[section
], line
, text
]
70 # FIXME rewrite to output proper entries
72 print
"#. type: %s\n" % [@type]
77 print
"#| msgid \"%s\"\n" % [@prev]
80 print
"msgid \"%s\"\n" % [@src]
81 print
"msgstr \"%s\"\n" % [@dest]
86 raise ArgumentError
, 'Source file not specified' if ARGV.size !
= 1
88 strings
= File
.open(file
,'r').read
.split(/\n\n/)[1..-1].map
{|str
| PoStr
.new(str
)}
93 strings
.each
do |entry
|
95 # Ignore whitespace changes between prev and src
96 if entry
.prev
.gsub(/ +/, ' ') == entry
.src
.gsub(/ +/, ' ')
98 print
"clear fuzzy (space)\n"
102 # Rewrite title strings, which lost '#' at the front
103 if entry
.prev
.gsub(/^#+ +/, '') == entry
.src
105 entry
.dest
.gsub!
(/^#+ +/, '')
106 print
"cleared fuzzy (title)\n"
110 # Rewrite footnotes to use "<placeholder type=\"footnote\" id=\"0\"/>"
111 if entry
.src
=~
/<placeholder type=\\"footnote\\" id=\\"0\\"\/>/
112 print
"found footnote\n"
114 p
.sub!
(/([a-z]\.["”]?)(\d+)(\s)/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>\\3")
115 p
.sub!
(/([a-z]\.["”]?)(\d+)$/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>")
117 print entry
.src
, "\n"
120 entry
.dest
.sub!
(/([a-z]\.["”»]?)(\d+)(\s)/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>\\3")
121 entry
.dest
.sub!
(/([a-z]\.["”»]?)(\d+)$/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>")
122 print
"cleared fuzzy (footnote)\n"
129 print
"Would clear %d fuzzy\n" % [c
]