[Mailman-i18n] sorting pygettext.py output
Tokio Kikuchi
tkikuchi@is.kochi-u.ac.jp
Sun, 20 May 2001 14:40:26 +0900
Tokio Kikuchi wrote:
>
> Hi,
>
> I found it a bit hard task to follow up the versions of mailman-i18n
> because pygettext.py output is random order.
> Following patch and executing the script with `--style sort' option
> make the output more friendly for translaters, I believe.
Stupid me! Yesterday version throws away one or more msgid's when in
a same line, keeping only one msgid. Here is a revised one.
Tokio
--- pygettext.py.orig Sat May 19 22:36:57 2001
+++ pygettext.py Sun May 20 14:23:10 2001
@@ -100,6 +100,7 @@
Solaris # File: filename, line: line-number
GNU #: filename:line
+ sort (slightly modified GNU with filename/line order)
The style name is case insensitive. GNU style is the default.
@@ -139,6 +140,7 @@
import time
import getopt
import tokenize
+import re
__version__ = '1.1'
@@ -288,7 +290,28 @@
# The time stamp in the header doesn't have the same format
# as that generated by xgettext...
print pot_header % {'time': timestamp, 'version':
__version__}
- for k, v in self.__messages.items():
+ if options.locationstyle == options.SORT:
+ separator = '#%= '
+ x = []
+ for k, v in self.__messages.items():
+ file_line = []
+ for filename, lineno in v:
+ file_line.append('#: %s:%05d\n'%
(filename,lineno))
+ file_line.sort()
+ s = ''
+ for f in file_line:
+ s = s + f
+ s = s + separator + k
+ x.append(s)
+ x.sort()
+ sep = re.compile(separator)
+ for s in x:
+ r, k = sep.split(s)
+ print r,
+ print 'msgid', normalize(k)
+ print 'msgstr ""\n'
+ else:
+ for k, v in self.__messages.items():
if not options.writelocations:
pass
# location comments are different b/w Solaris and GNU:
@@ -336,6 +359,7 @@
# constants
GNU = 1
SOLARIS = 2
+ SORT = 3
# defaults
extractall = 0 # FIXME: currently this option has no effect at
all.
escape = 0
@@ -351,6 +375,7 @@
options = Options()
locations = {'gnu' : options.GNU,
'solaris' : options.SOLARIS,
+ 'sort' : options.SORT,
}
# parse options