For strings initialized at the class or module level, mark them as translatable but don't translate until they are used. --- blivet/deviceaction.py | 20 +++++++++++------- blivet/formats/__init__.py | 6 +++--- blivet/formats/disklabel.py | 3 ++- blivet/formats/fs.py | 20 +++++++++--------- blivet/formats/luks.py | 9 ++++---- blivet/platform.py | 4 ++-- blivet/size.py | 51 +++++++++++++++++++++++++-------------------- 7 files changed, 61 insertions(+), 52 deletions(-)
diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py index 8664bbe..275a6fe 100644 --- a/blivet/deviceaction.py +++ b/blivet/deviceaction.py @@ -30,7 +30,7 @@ from devices import LVMLogicalVolumeDevice from formats import getFormat from errors import * from parted import partitionFlag, PARTITION_LBA -from i18n import _ +from i18n import _, N_
import logging log = logging.getLogger("blivet") @@ -144,7 +144,7 @@ class DeviceAction(object): """ type = ACTION_TYPE_NONE obj = ACTION_OBJECT_NONE - typeDesc = "" + typeDescStr = "" _id = 0
def __init__(self, device): @@ -227,6 +227,10 @@ class DeviceAction(object):
return s
+ @property + def typeDesc(self): + return _(self.typeDescStr) + def __str__(self): s = "[%d] %s %s" % (self.id, self.typeString, self.objectString) if self.isResize: @@ -257,7 +261,7 @@ class ActionCreateDevice(DeviceAction): """ Action representing the creation of a new device. """ type = ACTION_TYPE_CREATE obj = ACTION_OBJECT_DEVICE - typeDesc = _("create device") + typeDescStr = N_("create device")
def __init__(self, device): if device.exists: @@ -304,7 +308,7 @@ class ActionDestroyDevice(DeviceAction): """ An action representing the deletion of an existing device. """ type = ACTION_TYPE_DESTROY obj = ACTION_OBJECT_DEVICE - typeDesc = _("destroy device") + typeDescStr = N_("destroy device")
def __init__(self, device): # XXX should we insist that device.fs be None? @@ -376,7 +380,7 @@ class ActionResizeDevice(DeviceAction): """ An action representing the resizing of an existing device. """ type = ACTION_TYPE_RESIZE obj = ACTION_OBJECT_DEVICE - typeDesc = _("resize device") + typeDescStr = N_("resize device")
def __init__(self, device, newsize): if not device.resizable: @@ -433,7 +437,7 @@ class ActionCreateFormat(DeviceAction): """ An action representing creation of a new filesystem. """ type = ACTION_TYPE_CREATE obj = ACTION_OBJECT_FORMAT - typeDesc = _("create format") + typeDescStr = N_("create format")
def __init__(self, device, format=None): DeviceAction.__init__(self, device) @@ -516,7 +520,7 @@ class ActionDestroyFormat(DeviceAction): """ An action representing the removal of an existing filesystem. """ type = ACTION_TYPE_DESTROY obj = ACTION_OBJECT_FORMAT - typeDesc = _("destroy format") + typeDescStr = N_("destroy format")
def __init__(self, device): DeviceAction.__init__(self, device) @@ -575,7 +579,7 @@ class ActionResizeFormat(DeviceAction): """ type = ACTION_TYPE_RESIZE obj = ACTION_OBJECT_FORMAT - typeDesc = _("resize format") + typeDescStr = N_("resize format")
def __init__(self, device, newsize): if not device.format.resizable: diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py index a24a11c..e340f76 100644 --- a/blivet/formats/__init__.py +++ b/blivet/formats/__init__.py @@ -31,7 +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 -from ..i18n import _ +from ..i18n import _, N_
import logging log = logging.getLogger("blivet") @@ -143,7 +143,7 @@ def get_device_format_class(fmt_type): class DeviceFormat(object): """ Generic device format. """ _type = None - _name = _("Unknown") + _name = N_("Unknown") _udevTypes = [] partedFlag = None partedSystem = None @@ -238,7 +238,7 @@ class DeviceFormat(object): @property def name(self): if self._name: - name = self._name + name = _(self._name) else: name = self.type return name diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py index 5c821b8..a79f0a0 100644 --- a/blivet/formats/disklabel.py +++ b/blivet/formats/disklabel.py @@ -30,6 +30,7 @@ from ..errors import * from .. import arch from ..flags import flags from ..udev import udev_settle +from ..i18n import _ from . import DeviceFormat, register_device_format
import logging @@ -212,7 +213,7 @@ class DiskLabel(DeviceFormat):
@property def name(self): - return "%s (%s)" % (self._name, self.labelType.upper()) + return "%s (%s)" % (_(self._name), self.labelType.upper())
@property def size(self): diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py index e9bc58b..43f9d44 100644 --- a/blivet/formats/fs.py +++ b/blivet/formats/fs.py @@ -36,7 +36,7 @@ from ..flags import flags from parted import fileSystemType from ..storage_log import log_method_call from .. import arch -from ..i18n import _ +from ..i18n import _, N_
import logging log = logging.getLogger("blivet") @@ -820,11 +820,11 @@ class Ext2FS(FS): _resizefs = "resize2fs" _labelfs = "e2label" _fsck = "e2fsck" - _fsckErrors = {4: _("File system errors left uncorrected."), - 8: _("Operational error."), - 16: _("Usage or syntax error."), - 32: _("e2fsck cancelled by user request."), - 128: _("Shared library error.")} + _fsckErrors = {4: N_("File system errors left uncorrected."), + 8: N_("Operational error."), + 16: N_("Usage or syntax error."), + 32: N_("e2fsck cancelled by user request."), + 128: N_("Shared library error.")} _packages = ["e2fsprogs"] _formattable = True _supported = True @@ -859,7 +859,7 @@ class Ext2FS(FS):
for errorCode in self._fsckErrors.keys(): if rc & errorCode: - msg += "\n" + self._fsckErrors[errorCode] + msg += "\n" + _(self._fsckErrors[errorCode])
return msg.strip()
@@ -984,9 +984,9 @@ class FATFS(FS): _modules = ["vfat"] _labelfs = "dosfslabel" _fsck = "dosfsck" - _fsckErrors = {1: _("Recoverable errors have been detected or dosfsck has " + _fsckErrors = {1: N_("Recoverable errors have been detected or dosfsck has " "discovered an internal inconsistency."), - 2: _("Usage error.")} + 2: N_("Usage error.")} _supported = True _formattable = True _maxSize = 1024 * 1024 @@ -1001,7 +1001,7 @@ class FATFS(FS): return False
def _fsckErrorMessage(self, rc): - return self._fsckErrors[rc] + return _(self._fsckErrors[rc])
register_device_format(FATFS)
diff --git a/blivet/formats/luks.py b/blivet/formats/luks.py index dc54188..0f1889e 100644 --- a/blivet/formats/luks.py +++ b/blivet/formats/luks.py @@ -34,7 +34,7 @@ from ..errors import * from ..devicelibs import crypto from . import DeviceFormat, register_device_format from ..flags import flags -from ..i18n import _ +from ..i18n import _, N_
import logging log = logging.getLogger("blivet") @@ -44,7 +44,7 @@ class LUKS(DeviceFormat): """ A LUKS device. """ _type = "luks" _name = "LUKS" - _lockedName = _("Encrypted") + _lockedName = N_("Encrypted") _udevTypes = ["crypto_LUKS"] _formattable = True # can be formatted _supported = False # is supported @@ -117,12 +117,11 @@ class LUKS(DeviceFormat):
@property def name(self): - name = self._name # for existing locked devices, show "Encrypted" instead of LUKS if self.hasKey or not self.exists: - name = self._name + name = _(self._name) else: - name = "%s (%s)" % (self._lockedName, self._name) + name = "%s (%s)" % (_(self._lockedName), _(self._name)) return name
def _setPassphrase(self, passphrase): diff --git a/blivet/platform.py b/blivet/platform.py index 3ccc2be..31c4f50 100644 --- a/blivet/platform.py +++ b/blivet/platform.py @@ -28,7 +28,7 @@ import parted from . import arch from .flags import flags from .partspec import PartSpec -from .i18n import N_ +from .i18n import _, N_
class Platform(object): """Platform @@ -89,7 +89,7 @@ class Platform(object): "raid_levels": self._boot_stage1_raid_levels, "raid_metadata": self._boot_stage1_raid_metadata, "raid_member_types": self._boot_stage1_raid_member_types, - "descriptions": self._boot_descriptions} + "descriptions": {k: _(v) for k, v in self._boot_descriptions.items()}} return d
def requiredDiskLabelType(self, device_type): diff --git a/blivet/size.py b/blivet/size.py index 6d3dfbd..eaeef77 100644 --- a/blivet/size.py +++ b/blivet/size.py @@ -25,32 +25,32 @@ from decimal import Decimal from decimal import InvalidOperation
from errors import * -from i18n import _, P_ +from i18n import _, P_, N_
# Decimal prefixes for different size increments, along with the name # and accepted abbreviation for the prefix. These prefixes are all # for 'bytes'. -_decimalPrefix = [(1000, _("kilo"), _("k")), - (1000**2, _("mega"), _("M")), - (1000**3, _("giga"), _("G")), - (1000**4, _("tera"), _("T")), - (1000**5, _("peta"), _("P")), - (1000**6, _("exa"), _("E")), - (1000**7, _("zetta"), _("Z")), - (1000**8, _("yotta"), _("Y"))] +_decimalPrefix = [(1000, N_("kilo"), N_("k")), + (1000**2, N_("mega"), N_("M")), + (1000**3, N_("giga"), N_("G")), + (1000**4, N_("tera"), N_("T")), + (1000**5, N_("peta"), N_("P")), + (1000**6, N_("exa"), N_("E")), + (1000**7, N_("zetta"), N_("Z")), + (1000**8, N_("yotta"), N_("Y"))]
# Binary prefixes for the different size increments. Same structure # as the above list. -_binaryPrefix = [(1024, _("kibi"), _("Ki")), - (1024**2, _("mebi"), _("Mi")), - (1024**3, _("gibi"), _("Gi")), - (1024**4, _("tebi"), None), - (1024**5, _("pebi"), None), - (1024**6, _("ebi"), None), - (1024**7, _("zebi"), None), - (1024**8, _("yobi"), None)] +_binaryPrefix = [(1024, N_("kibi"), N_("Ki")), + (1024**2, N_("mebi"), N_("Mi")), + (1024**3, N_("gibi"), N_("Gi")), + (1024**4, N_("tebi"), None), + (1024**5, N_("pebi"), None), + (1024**6, N_("ebi"), None), + (1024**7, N_("zebi"), None), + (1024**8, N_("yobi"), None)]
-_bytes = [_('b'), _('byte'), _('bytes')] +_bytes = [N_('b'), N_('byte'), N_('bytes')] _prefixes = _decimalPrefix + _binaryPrefix
def _makeSpecs(prefix, abbr): @@ -89,10 +89,12 @@ def _parseSpec(spec): raise SizeNotPositiveError("spec= param must be >=0")
specifier = m.groups()[1].lower() - if specifier in _bytes or not specifier: + bytes_xlated = [_(b) for b in _bytes] + if not specifier or specifier in bytes_xlated: return size
- for factor, prefix, abbr in _prefixes: + prefixes_xlated = [_(p) for p in _prefixes] + for factor, prefix, abbr in prefixes_xlated: check = _makeSpecs(prefix, abbr)
if specifier in check: @@ -201,10 +203,12 @@ class Size(Decimal): """ spec = spec.lower()
- if spec in _bytes: + bytes_xlated = [_(b) for b in _bytes] + if spec in bytes_xlated: return self
- for factor, prefix, abbr in _prefixes: + prefixes_xlated = [_(p) for p in _prefixes] + for factor, prefix, abbr in prefixes_xlated: check = _makeSpecs(prefix, abbr)
if spec in check: @@ -228,7 +232,8 @@ class Size(Decimal): if Decimal(check) < 1000: return "%s B" % check
- for factor, prefix, abbr in _prefixes: + prefixes_xlated = [_(p) for p in _prefixes] + for factor, prefix, abbr in prefixes_xlated: newcheck = super(Size, self).__div__(Decimal(factor))
if newcheck < 1000: