[1108] | 1 | #!/usr/bin/python |
---|
| 2 | # sh_xgettext |
---|
| 3 | # Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
---|
| 4 | # Wed Mar 10 10:24:35 EST 1999 |
---|
| 5 | # Copyright Conectiva Consultoria e Desenvolvimento de Sistemas LTDA |
---|
| 6 | # |
---|
| 7 | # This program is free software; you can redistribute it and/or modify |
---|
| 8 | # it under the terms of the GNU General Public License as published by |
---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 10 | # (at your option) any later version. |
---|
| 11 | # |
---|
| 12 | # This program is distributed in the hope that it will be useful, |
---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | # GNU General Public License for more details. |
---|
| 16 | # |
---|
| 17 | # You should have received a copy of the GNU General Public License |
---|
| 18 | # along with this program; if not, write to the Free Software |
---|
| 19 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 20 | # |
---|
| 21 | # Changelog |
---|
| 22 | # Mon May 31 1999 Wanderlei Antonio Cavassin <cavassin@conectiva.com> |
---|
| 23 | # * option --initscripts |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | from sys import argv |
---|
| 27 | from string import find, split, strip |
---|
| 28 | |
---|
| 29 | s = {} |
---|
| 30 | |
---|
| 31 | def xgettext(arq, tokens_i18n): |
---|
| 32 | line = 0 |
---|
| 33 | f = open(arq, "r") |
---|
| 34 | while 1: |
---|
| 35 | l = f.readline() |
---|
| 36 | if not l: break |
---|
| 37 | line = line + 1 |
---|
| 38 | if l[0:1] == '#': continue |
---|
| 39 | elif l[0:1] == '\n': continue |
---|
| 40 | else: |
---|
| 41 | for token in tokens_i18n: |
---|
| 42 | pos = find(l, token + ' $"') |
---|
| 43 | if pos != -1: |
---|
| 44 | text = split(l[pos:], '"')[1] |
---|
| 45 | #if find (text, '$') != -1: |
---|
| 46 | # continue |
---|
| 47 | if s.has_key(text): |
---|
| 48 | s[text].append((arq, line)) |
---|
| 49 | else: |
---|
| 50 | s[text] = [(arq, line)] |
---|
| 51 | f.close() |
---|
| 52 | |
---|
| 53 | def print_header(): |
---|
| 54 | print 'msgid ""' |
---|
| 55 | print 'msgstr ""' |
---|
| 56 | print '"Project-Id-Version: \\n"' |
---|
| 57 | print '"PO-Revision-Date: YYYY-MM-DD HH:MM TZO DST\\n"' |
---|
| 58 | print '"Last-Translator: \\n"' |
---|
| 59 | print '"Language-Team: <XX@li.org>\\n"' |
---|
| 60 | print '"MIME-Version: 1.0\\n"' |
---|
| 61 | print '"Content-Type: text/plain; charset=ISO-8859-1\\n"' |
---|
| 62 | print '"Content-Transfer-Encoding: 8-bit\\n"\n' |
---|
| 63 | |
---|
| 64 | def print_pot(): |
---|
| 65 | print_header() |
---|
| 66 | |
---|
| 67 | for text in s.keys(): |
---|
| 68 | print '#:', |
---|
| 69 | for p in s[text]: |
---|
| 70 | print '%s:%d' % p, |
---|
| 71 | if find(text, '%') != -1: |
---|
| 72 | print '\n#, c-format', |
---|
| 73 | print '\nmsgid "' + text + '"' |
---|
| 74 | print 'msgstr ""\n' |
---|
| 75 | |
---|
| 76 | def main(): |
---|
| 77 | i18n_tokens = [] |
---|
| 78 | i18n_tokens.append('echo') |
---|
| 79 | i18n_tokens.append('echo -n') |
---|
| 80 | i18n_tokens.append('echo -e') |
---|
| 81 | i18n_tokens.append('echo -en') |
---|
| 82 | i18n_tokens.append('echo -ne') |
---|
| 83 | i18n_tokens.append('action') |
---|
| 84 | i18n_tokens.append('failure') |
---|
| 85 | i18n_tokens.append('passed') |
---|
| 86 | i18n_tokens.append('runcmd') |
---|
| 87 | i18n_tokens.append('success') |
---|
| 88 | |
---|
| 89 | for a in argv: |
---|
| 90 | xgettext(a, i18n_tokens) |
---|
| 91 | |
---|
| 92 | print_pot() |
---|
| 93 | |
---|
| 94 | if __name__ == '__main__': |
---|
| 95 | main() |
---|