diff options
Diffstat (limited to 'po/xgettext_sh.py')
-rwxr-xr-x | po/xgettext_sh.py | 130 |
1 files changed, 73 insertions, 57 deletions
diff --git a/po/xgettext_sh.py b/po/xgettext_sh.py index d442e989..0391d650 100755 --- a/po/xgettext_sh.py +++ b/po/xgettext_sh.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # sh_xgettext # Arnaldo Carvalho de Melo <acme@conectiva.com.br> # Wed Mar 10 10:24:35 EST 1999 @@ -24,74 +24,90 @@ from sys import argv -from string import find, split, strip +import string import re s = {} pattern = re.compile('[ =]\$"') + def xgettext(arq): - line = 0 - f = open(arq, "r") - while 1: - l = f.readline() - if not l: break - line = line + 1 - if l[0:1] == '#': continue - elif l[0:1] == '\n': continue - else: - for match in pattern.finditer(l): - pos = match.start() - p1 = l.find('"',pos) + 1 - p2 = p1+1 - while 1: - p2 = l.find('"',p2) - if p2 == -1: - p2 = p1 - break - if l[p2-1] == '\\': - p2 = p2 + 1 - else: - break - text = l[p1:p2] - #text = split(l[pos:], '"')[1] - if s.has_key(text): - s[text].append((arq, line)) - else: - s[text] = [(arq, line)] - f.close() + line = 0 + f = open(arq, "r") + + while 1: + l = f.readline() + + if not l: + break + + line = line + 1 + + if l[0:1] == '#': + continue + elif l[0:1] == '\n': + continue + else: + for match in pattern.finditer(l): + pos = match.start() + p1 = l.find('"', pos) + 1 + p2 = p1 + 1 + + while 1: + p2 = l.find('"', p2) + if p2 == -1: + p2 = p1 + break + if l[p2-1] == '\\': + p2 = p2 + 1 + else: + break + text = l[p1:p2] + + if text in s: + s[text].append((arq, line)) + else: + s[text] = [(arq, line)] + + f.close() + def print_header(): - print 'msgid ""' - print 'msgstr ""' - print '"Project-Id-Version: PACKAGE VERSION\\n"' - print '"Report-Msgid-Bugs-To: \\n"' - print '"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\\n"' - print '"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"' - print '"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"' - print '"Language-Team: LANGUAGE <LL@li.org>\\n"' - print '"Language: \\n"' - print '"MIME-Version: 1.0\\n"' - print '"Content-Type: text/plain; charset=UTF-8\\n"' - print '"Content-Transfer-Encoding: 8bit\\n"\n' + print('msgid ""') + print('msgstr ""') + print('"Project-Id-Version: PACKAGE VERSION\\n"') + print('"Report-Msgid-Bugs-To: \\n"') + print('"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\\n"') + print('"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"') + print('"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"') + print('"Language-Team: LANGUAGE <LL@li.org>\\n"') + print('"Language: \\n"') + print('"MIME-Version: 1.0\\n"') + print('"Content-Type: text/plain; charset=UTF-8\\n"') + print('"Content-Transfer-Encoding: 8bit\\n"\n') + def print_pot(): - print_header() - - for text in s.keys(): - print '#:', - for p in s[text]: - print '%s:%d' % p, - if find(text, '%') != -1: - print '\n#, c-format', - print '\nmsgid "' + text + '"' - print 'msgstr ""\n' - + print_header() + + for text in list(s.keys()): + print('#:', end=' ') + + for p in s[text]: + print('%s:%d' % p, end=' ') + + if text.find('%') != -1: + print('\n#, c-format', end=' ') + + print('\nmsgid "' + text + '"') + print('msgstr ""\n') + + def main(): - for a in argv: - xgettext(a) + for a in argv: + xgettext(a) - print_pot() + print_pot() if __name__ == '__main__': main() |