mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Sort the key of *.po files.
Without sorting the key, it is difficult to maintain the language resource files on Git.
This commit is contained in:
@ -30,11 +30,11 @@ def read_po(fp):
|
|||||||
rvalue += line
|
rvalue += line
|
||||||
elif line.startswith('msgid '):
|
elif line.startswith('msgid '):
|
||||||
st = 1
|
st = 1
|
||||||
key = unquote(line[5:])
|
key = unquote(line[6:])
|
||||||
rkey = line
|
rkey = line
|
||||||
elif line.startswith('msgstr '):
|
elif line.startswith('msgstr '):
|
||||||
st = 2
|
st = 2
|
||||||
value = unquote(line[6:])
|
value = unquote(line[7:])
|
||||||
rvalue = line
|
rvalue = line
|
||||||
else:
|
else:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
@ -45,34 +45,29 @@ def read_po(fp):
|
|||||||
def main():
|
def main():
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Read the current text catalog.
|
# Read the new text catalog template.
|
||||||
d = {}
|
d = {}
|
||||||
firstcomment = ''
|
for (comment, key, value, rkey, rvalue) in read_po(sys.stdin):
|
||||||
it = read_po(file(sys.argv[1]))
|
d[key] = (comment, rkey, rvalue)
|
||||||
try:
|
|
||||||
(comment, key, value, rkey, rvalue) = it.next()
|
# Override existing entries with current text catalog.
|
||||||
d[key] = rvalue
|
for (comment, key, value, rkey, rvalue) in read_po(file(sys.argv[1])):
|
||||||
firstcomment = comment # Preserve the first comment block
|
if d.has_key(key):
|
||||||
except StopIteration:
|
d[key] = (comment, rkey, rvalue)
|
||||||
pass
|
|
||||||
for (comment, key, value, rkey, rvalue) in it:
|
|
||||||
d[key] = rvalue
|
|
||||||
|
|
||||||
# Read the new text catalog template and output.
|
|
||||||
# The translated values come from the current text catalog read above.
|
|
||||||
out = file(sys.argv[1], 'w')
|
out = file(sys.argv[1], 'w')
|
||||||
out.write(firstcomment)
|
if d.has_key(''):
|
||||||
it = read_po(sys.stdin)
|
(comment, rkey, rvalue) = d['']
|
||||||
try:
|
|
||||||
(comment, key, value, rkey, rvalue) = it.next()
|
|
||||||
out.write(rkey)
|
|
||||||
out.write(d.get(key, rvalue))
|
|
||||||
except StopIteration:
|
|
||||||
pass
|
|
||||||
for (comment, key, value, rkey, rvalue) in it:
|
|
||||||
out.write(comment)
|
out.write(comment)
|
||||||
out.write(rkey)
|
out.write(rkey)
|
||||||
out.write(d.get(key, rvalue))
|
out.write(rvalue)
|
||||||
|
del d['']
|
||||||
|
|
||||||
|
for key in sorted(d.keys()):
|
||||||
|
(comment, rkey, rvalue) = d[key]
|
||||||
|
out.write(comment)
|
||||||
|
out.write(rkey)
|
||||||
|
out.write(rvalue)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Reference in New Issue
Block a user