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
== ':'
26 if lin
=~
/^\#\| msgid "(.*)"$/
27 #print "first '%s'\n" % $1
29 elsif lin
=~
/^\#\| "(.*)"$/
33 elsif lin
=~
/^msgid "(.*)"/
37 boom(section
, lin
, text
)
44 elsif lin
=~
/^msgstr "(.*)"/
48 boom(section
, lin
, text
)
56 boom(section
, lin
, text
)
62 def boom(section
, line
, text
)
63 raise RuntimeError
, "Unexpected string in %s:\n %s\n\nFull text: %s" %
64 [Sections
[section
], line
, text
]
72 # FIXME rewrite to output proper entries
74 print
"#. type: %s\n" % [@type]
79 print
"#| msgid \"%s\"\n" % [@prev]
82 print
"msgid \"%s\"\n" % [@src]
83 print
"msgstr \"%s\"\n" % [@dest]
88 raise ArgumentError
, 'Source file not specified' if ARGV.size !
= 1
90 strings
= File
.open(file
,'r').read
.split(/\n\n/)[1..-1].map
{|str
| PoStr
.new(str
)}
95 strings
.each
do |entry
|
97 # Ignore whitespace changes between prev and src
98 if entry
.prev
.gsub(/ +/, ' ') == entry
.src
.gsub(/ +/, ' ')
100 print
"clear fuzzy (space)\n"
104 # Rewrite title strings, which lost '#' at the front
105 if entry
.prev
.gsub(/^#+ +/, '') == entry
.src
107 entry
.dest
.gsub!
(/^#+ +/, '')
108 print
"cleared fuzzy (title)\n"
112 # Rewrite footnotes to use "<placeholder type=\"footnote\" id=\"0\"/>"
113 if entry
.src
=~
/<placeholder type=\\"footnote\\" id=\\"0\\"\/>/
114 print
"found footnote\n"
116 p
.sub!
(/([a-z]\.["”]?)(\d+)(\s)/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>\\3")
117 p
.sub!
(/([a-z]\.["”]?)(\d+)$/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>")
119 print entry
.src
, "\n"
122 entry
.dest
.sub!
(/([a-z]\.["”»]?)(\d+)(\s)/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>\\3")
123 entry
.dest
.sub!
(/([a-z]\.["”»]?)(\d+)$/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>")
124 print
"cleared fuzzy (footnote)\n"
131 print
"Would clear %d fuzzy\n" % [c
]