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]
92 print
"#: %s:%s\n" % [@location[:file], @location[:line]]
97 @prev.each_with_index
do |lin
, idx
|
99 print
"#| msgid \"%s\"\n" % lin
101 print
"#| \"%s\"\n" % lin
106 @src.each_with_index
do |lin
, idx
|
108 print
"msgid \"%s\"\n" % lin
110 print
"\"%s\"\n" % lin
113 @dest.each_with_index
do |lin
, idx
|
115 print
"msgstr \"%s\"\n" % lin
117 print
"\"%s\"\n" % lin
124 raise ArgumentError
, 'Source file not specified' if ARGV.size !
= 1
126 strings
= File
.open(file
,'r').read
.split(/\n\n/)[1..-1].map
{|str
| PoStr
.new(str
)}
131 strings
.each
do |entry
|
132 # Ignore whitespace changes between prev and src
133 entry
.prevclean
= entry
.prevstr().gsub(/ +/, ' ')
134 entry
.srcclean
= entry
.srcstr().gsub(/ +/, ' ')
137 if entry
.prevclean
== entry
.srcclean
139 #print "# clear fuzzy (space)\n"
145 # Rewrite title strings, which lost '#' at the front
146 if entry
.prevclean
.gsub(/^#+ +/, '') == entry
.srcclean
147 # FIXME Not safe to clear fuzzy flag, might have bogus translation
149 if entry
.dest
[0].gsub!
(/^#+ +/, '') ||
150 ('' == entry
.dest
[0] && entry
.dest
[1].gsub!
(/^#+ +/, ''))
151 #print "cleared fuzzy (title)\n"
156 # Rewrite footnotes to use "<placeholder type=\"footnote\" id=\"0\"/>"
157 if entry
.srcclean
=~
/<placeholder type=\\"footnote\\" id=\\"0\\"\/>/
158 #print "found footnote\n"
160 p
.sub!
(/([a-z]\.["”]?)(\d+)(\s)/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>\\3")
161 p
.sub!
(/([a-z]\.["”]?)(\d+)$/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>")
163 #print entry.src, "\n"
164 if p
== entry
.srcclean
166 entry
.dest
.each
do |part
|
167 if part
.sub!
(/([a-z]\.["”»]?)(\d+)(\s)/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>\\3")
171 entry
.dest
.each
do |part
|
172 if part
.sub!
(/([a-z]\.["”»]?)(\d+)$/, "\\1<placeholder type=\\\"footnote\\\" id=\\\"0\\\"\/>")
177 #print "cleared fuzzy (footnote)\n"
185 # Copy image references and single URLs unchanged, even for non-fuzzies
186 if entry
.prevclean
=~
/!\[\]\(Pictures\// ||
187 entry
.srcclean
=~
/^<ulink url=\\\".+\\\"\/>$/
188 entry
.dest
= entry
.src
.clone()
195 print
"# Cleared %d fuzzy strings\n" % [c
]