From 2970911df1a8c4c1a0b0413488710c16e4a37ab2 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Fri, 10 Mar 2006 16:23:25 +0000 Subject: [PATCH] Add support for translations. --- MANIFEST.in | 1 + Makefile | 3 ++ po/Makefile | 71 +++++++++++++++++++++++++++++ po/pykickstart.pot | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ pykickstart/parser.py | 50 ++++++++++---------- validator/ksvalidator | 15 ++++-- 6 files changed, 235 insertions(+), 28 deletions(-) create mode 100644 po/Makefile create mode 100644 po/pykickstart.pot diff --git a/MANIFEST.in b/MANIFEST.in index 6d9758e..a53247f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include COPYING ChangeLog Makefile pykickstart.spec +recursive-include po *.po *.pot Makefile recursive-include docs programmers-guide diff --git a/Makefile b/Makefile index ec1a40f..8f98994 100644 --- a/Makefile +++ b/Makefile @@ -9,12 +9,15 @@ PREFIX=/usr default: all all: + $(MAKE) -C po clean: -rm *.tar.gz pykickstart/*.pyc + $(MAKE) -C po clean python setup.py -q clean --all install: all + $(MAKE) -C po install python setup.py install --root=$(DESTDIR) tag: diff --git a/po/Makefile b/po/Makefile new file mode 100644 index 0000000..f4dad53 --- /dev/null +++ b/po/Makefile @@ -0,0 +1,71 @@ +# +# Makefile for the PO files (translation) catalog +# +# $Id$ + +TOP = ../.. + +# What is this package? +NLSPACKAGE = pykickstart +POTFILE = $(NLSPACKAGE).pot +INSTALL = /usr/bin/install -c +INSTALL_DATA = $(INSTALL) -m 644 +INSTALL_DIR = /usr/bin/install -d + +# destination directory +INSTALL_NLS_DIR = $(DESTDIR)/usr/share/locale + +# PO catalog handling +MSGMERGE = msgmerge -v +XGETTEXT = xgettext --default-domain=$(NLSPACKAGE) \ + --add-comments +MSGFMT = msgfmt --statistics --verbose + +# What do we need to do +POFILES = $(wildcard *.po) +MOFILES = $(patsubst %.po,%.mo,$(POFILES)) +PYSRC = $(wildcard ../pykickstart/*.py) +SRCFILES = $(PYSRC) ../validator/ksvalidator + +#default:: clean + +all:: update-po $(MOFILES) + +$(POTFILE): $(SRCFILES) + $(XGETTEXT) -L Python --keyword=_ --keyword=N_ $(SRCFILES) + @if cmp -s $(NLSPACKAGE).po $(POTFILE); then \ + rm -f $(NLSPACKAGE).po; \ + else \ + mv -f $(NLSPACKAGE).po $(POTFILE); \ + fi; \ + +update-po: Makefile $(POTFILE) refresh-po + +refresh-po: Makefile + for cat in $(POFILES); do \ + lang=`basename $$cat .po`; \ + if $(MSGMERGE) $$lang.po $(POTFILE) > $$lang.pot ; then \ + mv -f $$lang.pot $$lang.po ; \ + echo "$(MSGMERGE) of $$lang succeeded" ; \ + else \ + echo "$(MSGMERGE) of $$lang failed" ; \ + rm -f $$lang.pot ; \ + fi \ + done + +clean: + @rm -fv *mo *~ .depend + +install: $(MOFILES) + @for n in $(MOFILES); do \ + l=`basename $$n .mo`; \ + $(INSTALL_DIR) $(INSTALL_NLS_DIR)/$$l/LC_MESSAGES; \ + $(INSTALL_DATA) --verbose $$n $(INSTALL_NLS_DIR)/$$l/LC_MESSAGES/$(NLSPACKAGE).mo; \ + done + +%.mo: %.po + $(MSGFMT) -o $@ $< + +.PHONY: missing depend + + diff --git a/po/pykickstart.pot b/po/pykickstart.pot new file mode 100644 index 0000000..96f72f6 --- /dev/null +++ b/po/pykickstart.pot @@ -0,0 +1,123 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2006-03-10 11:19-0500\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: ../pykickstart/parser.py:45 +#, python-format +msgid "" +"The following problem occurred on line %s of the kickstart file:\n" +"\n" +"%s\n" +msgstr "" + +#: ../pykickstart/parser.py:47 +#, python-format +msgid "There was a problem reading from line %s of the kickstart file" +msgstr "" + +#: ../pykickstart/parser.py:104 +#, python-format +msgid "Option %s is required" +msgstr "" + +#: ../pykickstart/parser.py:107 +#, python-format +msgid "" +"Ignoring deprecated option on line %s: The %s option has been deprecated " +"and no longer has any effect. It may be removed from future releases, which " +"will result in a fatal error from kickstart. Please modify your kickstart " +"file to remove this option." +msgstr "" + +#: ../pykickstart/parser.py:139 +msgid "Required flag set for option that doesn't take a value" +msgstr "" + +#: ../pykickstart/parser.py:147 +#, python-format +msgid "Option %s: invalid boolean value: %r" +msgstr "" + +#: ../pykickstart/parser.py:278 +#, python-format +msgid "" +"Ignoring deprecated command on line %s: The %s command has been deprecated " +"and no longer has any effect. It may be removed from future releases, which " +"will result in a fatal error from kickstart. Please modify your kickstart " +"file to remove this command." +msgstr "" + +#: ../pykickstart/parser.py:285 ../pykickstart/parser.py:414 +#: ../pykickstart/parser.py:474 ../pykickstart/parser.py:705 +#: ../pykickstart/parser.py:723 +#, python-format +msgid "Command %s does not take any arguments" +msgstr "" + +#: ../pykickstart/parser.py:420 ../pykickstart/parser.py:426 +#, python-format +msgid "Command %s only takes one argument" +msgstr "" + +#: ../pykickstart/parser.py:463 ../pykickstart/parser.py:606 +#: ../pykickstart/parser.py:668 +#, python-format +msgid "Mount point required for %s" +msgstr "" + +#: ../pykickstart/parser.py:516 ../pykickstart/parser.py:791 +#, python-format +msgid "Unexpected arguments to %s command: %s" +msgstr "" + +#: ../pykickstart/parser.py:687 ../pykickstart/parser.py:717 +#, python-format +msgid "A single argument is expected for the %s command" +msgstr "" + +#: ../pykickstart/parser.py:798 +#, python-format +msgid "" +"Ignoring deprecated option on line %s: The zerombr command no longer takes " +"any options. In future releases, this will result in a fatal error from " +"kickstart. Please modify your kickstart file to remove any options." +msgstr "" + +#: ../validator/ksvalidator:29 +msgid "halt after the first error or warning" +msgstr "" + +#: ../validator/ksvalidator:32 +#, python-format +msgid "parse include files when %include is seen" +msgstr "" + +#: ../validator/ksvalidator:54 +#, python-format +msgid "" +"File uses a deprecated option or command.\n" +"%s" +msgstr "" + +#: ../validator/ksvalidator:60 +msgid "General kickstart error in input file" +msgstr "" + +#: ../validator/ksvalidator:63 +#, python-format +msgid "General error in input file: %s" +msgstr "" diff --git a/pykickstart/parser.py b/pykickstart/parser.py index a00d2d5..7490288 100644 --- a/pykickstart/parser.py +++ b/pykickstart/parser.py @@ -23,6 +23,11 @@ from optparse import * from constants import * from data import * +from rhpl.translate import _ +import rhpl.translate as translate + +translate.textdomain("pykickstart") + STATE_END = 0 STATE_COMMANDS = 1 STATE_PACKAGES = 2 @@ -37,9 +42,9 @@ STATE_TRACEBACK = 6 def formatErrorMsg(lineno, msg=""): if msg != "": - return "The following problem occurred on line %s of the kickstart file:\n\n%s\n" % (lineno, msg) + return _("The following problem occurred on line %s of the kickstart file:\n\n%s\n") % (lineno, msg) else: - return "There was a problem reading from line %s of the kickstart file" % lineno + return _("There was a problem reading from line %s of the kickstart file") % lineno class KickstartError(Exception): def __init__(self, val = ""): @@ -96,10 +101,10 @@ class KSOptionParser(OptionParser): for option in self.option_list: if (isinstance(option, Option) and option.required and \ not self.option_seen.has_key(option)): - raise KickstartValueError, formatErrorMsg(self.lineno, "Option %s is required" % option) + raise KickstartValueError, formatErrorMsg(self.lineno, _("Option %s is required") % option) elif isinstance(option, Option) and option.deprecated and \ self.option_seen.has_key(option): - warnings.warn("Ignoring deprecated option on line %s: The %s option has been deprecated and no longer has any effect. It may be removed from future releases, which will result in a fatal error from kickstart. Please modify your kickstart file to remove this option." % (self.lineno, option), DeprecationWarning) + warnings.warn(_("Ignoring deprecated option on line %s: The %s option has been deprecated and no longer has any effect. It may be removed from future releases, which will result in a fatal error from kickstart. Please modify your kickstart file to remove this option.") % (self.lineno, option), DeprecationWarning) return (values, args) @@ -131,7 +136,7 @@ class KSOption (Option): def _check_required(self): if self.required and not self.takes_value(): - raise OptionError("Required flag set for option that doesn't take a value", self) + raise OptionError(_("Required flag set for option that doesn't take a value"), self) def _check_ksboolean(option, opt, value): if value.lower() in ("on", "yes", "true", "1"): @@ -139,8 +144,7 @@ class KSOption (Option): elif value.lower() in ("off", "no", "false", "0"): return False else: - raise OptionValueError("option %s: invalid boolean " - "value: %r" % (opt, value)) + raise OptionValueError(_("Option %s: invalid boolean value: %r") % (opt, value)) # Make sure _check_required() is called from the constructor! CHECK_METHODS = Option.CHECK_METHODS + [_check_required] @@ -271,14 +275,14 @@ class KickstartHandlers: self.handlers[key] = None def deprecatedCommand(self, cmd): - warnings.warn("Ignoring deprecated command on line %s: The %s command has been deprecated and no longer has any effect. It may be removed from future releases, which will result in a fatal error from kickstart. Please modify your kickstart file to remove this command." % (self.lineno, cmd), DeprecationWarning) + warnings.warn(_("Ignoring deprecated command on line %s: The %s command has been deprecated and no longer has any effect. It may be removed from future releases, which will result in a fatal error from kickstart. Please modify your kickstart file to remove this command.") % (self.lineno, cmd), DeprecationWarning) def doAuthconfig(self, args): self.ksdata.authconfig = string.join(args) def doAutoPart(self, args): if len(args) > 0: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Command does not take any arguments") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Command %s does not take any arguments") % "autopart") self.ksdata.autopart = True @@ -407,19 +411,19 @@ class KickstartHandlers: def doInteractive(self, args): if len(args) > 0: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Command does not take any arguments") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Command %s does not take any arguments") % "interactive") self.ksdata.interactive = True def doKeyboard(self, args): if len(args) > 1: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Command only takes one argument") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Command %s only takes one argument") % "keyboard") self.ksdata.keyboard = args[0] def doLang(self, args): if len(args) > 1: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Command only takes one argument") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Command %s only takes one argument") % "lang") self.ksdata.lang = args[0] @@ -456,7 +460,7 @@ class KickstartHandlers: (opts, extra) = op.parse_args(args=args) if len(extra) == 0: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Mount point required for logvol") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Mount point required for %s") % "logvol") lvd = KickstartLogVolData() for key in filter (lambda k: getattr(opts, k) != None, op.keys()): @@ -467,7 +471,7 @@ class KickstartHandlers: def doMediaCheck(self, args): if len(args) > 0: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Command does not take any arguments") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Command %s does not take any arguments") % "mediacheck") self.ksdata.mediacheck = True @@ -509,7 +513,7 @@ class KickstartHandlers: (opts, extra) = op.parse_args(args=args) if extra: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Unexpected arguments to monitor command: %s" % extra) + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %s command: %s") % ("monitor", extra)) for key in filter (lambda k: getattr(opts, k) != None, op.keys()): self.ksdata.monitor[key] = getattr(opts, key) @@ -599,7 +603,7 @@ class KickstartHandlers: (opts, extra) = op.parse_args(args=args) if len(extra) != 1: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Mount point required for partition") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Mount point required for %s") % "partition") pd = KickstartPartData() for key in filter (lambda k: getattr(opts, k) != None, op.keys()): @@ -661,7 +665,7 @@ class KickstartHandlers: (opts, extra) = op.parse_args(args=args) if len(extra) == 0: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Mount point required for raid") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Mount point required for %s") % "raid") rd = KickstartRaidData() for key in filter (lambda k: getattr(opts, k) != None, op.keys()): @@ -680,7 +684,7 @@ class KickstartHandlers: self.ksdata.rootpw["isCrypted"] = opts.isCrypted if len(extra) != 1: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="A single argument is expected for rootpw") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("A single argument is expected for the %s command") % "rootpw") self.ksdata.rootpw["password"] = extra[0] @@ -698,7 +702,7 @@ class KickstartHandlers: def doSkipX(self, args): if len(args) > 0: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Command does not take any arguments") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Command %s does not take any arguments") % "skipx") self.ksdata.skipx = True @@ -710,13 +714,13 @@ class KickstartHandlers: self.ksdata.timezone["isUtc"] = opts.isUtc if len(extra) != 1: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="A single argument is expected for timezone") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("A single argument is expected for the %s command") % "timezone") self.ksdata.timezone["timezone"] = extra[0] def doUpgrade(self, args): if len(args) > 0: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Command does not take any arguments") + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Command %s does not take any arguments") % "upgrade") self.ksdata.upgrade = True @@ -784,14 +788,14 @@ class KickstartHandlers: (opts, extra) = op.parse_args(args=args) if extra: - raise KickstartValueError, formatErrorMsg(self.lineno, msg="Unexpected arguments to xconfig command: %s" % extra) + raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %s command: %s" % ("xconfig", extra))) for key in filter (lambda k: getattr(opts, k) != None, op.keys()): self.ksdata.xconfig[key] = getattr(opts, key) def doZeroMbr(self, args): if len(args) > 0: - warnings.warn("Ignoring deprecated option on line %s: The zerombr command no longer takes any options. In future releases, this will result in a fatal error from kickstart. Please modify your kickstart file to remove any options." % self.lineno, DeprecationWarning) + warnings.warn(_("Ignoring deprecated option on line %s: The zerombr command no longer takes any options. In future releases, this will result in a fatal error from kickstart. Please modify your kickstart file to remove any options.") % self.lineno, DeprecationWarning) self.ksdata.zerombr = True diff --git a/validator/ksvalidator b/validator/ksvalidator index 0c5211e..157f917 100755 --- a/validator/ksvalidator +++ b/validator/ksvalidator @@ -19,12 +19,17 @@ import warnings from pykickstart.data import * from pykickstart.parser import * +from rhpl.translate import _ +import rhpl.translate as translate + +translate.textdomain("pykickstart") + op = OptionParser(usage="usage: %prog [options] ksfile") op.add_option("-e", "--firsterror", dest="firsterror", action="store_true", - default=False, help="halt after the first error or warning") + default=False, help=_("halt after the first error or warning")) op.add_option("-i", "--followincludes", dest="followincludes", action="store_true", default=False, - help="parse include files when %include is seen") + help=_("parse include files when %include is seen")) (opts, extra) = op.parse_args(sys.argv[1:]) @@ -46,16 +51,16 @@ warnings.filterwarnings("error") try: ksparser.readKickstart(f) except DeprecationWarning, msg: - print "File uses a deprecated option or command.\n%s" % msg + print _("File uses a deprecated option or command.\n%s") % msg os._exit(1) except (KickstartParseError, KickstartValueError), msg: print msg os._exit(1) except KickstartError: - print "General kickstart error in input file" + print _("General kickstart error in input file") os._exit(1) except Exception, e: - print "General error in input file: %s" % e + print _("General error in input file: %s") % e os._exit(1) os._exit(0) -- 2.11.4.GIT