]> Frank Brehm's Git Trees - my-stuff/py-logrotate.git/commitdiff
gettext-Dinge zu Internationalisierung dazu
authorFrank Brehm <frank@brehm-online.com>
Tue, 19 Apr 2011 10:29:55 +0000 (10:29 +0000)
committerFrank Brehm <frank@brehm-online.com>
Tue, 19 Apr 2011 10:29:55 +0000 (10:29 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@203 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

LogRotateGetopts.py
logrotate.py
po/LogRotateGetopts.de.po [new file with mode: 0644]
po/LogRotateGetopts.pot [new file with mode: 0644]
po/Makefile [new file with mode: 0644]
po/pylogrotate.de.po [new file with mode: 0644]
po/pylogrotate.pot [new file with mode: 0644]

index 95dfc06199abe3b91f2c32a780e42d0fdc83a5c1..fc67766f50a65c9fd14c8e6a0a1ee1bd34e89cd5 100755 (executable)
@@ -15,6 +15,7 @@
 
 import re
 import sys
+import gettext
 
 from optparse import OptionError
 from optparse import OptionParser
@@ -55,13 +56,20 @@ class LogrotateOptParser(object):
     #-------------------------------------------------------
     def __init__( self, prog = '%prog',
                         version = None,
+                        local_dir = None,
     ):
         '''
         Costructor.
-        @param prog: The name of the calling process (e.g. sys.argv[0])
-        @type prog: str
-        @param version: The version string to use
-        @type version: str
+
+        @param prog:      The name of the calling process (e.g. sys.argv[0])
+        @type prog:       str
+        @param version:   The version string to use
+        @type version:    str
+        @param local_dir: The directory, where the i18n-files (*.mo)
+                          are located. If None, then system default
+                          (/usr/share/locale) is used.
+        @type local_dir:  str or None
+
         @return: None
         '''
 
@@ -77,13 +85,31 @@ class LogrotateOptParser(object):
         @type: str
         '''
 
-        self.description = 'Rotates and compresses system logs.'
+        self.local_dir = local_dir
+        '''
+        @ivar: The directory, where the i18n-files (*.mo) are located.
+        @type: str or None
+        '''
+
+        self.t = gettext.translation(
+            'LogRotateGetopts',
+            local_dir,
+            fallback = True
+        )
+        '''
+        @ivar: a gettext translation object
+        @type: gettext.translation
+        '''
+
+        _ = self.t.lgettext
+
+        self.description = _('Rotates, compresses and mails system logs.')
         '''
         @ivar: description of the program
         @type: str
         '''
 
-        self.usage = "Usage: %s [options] <configfile>\n" %(prog)
+        self.usage = ( _("%s [options] <configfile>") + "\n" ) %(prog)
         '''
         @ivar: the usage string in getopt help output
         @type: str
@@ -135,6 +161,9 @@ class LogrotateOptParser(object):
         to the OptionParser object
         '''
 
+        _ = self.t.ugettext
+        __ = self.t.ungettext
+
         if self.parser.has_option('--help'):
             self.parser.remove_option('--help')
 
@@ -148,7 +177,7 @@ class LogrotateOptParser(object):
             default = False,
             action  = 'store_true',
             dest    = 'test',
-            help    = 'set this do simulate commands'
+            help    = _('set this do simulate commands'),
         )
 
         self.parser.add_option(
@@ -157,7 +186,7 @@ class LogrotateOptParser(object):
             default = False,
             action  = 'count',
             dest    = 'verbose',
-            help    = 'set the verbosity level'
+            help    = _('set the verbosity level'),
         )
 
         self.parser.add_option(
@@ -166,7 +195,7 @@ class LogrotateOptParser(object):
             default = False,
             action  = 'store_true',
             dest    = 'debug',
-            help    = "Don't do anything, just test (implies -v and -T)"
+            help    = _("Don't do anything, just test (implies -v and -T)"),
         )
 
         self.parser.add_option(
@@ -175,7 +204,7 @@ class LogrotateOptParser(object):
             default = False,
             action  = 'store_true',
             dest    = 'force',
-            help    = "Force file rotation"
+            help    = _("Force file rotation"),
         )
 
         self.parser.add_option(
@@ -184,8 +213,8 @@ class LogrotateOptParser(object):
             default = False,
             action  = 'store_true',
             dest    = 'configcheck',
-            help    = "Checks only the given configuration file and does "
-                      + "nothing. Conflicts with -f",
+            help    = _("Checks only the given configuration file and does "
+                      + "nothing. Conflicts with -f."),
         )
 
         self.parser.add_option(
@@ -193,29 +222,22 @@ class LogrotateOptParser(object):
             '-s',
             dest    = "statefile",
             metavar = 'FILE',
-            help    = 'Path of state file (different to configuration)',
+            help    = _('Path of state file (different to configuration)'),
         )
 
-        ######
-        # Deprecated options for compatibilty to logrotate
-        group = OptionGroup(self.parser, "Deprecated options")
-
-        group.add_option(
+        self.parser.add_option(
             '--mail',
             '-m',
             dest    = "mailcmd",
             metavar = 'CMD',
-            help    = ( ( 'Should tell %s which command to use '
-                        + 'when mailing logs - not used.' )
-                        %(str(self.prog)) ),
+            help    = _('Command to send mail (instead of using '
+                        + 'the Phyton email package)'),
         )
 
-        self.parser.add_option_group(group)
-
         ######
         # Option group for common options
 
-        group = OptionGroup(self.parser, "Common options")
+        group = OptionGroup(self.parser, _("Common options"))
 
         group.add_option(
             '-h',
@@ -224,7 +246,7 @@ class LogrotateOptParser(object):
             default = False,
             action  = 'help',
             dest    = 'help',
-            help    = 'shows a help message and exit'
+            help    = _('Shows a help message and exit.'),
         )
 
         group.add_option(
@@ -232,7 +254,7 @@ class LogrotateOptParser(object):
             default = False,
             action  = 'store_true',
             dest    = 'usage',
-            help    = 'Display brief usage message and exit'
+            help    = _('Display brief usage message and exit.'),
         )
 
         group.add_option(
@@ -241,7 +263,7 @@ class LogrotateOptParser(object):
             default = False,
             action  = 'version',
             dest    = 'version',
-            help    = 'shows the version number of the program and exit',
+            help    = _('Shows the version number of the program and exit.'),
         )
 
         self.parser.add_option_group(group)
@@ -254,6 +276,8 @@ class LogrotateOptParser(object):
         @return: None
         '''
 
+        _ = self.t.ugettext
+
         if not self.parsed:
             self.options, self.args = self.parser.parse_args()
             self.parsed = True
@@ -263,23 +287,21 @@ class LogrotateOptParser(object):
             sys.exit(0)
 
         if self.options.force and self.options.configcheck:
-            raise LogrotateOptParserError('Invalid usage of --force and '
-                + '--config-check.')
+            raise LogrotateOptParserError( _('Invalid usage of --force and '
+                + '--config-check.') )
 
-        if self.args is None:
-            raise LogrotateOptParserError('No configuration file given.')
+        if self.args is None or len(self.args) < 1:
+            raise LogrotateOptParserError( _('No configuration file given.') )
 
         if len(self.args) != 1:
-            raise LogrotateOptParserError('Only one configuration file is allowed.')
-
-        if self.options.mailcmd:
-            sys.stderr.write('Usage of --mail is deprecated '
-                + 'in this version.\n\n')
+            raise LogrotateOptParserError(
+                _('Only one configuration file is allowed.')
+            )
 
 #========================================================================
 
 if __name__ == "__main__":
-    main()
+    pass
 
 
 #========================================================================
index 4a9a183d751b5cde939779f59f2ebffd1b7b45c6..7f6387df58a7576bb7789972fcc0791f30fb4ee4 100755 (executable)
@@ -9,7 +9,7 @@
 @contact: frank@brehm-online.com
 @license: GPL3
 @copyright: (c) 2010-2011 by Frank Brehm, Berlin
-@version: 0.1.0
+@version: 0.2.0
 @summary: rotates and compress system logs
 '''
 
@@ -19,8 +19,8 @@ import pprint
 import gettext
 import os.path
 
-from LogRotateGetopts import LogrotateOptParser;
-from LogRotateGetopts import LogrotateOptParserError;
+from LogRotateGetopts import LogrotateOptParser
+from LogRotateGetopts import LogrotateOptParserError
 
 revision = '$Revision$'
 revision = re.sub( r'\$', '', revision )
@@ -29,7 +29,7 @@ revision = re.sub( r'Revision: ', r'r', revision )
 __author__    = 'Frank Brehm'
 __copyright__ = '(C) 2011 by Frank Brehm, Berlin'
 __contact__    = 'frank@brehm-online.com'
-__version__    = '0.1.0 ' + revision
+__version__    = '0.2.0 ' + revision
 __license__    = 'GPL3'
 
 
@@ -38,10 +38,19 @@ def main():
 
     basedir = os.path.realpath(os.path.dirname(sys.argv[0]))
     #print "Basedir: %s" % ( basedir )
+    local_dir = os.path.join(basedir, 'po')
+    if not os.path.isdir(local_dir):
+        local_dir = None
+    #print "Locale-Dir: %s" % ( local_dir )
+
+    t = gettext.translation('pylogrotate', local_dir, fallback=True)
+    _ = t.lgettext
+    __ = t.lngettext
 
     opt_parser = LogrotateOptParser(
-        prog = "logrotate",
-        version = __version__,
+        prog      = "logrotate",
+        version   = __version__,
+        local_dir = local_dir,
     )
     pp = pprint.PrettyPrinter(indent=4)
     try:
@@ -51,8 +60,8 @@ def main():
         opt_parser.parser.print_help(sys.stderr)
         sys.exit(1)
 
-    print "Options: " + pp.pformat(opt_parser.options)
-    print "Arguments: " + pp.pformat(opt_parser.args)
+    print _("Options") + ": " + pp.pformat(opt_parser.options)
+    print _("Arguments") + ": " + pp.pformat(opt_parser.args)
 
 
 #========================================================================
diff --git a/po/LogRotateGetopts.de.po b/po/LogRotateGetopts.de.po
new file mode 100644 (file)
index 0000000..bdd5154
--- /dev/null
@@ -0,0 +1,89 @@
+# German translations for pylogrotate package
+# German messages for pylogrotate.
+# Copyright (C) 2011 THE pylogrotate'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the pylogrotate package.
+# Frank Brehm <frank@brehm-online.com>, 2011.
+#
+# $Id$
+# $URL$
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: LogRotateGetopts 0.2\n"
+"Report-Msgid-Bugs-To: Frank Brehm <frank@brehm-online.com>\n"
+"POT-Creation-Date: 2011-04-18 18:40+0200\n"
+"PO-Revision-Date: 2011-04-19 10:53+0200\n"
+"Last-Translator: Frank Brehm <frank@brehm-online.com>\n"
+"Language-Team: German\n"
+"Language: de\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: LogRotateGetopts.py:106
+msgid "Rotates, compresses and mails system logs."
+msgstr "Rotiert, komprimiert und versended Systemlogdateien per Mail"
+
+#: LogRotateGetopts.py:112
+#, python-format
+msgid "%s [options] <configfile>"
+msgstr "%s [Optionen] <Konfigurationsdatei>"
+
+#: LogRotateGetopts.py:180
+msgid "set this do simulate commands"
+msgstr "Testmodus, Kommandos werden nur simuliert"
+
+#: LogRotateGetopts.py:189
+msgid "set the verbosity level"
+msgstr "bestimmt das Ausführlichkeits-Niveau"
+
+#: LogRotateGetopts.py:198
+msgid "Don't do anything, just test (implies -v and -T)"
+msgstr "Testmodus, Kommandos werden nur simuliert (beinhaltet -v und -T)"
+
+#: LogRotateGetopts.py:207
+msgid "Force file rotation"
+msgstr "Erzwingt Logratation"
+
+#: LogRotateGetopts.py:216
+msgid "Checks only the given configuration file and does nothing. Conflicts with -f."
+msgstr "Überprüft nur die gegebene Konfigurationsdatei und führt nichts aus. Beißt sich mit -f."
+
+#: LogRotateGetopts.py:225
+msgid "Path of state file (different to configuration)"
+msgstr "Pfad zur Statusdatei (im Unterschied zur Konfiguration)"
+
+#: LogRotateGetopts.py:233
+msgid "Command to send mail (instead of using the Phyton email package)"
+msgstr "Befehl zum Mailversand (anstelle der Verwendung des Python email-Paketes"
+
+#. #####
+#. Option group for common options
+#: LogRotateGetopts.py:240
+msgid "Common options"
+msgstr "Allgemeine Optionen"
+
+#: LogRotateGetopts.py:249
+msgid "Shows a help message and exit."
+msgstr "Zeigt einen Hilfetext und beendet sich."
+
+#: LogRotateGetopts.py:257
+msgid "Display brief usage message and exit."
+msgstr "Zeigt einen kurzen Text zur Verwendung und beendet sich."
+
+#: LogRotateGetopts.py:266
+msgid "Shows the version number of the program and exit."
+msgstr "Zeigt die Versionsnummer des Programms und beendet sich."
+
+#: LogRotateGetopts.py:290
+msgid "Invalid usage of --force and --config-check."
+msgstr "Ungültige Verwendung von --force und --config-check."
+
+#: LogRotateGetopts.py:294
+msgid "No configuration file given."
+msgstr "Keine Konfigurationsdatei angegeben."
+
+#: LogRotateGetopts.py:298
+msgid "Only one configuration file is allowed."
+msgstr "Es ist nur die Angabe einer Konfigurationsdatei erlaubt."
diff --git a/po/LogRotateGetopts.pot b/po/LogRotateGetopts.pot
new file mode 100644 (file)
index 0000000..4566eba
--- /dev/null
@@ -0,0 +1,88 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the pylogrotate package.
+# Frank Brehm <frank@brehm-online.com>, 2011.
+#
+# $Id: $
+# $URL: $
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: pylogrotate 0.2\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-04-18 18:40+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: LogRotateGetopts.py:106
+msgid "Rotates, compresses and mails system logs."
+msgstr ""
+
+#: LogRotateGetopts.py:112
+#, python-format
+msgid "%s [options] <configfile>"
+msgstr ""
+
+#: LogRotateGetopts.py:180
+msgid "set this do simulate commands"
+msgstr ""
+
+#: LogRotateGetopts.py:189
+msgid "set the verbosity level"
+msgstr ""
+
+#: LogRotateGetopts.py:198
+msgid "Don't do anything, just test (implies -v and -T)"
+msgstr ""
+
+#: LogRotateGetopts.py:207
+msgid "Force file rotation"
+msgstr ""
+
+#: LogRotateGetopts.py:216
+msgid "Checks only the given configuration file and does nothing. Conflicts with -f."
+msgstr ""
+
+#: LogRotateGetopts.py:225
+msgid "Path of state file (different to configuration)"
+msgstr ""
+
+#: LogRotateGetopts.py:233
+msgid "Command to send mail (instead of using the Phyton email package)"
+msgstr ""
+
+#. #####
+#. Option group for common options
+#: LogRotateGetopts.py:240
+msgid "Common options"
+msgstr ""
+
+#: LogRotateGetopts.py:249
+msgid "Shows a help message and exit."
+msgstr ""
+
+#: LogRotateGetopts.py:257
+msgid "Display brief usage message and exit."
+msgstr ""
+
+#: LogRotateGetopts.py:266
+msgid "Shows the version number of the program and exit."
+msgstr ""
+
+#: LogRotateGetopts.py:290
+msgid "Invalid usage of --force and --config-check."
+msgstr ""
+
+#: LogRotateGetopts.py:294
+msgid "No configuration file given."
+msgstr ""
+
+#: LogRotateGetopts.py:298
+msgid "Only one configuration file is allowed."
+msgstr ""
diff --git a/po/Makefile b/po/Makefile
new file mode 100644 (file)
index 0000000..330572c
--- /dev/null
@@ -0,0 +1,23 @@
+#
+# Makefile for i18n-Objects in PyLogrotate
+#
+# $Id$
+# $URL$
+#
+
+all: pylogrotate.de.mo LogRotateGetopts.de.mo
+
+pylogrotate.de.mo: pylogrotate.de.po
+       @echo
+       @echo "Compiling $@ ..."
+       msgfmt -o pylogrotate.de.mo --check -v pylogrotate.de.po
+       @if [ ! -d de_DE/LC_MESSAGES ] ; then mkdir -vp de_DE/LC_MESSAGES; fi
+       @cp -pv pylogrotate.de.mo de_DE/LC_MESSAGES/pylogrotate.mo
+
+LogRotateGetopts.de.mo: LogRotateGetopts.de.po
+       @echo
+       @echo "Compiling $@ ..."
+       msgfmt -o LogRotateGetopts.de.mo --check -v LogRotateGetopts.de.po
+       @if [ ! -d de_DE/LC_MESSAGES ] ; then mkdir -vp de_DE/LC_MESSAGES; fi
+       @cp -pv LogRotateGetopts.de.mo de_DE/LC_MESSAGES/LogRotateGetopts.mo
+
diff --git a/po/pylogrotate.de.po b/po/pylogrotate.de.po
new file mode 100644 (file)
index 0000000..623dda7
--- /dev/null
@@ -0,0 +1,29 @@
+# German translations for pylogrotate package.
+# Copyright (C) 2011 THE pylogrotate'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the pylogrotate package.
+# Frank Brehm <frank@brehm-online.com>, 2011.
+#
+# $Id$
+# $URL$
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: pylogrotate 0.2\n"
+"Report-Msgid-Bugs-To: Frank Brehm <frank@brehm-online.com>\n"
+"POT-Creation-Date: 2011-04-18 18:35+0200\n"
+"PO-Revision-Date: 2011-04-18 21:10+0200\n"
+"Last-Translator: Frank Brehm <frank@brehm-online.com>\n"
+"Language-Team: German\n"
+"Language: de\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: logrotate.py:54
+msgid "Options"
+msgstr "Optionen"
+
+#: logrotate.py:55
+msgid "Arguments"
+msgstr "Argumente"
diff --git a/po/pylogrotate.pot b/po/pylogrotate.pot
new file mode 100644 (file)
index 0000000..216a46f
--- /dev/null
@@ -0,0 +1,29 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the pylogrotate package.
+# Frank Brehm <frank@brehm-online.com>, 2011.
+#
+# $Id: $
+# $URL: $
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-04-18 18:35+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: logrotate.py:54
+msgid "Options"
+msgstr ""
+
+#: logrotate.py:55
+msgid "Arguments"
+msgstr ""