[blivet f20/master 3/5] Added a i18n module for gettext functions.
David Shea
dshea at redhat.com
Thu Nov 21 20:33:00 UTC 2013
This keeps the gettext function definitions all in one place, and makes
it easier for other software to import blivet.i18n to get
blivet-specific translation functions.
Removed unused translation functions.
---
blivet/__init__.py | 4 +---
blivet/dasd.py | 5 +----
blivet/deviceaction.py | 4 +---
blivet/devicefactory.py | 3 ---
blivet/devicelibs/btrfs.py | 3 ---
blivet/devicelibs/crypto.py | 3 ---
blivet/devicelibs/dm.py | 3 ---
blivet/devicelibs/loop.py | 3 ---
blivet/devicelibs/lvm.py | 4 +---
blivet/devicelibs/mdraid.py | 3 ---
blivet/devicelibs/swap.py | 3 ---
blivet/devices.py | 5 +----
blivet/devicetree.py | 3 ---
blivet/fcoe.py | 4 +---
blivet/formats/__init__.py | 4 +---
blivet/formats/disklabel.py | 3 ---
blivet/formats/dmraid.py | 3 ---
blivet/formats/fs.py | 4 +---
blivet/formats/luks.py | 4 +---
blivet/formats/lvmpv.py | 3 ---
blivet/formats/mdraid.py | 3 ---
blivet/formats/multipath.py | 3 ---
blivet/formats/swap.py | 3 ---
blivet/i18n.py | 28 ++++++++++++++++++++++++++++
blivet/iscsi.py | 4 +---
blivet/partitioning.py | 4 +---
blivet/platform.py | 5 +----
blivet/size.py | 5 +----
blivet/zfcp.py | 4 +---
29 files changed, 42 insertions(+), 88 deletions(-)
create mode 100644 blivet/i18n.py
diff --git a/blivet/__init__.py b/blivet/__init__.py
index 327389b..a175cca 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -86,13 +86,11 @@ import arch
from flags import flags
from platform import platform as _platform
from size import Size, xlate_size
+from i18n import _
import shelve
import contextlib
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/dasd.py b/blivet/dasd.py
index c2ec2e4..12cfaa7 100644
--- a/blivet/dasd.py
+++ b/blivet/dasd.py
@@ -26,14 +26,11 @@ from .devices import deviceNameToDiskByPath
from . import util
from . import arch
from .udev import udev_trigger
+from .i18n import P_
import logging
log = logging.getLogger("blivet")
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-P_ = lambda x, y, z: gettext.ldngettext("blivet", x, y, z)
-
def getDasdPorts():
""" Return comma delimited string of valid DASD ports. """
ports = []
diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index a53fdb5..8664bbe 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -30,9 +30,7 @@ from devices import LVMLogicalVolumeDevice
from formats import getFormat
from errors import *
from parted import partitionFlag, PARTITION_LBA
-
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
+from i18n import _
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py
index 4c95709..134e1ee 100644
--- a/blivet/devicefactory.py
+++ b/blivet/devicefactory.py
@@ -35,9 +35,6 @@ from .partitioning import SameSizeSet
from .partitioning import TotalSizeSet
from .partitioning import doPartitioning
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/devicelibs/btrfs.py b/blivet/devicelibs/btrfs.py
index 2f0cee4..5d623e2 100644
--- a/blivet/devicelibs/btrfs.py
+++ b/blivet/devicelibs/btrfs.py
@@ -26,9 +26,6 @@ import re
from .. import util
from ..errors import *
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/devicelibs/crypto.py b/blivet/devicelibs/crypto.py
index bdb6645..bc1e45d 100644
--- a/blivet/devicelibs/crypto.py
+++ b/blivet/devicelibs/crypto.py
@@ -25,9 +25,6 @@ from pycryptsetup import CryptSetup
from ..errors import *
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
LUKS_METADATA_SIZE = 2.0 # MB
# Keep the character set size a power of two to make sure all characters are
diff --git a/blivet/devicelibs/dm.py b/blivet/devicelibs/dm.py
index 382b931..a64016b 100644
--- a/blivet/devicelibs/dm.py
+++ b/blivet/devicelibs/dm.py
@@ -26,9 +26,6 @@ import block
from .. import util
from ..errors import *
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/devicelibs/loop.py b/blivet/devicelibs/loop.py
index acaa61c..d67b508 100644
--- a/blivet/devicelibs/loop.py
+++ b/blivet/devicelibs/loop.py
@@ -25,9 +25,6 @@ import os
from .. import util
from ..errors import *
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
index 5bc189c..0f96c9d 100644
--- a/blivet/devicelibs/lvm.py
+++ b/blivet/devicelibs/lvm.py
@@ -30,9 +30,7 @@ log = logging.getLogger("blivet")
from .. import util
from .. import arch
from ..errors import *
-
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
+from ..i18n import _
MAX_LV_SLOTS = 256
diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
index 9c827e1..150dd8a 100644
--- a/blivet/devicelibs/mdraid.py
+++ b/blivet/devicelibs/mdraid.py
@@ -25,9 +25,6 @@ import os
from .. import util
from ..errors import *
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/devicelibs/swap.py b/blivet/devicelibs/swap.py
index 99ca3ca..31f86f3 100644
--- a/blivet/devicelibs/swap.py
+++ b/blivet/devicelibs/swap.py
@@ -27,9 +27,6 @@ from ..errors import *
from .. import util
from . import dm
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/devices.py b/blivet/devices.py
index 54ece22..720ec24 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -117,10 +117,7 @@ from flags import flags
from storage_log import log_method_call
from udev import *
from formats import get_device_format_class, getFormat, DeviceFormat
-
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-P_ = lambda x, y, z: gettext.ldngettext("blivet", x, y, z)
+from i18n import P_
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index bad135c..52e9782 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -48,9 +48,6 @@ from storage_log import log_method_call, log_method_return
import parted
import _ped
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/fcoe.py b/blivet/fcoe.py
index 4bbd8c3..6429085 100644
--- a/blivet/fcoe.py
+++ b/blivet/fcoe.py
@@ -23,11 +23,9 @@ from .udev import udev_settle
#from pyanaconda import isys
import logging
import time
+from .i18n import _
log = logging.getLogger("blivet")
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
_fcoe_module_loaded = False
def has_fcoe():
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index 67ac996..a24a11c 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -31,9 +31,7 @@ from ..errors import *
from ..devicelibs.dm import dm_node_from_name
from ..devicelibs.mdraid import md_node_from_name
from ..udev import udev_device_get_major, udev_device_get_minor
-
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
+from ..i18n import _
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index 90b73f3..5c821b8 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -32,9 +32,6 @@ from ..flags import flags
from ..udev import udev_settle
from . import DeviceFormat, register_device_format
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/formats/dmraid.py b/blivet/formats/dmraid.py
index 2bf4567..35bc1b7 100644
--- a/blivet/formats/dmraid.py
+++ b/blivet/formats/dmraid.py
@@ -25,9 +25,6 @@ from ..flags import flags
from ..errors import *
from . import DeviceFormat, register_device_format
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 56bd445..e9bc58b 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -36,13 +36,11 @@ from ..flags import flags
from parted import fileSystemType
from ..storage_log import log_method_call
from .. import arch
+from ..i18n import _
import logging
log = logging.getLogger("blivet")
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
try:
lost_and_found_context = selinux.matchpathcon("/lost+found", 0)[1]
except OSError:
diff --git a/blivet/formats/luks.py b/blivet/formats/luks.py
index 0c4b25b..dc54188 100644
--- a/blivet/formats/luks.py
+++ b/blivet/formats/luks.py
@@ -34,9 +34,7 @@ from ..errors import *
from ..devicelibs import crypto
from . import DeviceFormat, register_device_format
from ..flags import flags
-
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
+from ..i18n import _
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
index 4111ad0..ccf2c12 100644
--- a/blivet/formats/lvmpv.py
+++ b/blivet/formats/lvmpv.py
@@ -28,9 +28,6 @@ from ..errors import *
from ..devicelibs import lvm
from . import DeviceFormat, register_device_format
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/formats/mdraid.py b/blivet/formats/mdraid.py
index 44d111e..9112ed0 100644
--- a/blivet/formats/mdraid.py
+++ b/blivet/formats/mdraid.py
@@ -29,9 +29,6 @@ from ..devicelibs import mdraid
from . import DeviceFormat, register_device_format
from ..flags import flags
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/formats/multipath.py b/blivet/formats/multipath.py
index 4102cb0..2d6a5f3 100644
--- a/blivet/formats/multipath.py
+++ b/blivet/formats/multipath.py
@@ -28,9 +28,6 @@ from ..storage_log import log_method_call
from ..errors import *
from . import DeviceFormat, register_device_format
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py
index da8f4df..72ca84f 100644
--- a/blivet/formats/swap.py
+++ b/blivet/formats/swap.py
@@ -27,9 +27,6 @@ from ..util import numeric_type
from ..devicelibs import swap
from . import DeviceFormat, register_device_format
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/i18n.py b/blivet/i18n.py
new file mode 100644
index 0000000..8aca12e
--- /dev/null
+++ b/blivet/i18n.py
@@ -0,0 +1,28 @@
+# i18n.py
+# Internationalization functions
+#
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details. You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): David Shea <dshea at redhat.com>
+
+__all__ = ["_", "N_", "P_"]
+
+import gettext
+
+_ = lambda x: gettext.ldgettext("blivet", x)
+N_ = lambda x: x
+P_ = lambda x, y, z: gettext.ldngettext("blivet", x, y, z)
diff --git a/blivet/iscsi.py b/blivet/iscsi.py
index fceb881..45a0ac8 100644
--- a/blivet/iscsi.py
+++ b/blivet/iscsi.py
@@ -21,6 +21,7 @@
from udev import udev_settle
from . import util
from .flags import flags
+from .i18n import _
import os
import logging
import shutil
@@ -28,9 +29,6 @@ import time
import itertools
log = logging.getLogger("blivet")
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-
has_libiscsi = True
try:
import libiscsi
diff --git a/blivet/partitioning.py b/blivet/partitioning.py
index 1109ead..4216be2 100644
--- a/blivet/partitioning.py
+++ b/blivet/partitioning.py
@@ -33,9 +33,7 @@ from flags import flags
from devices import PartitionDevice, LUKSDevice, devicePathToName
from formats import getFormat
from devicelibs.lvm import get_pool_padding
-
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
+from i18n import _
import logging
log = logging.getLogger("blivet")
diff --git a/blivet/platform.py b/blivet/platform.py
index b6e8bb0..3ccc2be 100644
--- a/blivet/platform.py
+++ b/blivet/platform.py
@@ -28,10 +28,7 @@ import parted
from . import arch
from .flags import flags
from .partspec import PartSpec
-
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-N_ = lambda x: x
+from .i18n import N_
class Platform(object):
"""Platform
diff --git a/blivet/size.py b/blivet/size.py
index 7c03c2e..6d3dfbd 100644
--- a/blivet/size.py
+++ b/blivet/size.py
@@ -25,10 +25,7 @@ from decimal import Decimal
from decimal import InvalidOperation
from errors import *
-
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
-P_ = lambda x, y, z: gettext.ldngettext("blivet", x, y, z)
+from i18n import _, P_
# Decimal prefixes for different size increments, along with the name
# and accepted abbreviation for the prefix. These prefixes are all
diff --git a/blivet/zfcp.py b/blivet/zfcp.py
index cf8ec40..1c31820 100644
--- a/blivet/zfcp.py
+++ b/blivet/zfcp.py
@@ -23,9 +23,7 @@ import string
import os
from udev import udev_settle
from . import util
-
-import gettext
-_ = lambda x: gettext.ldgettext("blivet", x)
+from .i18n import _
import logging
log = logging.getLogger("blivet")
--
1.8.4.2
More information about the anaconda-patches
mailing list