4 Sections
= %w(Headers Source Translated
)
5 attr_accessor
:status, :src, :srcclean, :dest, :prev, :prevclean, :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
]
84 # No use outputting empty translations
85 if '' == srcstr() && '' == deststr()
89 print
"#. type:%s\n" % [@type]
94 @prev.each_with_index
do |lin
, idx
|
96 print
"#| msgid \"%s\"\n" % lin
98 print
"#| \"%s\"\n" % lin
103 @src.each_with_index
do |lin
, idx
|
105 print
"msgid \"%s\"\n" % lin
107 print
"\"%s\"\n" % lin
110 @dest.each_with_index
do |lin
, idx
|
112 print
"msgstr \"%s\"\n" % lin
114 print
"\"%s\"\n" % lin
121 raise ArgumentError
, 'Source file not specified' if ARGV.size !
= 1
123 strings
= File
.open(file
,'r').read
.split(/\n\n/)[1..-1].map
{|str
| PoStr
.new(str
)}
128 strings
.each
do |entry
|
130 # Ignore whitespace changes between prev and src
131 entry
.prevclean
= entry
.prevstr().gsub(/ +/, ' ')
132 entry
.srcclean
= entry
.srcstr().gsub(/ +/, ' ')
134 if entry
.prevclean
== entry
.srcclean
136 #print "clear fuzzy (space)\n"
141 # Rewrite title strings, which lost '#' at the front
142 if entry
.prevclean
.gsub(/^#+ +/, '') == entry
.srcclean
145 if entry
.dest
[0].gsub!
(/^#+ +/, '') ||
146 ('' == entry
.dest
[0] && entry
.dest
[1].gsub!
(/^#+ +/, ''))
147 #print "cleared fuzzy (title)\n"
152 # Rewrite footnotes to use "<placeholder type=\"footnote\" id=\"0\"/>"
153 if entry
.srcclean
=~
/<placeholder type=\\"footnote\\" id=\\"0\\"\/>/
154 #print "found footnote\n"
156 p
.sub!
(/([a-z]\.["”]?)(\d+)(\s)/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>\\3")
157 p
.sub!
(/([a-z]\.["”]?)(\d+)$/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>")
159 #print entry.src, "\n"
160 if p
== entry
.srcclean
162 entry
.dest
.each
do |part
|
163 if part
.sub!
(/([a-z]\.["”»]?)(\d+)(\s)/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>\\3")
167 entry
.dest
.each
do |part
|
168 if part
.sub!
(/([a-z]\.["”»]?)(\d+)$/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>")
173 #print "cleared fuzzy (footnote)\n"
182 print
"# Would clear %d fuzzy\n" % [c
]