#!/usr/bin/env python # -*- mode: python; coding: iso-8859-1 -*- # Copyright © 1996, 1999, 2000 Progiciels Bourbeau-Pinard inc. # François Pinard , 1996. """\ Tripotage temporaire, un fichier `.scm' d'un fichier `.po'. """ import os, sys sys.path.insert(0, os.path.expanduser('~/po/web/lib')) def _(text): return text if len(sys.argv) > 1: if sys.argv[1] == '-scm': mode_scm = 1 del sys.argv[1] elif sys.argv[1] == '-el': mode_el = 1 del sys.argv[1] elif sys.argv[1][0] == '-': raise _('Usage: %s [ -scm | -el ] [FILE]...') % sys.argv[0] if mode_el: mode_scm = 1 # FIXME: ### sys.stdin .vs. sys.argv ? prologue() for line in sys.stdin.readlines(): match = re.match('msgid "(.*)"$', line) if match: type = 'msgid' msgid = match.group(1) continue match = re.match('msgstr "(.*)"$', line) if match: type = 'msgstr' msgstr = match.group(1) continue match = re.match('"(.*)"$', line) if match: if type == 'msgid': msgid = msgid + match.group(1) else: msgstr = msgstr + match.group(1) continue if line[0] == '\n' or line[0] == '#': if msgstr: process_pair() continue if msgstr: process_pair() epilogue() def process_pair(): msgid = re.sub(r'\\n', r'\n', msgid) msgstr = re.sub(r'\\n', r'\n', msgstr) sys.stdout.write(' ("%s"\n' % msgid) sys.stdout.write(' + "%s")\n' % msgstr) def prologue(): sys.stdout.write("""\ ;;; This file has been generated by `%s' -- DO NOT EDIT! ;;; Gettext substitute for Gambit, waiting for the real thing. ;;; Copyright © 1996 Progiciels Bourbeau-Pinard inc. ;;; François Pinard , 1996. (define (gettext string) (let ((translation (assoc string gettext:table))) (if translation (cdr translation) string))) (define (gettext-noop string) string) (define _ gettext) (define N_ gettext-noop) (define gettext:table '( """ % sys.argv[0]) def epilogue(): sys.stdout.write("""\ )) """)