~ubuntu-branches/ubuntu/precise/aptdaemon/precise-proposed

« back to all changes in this revision

Viewing changes to aptdaemon/core.py

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-08-08 16:28:01 UTC
  • Revision ID: package-import@ubuntu.com-20120808162801-5550j97jgp3tlvp9
Tags: 0.43+bzr805-0ubuntu3
* debian/patches/fix_gettext_return_value_type.patch:
  - Make sure to always return unicode from core.Transaction.gettext()
    (LP: #926340).  Based partially on a patch by Sebastian Heinlein.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
 
69
69
# Setup i18n
70
70
_ = lambda msg: gettext.dgettext("aptdaemon", msg)
 
71
if sys.version >= '3':
 
72
    _gettext_method = "gettext"
 
73
    _ngettext_method = "ngettext"
 
74
else:
 
75
    _gettext_method = "ugettext"
 
76
    _ngettext_method = "ungettext"
71
77
 
72
78
APTDAEMON_DBUS_INTERFACE = 'org.debian.apt'
73
79
APTDAEMON_DBUS_PATH = '/org/debian/apt'
1220
1226
        """Set the kwargs which will be send to the AptWorker."""
1221
1227
        self.kwargs = kwargs
1222
1228
 
 
1229
    def _get_translations(self):
 
1230
        """Get a usable translations object, no matter what."""
 
1231
        if self._translation:
 
1232
            return self._translation
 
1233
        else:
 
1234
            domain = "aptdaemon"
 
1235
            return gettext.translation(domain, gettext.bindtextdomain(domain),
 
1236
                                       gettext.bind_textdomain_codeset(domain),
 
1237
                                       fallback=True)
 
1238
 
1223
1239
    def gettext(self, msg):
1224
1240
        """Translate the given message to the language of the transaction.
1225
1241
        Fallback to the system default.
1227
1243
        # Avoid showing the header of the mo file for an empty string
1228
1244
        if not msg:
1229
1245
            return ""
1230
 
        if self._translation:
1231
 
            return self._translation.gettext(msg)
1232
 
        else:
1233
 
            return gettext.gettext(msg)
 
1246
        translation = self._get_translations()
 
1247
        return getattr(translation, _gettext_method)(msg)
1234
1248
 
1235
1249
    def ngettext(self, singular, plural, count):
1236
1250
        """Translate the given plural message to the language of the
1237
1251
        transaction. Fallback to the system default.
1238
1252
        """
1239
 
        if self._translation:
1240
 
            return self._translation.ngettext(singular, plural, count)
1241
 
        else:
1242
 
            return gettext.ngettext(singular, plural, count)
 
1253
        translation = self._get_translations()
 
1254
        return getattr(translation, _ngettext_method)(singular, plural, count)
1243
1255
 
1244
1256
 
1245
1257
class TransactionQueue(GObject.GObject):