]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
python: Move common i18n code into python module
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 May 2020 10:04:50 +0000 (10:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 May 2020 10:04:50 +0000 (10:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/python/i18n.py [new file with mode: 0644]
src/python/location-downloader.in
src/python/location-exporter.in
src/python/location-query.in

index 6f4a8c969a1fe873a3f6e0310cbeb176b9ea2c1a..c92ee8f8d906de0c5e95bf9a294eb2b500aa2fae 100644 (file)
@@ -154,6 +154,7 @@ CLEANFILES += \
 
 dist_pkgpython_PYTHON = \
        src/python/__init__.py \
+       src/python/i18n.py \
        src/python/logger.py
 
 pyexec_LTLIBRARIES = \
diff --git a/src/python/i18n.py b/src/python/i18n.py
new file mode 100644 (file)
index 0000000..2161aa6
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/python3
+###############################################################################
+#                                                                             #
+# libloc - A library to determine the location of someone on the Internet     #
+#                                                                             #
+# Copyright (C) 2020 IPFire Development Team <info@ipfire.org>                #
+#                                                                             #
+# This library is free software; you can redistribute it and/or               #
+# modify it under the terms of the GNU Lesser General Public                  #
+# License as published by the Free Software Foundation; either                #
+# version 2.1 of the License, or (at your option) any later version.          #
+#                                                                             #
+# This library is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           #
+# Lesser General Public License for more details.                             #
+#                                                                             #
+###############################################################################
+
+import gettext
+
+def _(singular, plural=None, n=None):
+       if plural:
+               return gettext.dngettext("libloc", singular, plural, n)
+
+       return gettext.dgettext("libloc", singular)
index ca64a0d62619ec72f1d0191b51c223f68c8b9f3d..2d38136f9a577789676fb3b57b30b762aa956b25 100644 (file)
@@ -19,7 +19,6 @@
 
 import argparse
 import datetime
-import gettext
 import logging
 import lzma
 import os
@@ -34,6 +33,7 @@ import urllib.request
 
 # Load our location module
 import location
+from location.i18n import _
 
 DATABASE_FILENAME = "test.db.xz"
 MIRRORS = (
@@ -45,14 +45,6 @@ MIRRORS = (
 log = logging.getLogger("location.downloader")
 log.propagate = 1
 
-# i18n
-def _(singular, plural=None, n=None):
-       if plural:
-               return gettext.dngettext("libloc", singular, plural, n)
-
-       return gettext.dgettext("libloc", singular)
-
-
 class Downloader(object):
        def __init__(self, mirrors):
                self.mirrors = list(mirrors)
index 0f7fbae3401124f99b9fef9f1de2b18eecf21236..3e53d4183c5f8e970972fb521e073db589e9e921 100644 (file)
@@ -18,7 +18,6 @@
 ###############################################################################
 
 import argparse
-import gettext
 import io
 import ipaddress
 import logging
@@ -28,18 +27,12 @@ import sys
 
 # Load our location module
 import location
+from location.i18n import _
 
 # Initialise logging
 log = logging.getLogger("location.exporter")
 log.propagate = 1
 
-# i18n
-def _(singular, plural=None, n=None):
-       if plural:
-               return gettext.dngettext("libloc", singular, plural, n)
-
-       return gettext.dgettext("libloc", singular)
-
 class OutputWriter(object):
        suffix = "networks"
 
index 260425546aef5752b098804340f4a6066a6f75b8..4534279e72d6e7da34d565a2c025c824bb5386ec 100644 (file)
@@ -18,7 +18,6 @@
 ###############################################################################
 
 import argparse
-import gettext
 import ipaddress
 import os
 import socket
@@ -26,13 +25,7 @@ import sys
 
 # Load our location module
 import location
-
-# i18n
-def _(singular, plural=None, n=None):
-       if plural:
-               return gettext.dngettext("libloc", singular, plural, n)
-
-       return gettext.dgettext("libloc", singular)
+from location.i18n import _
 
 # Output formatters