Python gettext 模块,dgettext() 实例源码

我们从Python开源项目中,提取了以下34个代码示例,用于说明如何使用gettext.dgettext()

项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def get_region_name(countrycode):
    """ return translated region name from countrycode using iso3166 """
    # find translated name
    if countrycode:
        for iso in ["iso_3166", "iso_3166_2"]:
            path = os.path.join("/usr/share/xml/iso-codes/", iso + ".xml")
            if os.path.exists(path):
                root = xml.etree.ElementTree.parse(path)
                xpath = ".//%s_entry[@alpha_2_code='%s']" % (iso, countrycode)
                match = root.find(xpath)
                if match is not None:
                    name = match.attrib.get("common_name")
                    if not name:
                        name = match.attrib["name"]
                    return dgettext(iso, name)
    return ""


# the first parameter of SetRequirements
项目:enigma2    作者:OpenLD    | 项目源码 | 文件源码
def _(txt):
    t = gettext.dgettext('messages', txt)
    if t == txt:
        t = gettext.gettext(txt)
    return t
项目:enigma2    作者:OpenLD    | 项目源码 | 文件源码
def _(txt):
    t = gettext.dgettext('messages', txt)
    if t == txt:
        t = gettext.gettext(txt)
    return t
项目:enigma2    作者:Openeight    | 项目源码 | 文件源码
def _(txt):
    t = gettext.dgettext("XTPanel", txt)
    if t == txt:
        print "[XTPanel] fallback to default translation for", txt
        t = gettext.gettext(txt)
    return t
###############################
# Coded by PCD, February 2008 #
###############################
项目:enigma2    作者:Openeight    | 项目源码 | 文件源码
def _(txt):
    t = gettext.dgettext("CCcamInfo", txt)
    if t == txt:
        t = gettext.gettext(txt)
    return t
项目:enigma2    作者:Openeight    | 项目源码 | 文件源码
def _(txt):
    t = gettext.dgettext("MountManager", txt)
    if t == txt:
        t = gettext.gettext(txt)
    return t
项目:DevOps    作者:YoLoveLife    | 项目源码 | 文件源码
def check_incorrect_password(self, b_output):
        b_incorrect_password = to_bytes(gettext.dgettext(self._play_context.become_method, C.BECOME_ERROR_STRINGS[self._play_context.become_method]))
        return b_incorrect_password and b_incorrect_password in b_output
项目:DevOps    作者:YoLoveLife    | 项目源码 | 文件源码
def check_missing_password(self, b_output):
        b_missing_password = to_bytes(gettext.dgettext(self._play_context.become_method, C.BECOME_MISSING_STRINGS[self._play_context.become_method]))
        return b_missing_password and b_missing_password in b_output
项目:enigma2    作者:BlackHole    | 项目源码 | 文件源码
def doSettingsBackup(self):
        backup = None
        from Plugins.SystemPlugins.OBH.BackupManager import BackupFiles
        self.BackupFiles = BackupFiles(self.session, True)
        Components.Task.job_manager.AddJob(self.BackupFiles.createBackupJob())
        Components.Task.job_manager.in_background = False
        for job in Components.Task.job_manager.getPendingJobs():
            if job.name == dgettext('obh', 'Backup manager'):
                break
        self.showJobView(job)
项目:enigma2    作者:BlackHole    | 项目源码 | 文件源码
def doImageBackup(self):
        backup = None
        from Plugins.SystemPlugins.OBH.ImageManager import ImageBackup
        self.ImageBackup = ImageBackup(self.session, True)
        Components.Task.job_manager.AddJob(self.ImageBackup.createBackupJob())
        Components.Task.job_manager.in_background = False
        for job in Components.Task.job_manager.getPendingJobs():
            if job.name == dgettext('obh', 'Image manager'):
                break
        self.showJobView(job)
项目:enigma2    作者:BlackHole    | 项目源码 | 文件源码
def showJobView(self, job):
        if job.name == dgettext('OBH', 'Image manager'):
            self.ImageBackupDone = True
        elif job.name == dgettext('obh', 'Backup manager'):
            self.SettingsBackupDone = True
        from Screens.TaskView import JobView
        Components.Task.job_manager.in_background = False
        if not self.autobackuprunning:
            self.session.openWithCallback(self.startActualUpgrade(("menu", "menu")), JobView, job,  cancelable = False, backgroundable = False, afterEventChangeable = False, afterEvent="close")
        else:
            self.session.openWithCallback(self.doAutoBackup, JobView, job,  cancelable = False, backgroundable = False, afterEventChangeable = False, afterEvent="close")
项目:AutoBouquetsMaker    作者:oe-alliance    | 项目源码 | 文件源码
def _(txt):
    if gettext.dgettext(PluginLanguageDomain, txt):
        return gettext.dgettext(PluginLanguageDomain, txt)
    else:
        print "[" + PluginLanguageDomain + "] fallback to default translation for " + txt
        return gettext.gettext(txt)
项目:gnome-appfolders-manager    作者:muflone    | 项目源码 | 文件源码
def text(message, gtk30=False, context=None):
    """Return a translated message and cache it for reuse"""
    if message not in localized_messages:
        if gtk30:
            # Get a message translated from GTK+ 3 domain
            full_message = message if not context else '%s\04%s' % (
                context, message)
            localized_messages[message] = dgettext('gtk30', full_message)
            # Fix for untranslated messages with context
            if context and localized_messages[message] == full_message:
                localized_messages[message] = dgettext('gtk30', message)
        else:
            localized_messages[message] = gettext(message)
    return localized_messages[message]
项目:ansible-provider-docs    作者:alibaba    | 项目源码 | 文件源码
def check_incorrect_password(self, b_output):
        b_incorrect_password = to_bytes(gettext.dgettext(self._play_context.become_method, C.BECOME_ERROR_STRINGS[self._play_context.become_method]))
        return b_incorrect_password and b_incorrect_password in b_output
项目:ansible-provider-docs    作者:alibaba    | 项目源码 | 文件源码
def check_missing_password(self, b_output):
        b_missing_password = to_bytes(gettext.dgettext(self._play_context.become_method, C.BECOME_MISSING_STRINGS[self._play_context.become_method]))
        return b_missing_password and b_missing_password in b_output
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def langcode_to_name(langcode):
    import xml.etree.ElementTree
    from gettext import dgettext
    for iso in ["iso_639_3", "iso_639"]:
        path = os.path.join("/usr/share/xml/iso-codes/", iso + ".xml")
        if os.path.exists(path):
            root = xml.etree.ElementTree.parse(path)
            xpath = ".//%s_entry[@part1_code='%s']" % (iso, langcode)
            match = root.find(xpath)
            if match is not None:
                return dgettext(iso, match.attrib["name"])
    return langcode
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _init_submit(self):
        self.submit_window.set_title(_("Review %s") %
            gettext.dgettext("app-install-data", self.app.name))
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _init_modify(self):
        self._populate_review()
        self.submit_window.set_title(_("Modify Your %(appname)s Review") % {
            'appname': gettext.dgettext("app-install-data", self.app.name)})
        self.button_post.set_label(_("Modify"))
        self.SUBMIT_MESSAGE = _("Updating your review")
        self.FAILURE_MESSAGE = _("Failed to edit review")
        self.SUCCESS_MESSAGE = _("Review updated")
        self._enable_or_disable_post_button()
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _setup_details(self, widget, app, iconname, version, display_name):
        # icon shazam
        try:
            icon = self.icons.load_icon(iconname, self.APP_ICON_SIZE, 0)
        except:
            icon = self.icons.load_icon(Icons.MISSING_APP, self.APP_ICON_SIZE,
                0)
        self.review_appicon.set_from_pixbuf(icon)

        # title
        app = utf8(gettext.dgettext("app-install-data", app.name))
        version = utf8(version)
        self.review_title.set_markup(
            '<b><span size="x-large">%s</span></b>\n%s' % (app, version))

        # review label
        self.review_label.set_markup(_('Review by: %s') %
            display_name.encode('utf8'))

        # review summary label
        self.review_summary_label.set_markup(_('Summary:'))

        #rating label
        self.rating_label.set_markup(_('Rating:'))
        #error detail link label
        self.label_expander.set_markup('<small><u>%s</u></small>' %
            (_('Error Details')))
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def get_desktop(self, key, translated=True):
        " get generic option under 'Desktop Entry'"
        # never translate the pkgname
        if key == "X-AppInstall-Package":
            return self.get(self.DE, key)
        # shortcut
        if not translated:
            return self.get(self.DE, key)
        # first try dgettext
        if self.has_option_desktop("X-Ubuntu-Gettext-Domain"):
            value = self.get(self.DE, key)
            if value:
                domain = self.get(self.DE, "X-Ubuntu-Gettext-Domain")
                translated_value = gettext.dgettext(domain, value)
                if value != translated_value:
                    return translated_value
        # then try app-install-data
        value = self.get(self.DE, key)
        if value:
            translated_value = gettext.dgettext("app-install-data", value)
            if value != translated_value:
                return translated_value
        # then try the i18n version of the key (in [de_DE] or
        # [de]) but ignore errors and return the untranslated one then
        try:
            locale = getdefaultlocale(('LANGUAGE', 'LANG', 'LC_CTYPE',
                'LC_ALL'))[0]
            if locale:
                if self.has_option_desktop("%s[%s]" % (key, locale)):
                    return self.get(self.DE, "%s[%s]" % (key, locale))
                if "_" in locale:
                    locale_short = locale.split("_")[0]
                    if self.has_option_desktop("%s[%s]" % (key, locale_short)):
                        return self.get(self.DE, "%s[%s]" %
                            (key, locale_short))
        except ValueError:
            pass
        # and then the untranslated field
        return self.get(self.DE, key)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def langcode_to_name(langcode):
    import xml.etree.ElementTree
    from gettext import dgettext
    for iso in ["iso_639_3", "iso_639"]:
        path = os.path.join("/usr/share/xml/iso-codes/", iso + ".xml")
        if os.path.exists(path):
            root = xml.etree.ElementTree.parse(path)
            xpath = ".//%s_entry[@part1_code='%s']" % (iso, langcode)
            match = root.find(xpath)
            if match is not None:
                return dgettext(iso, match.attrib["name"])
    return langcode
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _init_submit(self):
        self.submit_window.set_title(_("Review %s") %
            gettext.dgettext("app-install-data", self.app.name))
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _init_modify(self):
        self._populate_review()
        self.submit_window.set_title(_("Modify Your %(appname)s Review") % {
            'appname': gettext.dgettext("app-install-data", self.app.name)})
        self.button_post.set_label(_("Modify"))
        self.SUBMIT_MESSAGE = _("Updating your review")
        self.FAILURE_MESSAGE = _("Failed to edit review")
        self.SUCCESS_MESSAGE = _("Review updated")
        self._enable_or_disable_post_button()
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _setup_details(self, widget, app, iconname, version, display_name):
        # icon shazam
        try:
            icon = self.icons.load_icon(iconname, self.APP_ICON_SIZE, 0)
        except:
            icon = self.icons.load_icon(Icons.MISSING_APP, self.APP_ICON_SIZE,
                0)
        self.review_appicon.set_from_pixbuf(icon)

        # title
        app = utf8(gettext.dgettext("app-install-data", app.name))
        version = utf8(version)
        self.review_title.set_markup(
            '<b><span size="x-large">%s</span></b>\n%s' % (app, version))

        # review label
        self.review_label.set_markup(_('Review by: %s') %
            display_name.encode('utf8'))

        # review summary label
        self.review_summary_label.set_markup(_('Summary:'))

        #rating label
        self.rating_label.set_markup(_('Rating:'))
        #error detail link label
        self.label_expander.set_markup('<small><u>%s</u></small>' %
            (_('Error Details')))
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def get_desktop(self, key, translated=True):
        # strip away bogus prefixes
        if key.startswith("X-AppInstall-"):
            key = key[len("X-AppInstall-"):]
        # shortcut
        if not translated:
            return self.tag_section[key]
        # FIXME: make i18n work similar to get_desktop
        # first try dgettext
        if "Gettext-Domain" in self.tag_section:
            value = self.tag_section.get(key)
            if value:
                domain = self.tag_section["Gettext-Domain"]
                translated_value = gettext.dgettext(domain, value)
                if value != translated_value:
                    return translated_value
        # then try the i18n version of the key (in [de_DE] or
        # [de]) but ignore errors and return the untranslated one then
        try:
            locale = getdefaultlocale(('LANGUAGE', 'LANG', 'LC_CTYPE',
                'LC_ALL'))[0]
            if locale:
                if self.has_option_desktop("%s-%s" % (key, locale)):
                    return self.tag_section["%s-%s" % (key, locale)]
                if "_" in locale:
                    locale_short = locale.split("_")[0]
                    if self.has_option_desktop("%s-%s" % (key, locale_short)):
                        return self.tag_section["%s-%s" % (key, locale_short)]
        except ValueError:
            pass
        # and then the untranslated field
        return self.tag_section[key]
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def get_desktop(self, key, translated=True):
        " get generic option under 'Desktop Entry'"
        # never translate the pkgname
        if key == "X-AppInstall-Package":
            return self.get(self.DE, key)
        # shortcut
        if not translated:
            return self.get(self.DE, key)
        # first try dgettext
        if self.has_option_desktop("X-Ubuntu-Gettext-Domain"):
            value = self.get(self.DE, key)
            if value:
                domain = self.get(self.DE, "X-Ubuntu-Gettext-Domain")
                translated_value = gettext.dgettext(domain, value)
                if value != translated_value:
                    return translated_value
        # then try app-install-data
        value = self.get(self.DE, key)
        if value:
            translated_value = gettext.dgettext("app-install-data", value)
            if value != translated_value:
                return translated_value
        # then try the i18n version of the key (in [de_DE] or
        # [de]) but ignore errors and return the untranslated one then
        try:
            locale = getdefaultlocale(('LANGUAGE', 'LANG', 'LC_CTYPE',
                'LC_ALL'))[0]
            if locale:
                if self.has_option_desktop("%s[%s]" % (key, locale)):
                    return self.get(self.DE, "%s[%s]" % (key, locale))
                if "_" in locale:
                    locale_short = locale.split("_")[0]
                    if self.has_option_desktop("%s[%s]" % (key, locale_short)):
                        return self.get(self.DE, "%s[%s]" %
                            (key, locale_short))
        except ValueError:
            pass
        # and then the untranslated field
        return self.get(self.DE, key)
项目:HRTunerProxy    作者:OpenViX    | 项目源码 | 文件源码
def _(txt):
    if gettext.dgettext(PluginLanguageDomain, txt):
        return gettext.dgettext(PluginLanguageDomain, txt)
    else:
        print "[" + PluginLanguageDomain + "] fallback to default translation for " + txt
        return gettext.gettext(txt)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def _dugettext(domain, message):
    '''
    :param domain: translation domain
    :param message: message to translate
    :returns: the translated message

    Unicode version of :func:`gettext.dgettext`.
    '''
    try:
        t = gettext.translation(domain, gettext._localedirs.get(domain, None),
                                codeset=gettext._localecodesets.get(domain))
    except IOError:
        return message
    else:
        return t.ugettext(message)
项目:gdebi    作者:linuxmint    | 项目源码 | 文件源码
def __(catalog,str):
    return utf8(gettext.dgettext(catalog, str))
项目:crossplatform_iptvplayer    作者:j00zek    | 项目源码 | 文件源码
def TranslateTXT(txt):
    t = gettext.dgettext(PluginLanguageDomain, txt)
    if t == txt:
        t = gettext.gettext(txt)
    return t
项目:crossplatform_iptvplayer    作者:j00zek    | 项目源码 | 文件源码
def TranslateTXT(txt):
    t = gettext.dgettext(PluginLanguageDomain, txt)
    if t == txt:
        t = gettext.gettext(txt)
    return t
项目:enigma2    作者:OpenLD    | 项目源码 | 文件源码
def addItems(self, list, parentNode):
        for x in parentNode:
            if not x.tag:
                continue
            if x.tag == 'item':
                item_level = int(x.get("level", 0))

                if not self.onNotifiers:
                    self.onNotifiers.append(self.levelChanged)
                    self.onClose.append(self.removeNotifier)

                if item_level > config.usage.setup_level.index:
                    continue

                requires = x.get("requires")
                if requires and requires.startswith('config.'):
                    item = eval(requires or "")
                    if item.value and not item.value == "0":
                        SystemInfo[requires] = True
                    else:
                        SystemInfo[requires] = False

                if requires and not SystemInfo.get(requires, False):
                    continue

                if self.PluginLanguageDomain:
                    item_text = dgettext(self.PluginLanguageDomain, x.get("text", "??").encode("UTF-8"))
                    item_description = dgettext(self.PluginLanguageDomain, x.get("description", " ").encode("UTF-8"))
                else:
                    item_text = _(x.get("text", "??").encode("UTF-8"))
                    item_description = _(x.get("description", " ").encode("UTF-8"))

                item_text = item_text.replace("%s %s","%s %s" % (getMachineBrand(), getMachineName()))
                item_description = item_description.replace("%s %s","%s %s" % (getMachineBrand(), getMachineName()))
                b = eval(x.text or "")
                if b == "":
                    continue
                #add to configlist
                item = b
                # the first b is the item itself, ignored by the configList.
                # the second one is converted to string.
                if not isinstance(item, ConfigNothing):
                    list.append((item_text, item, item_description))
项目:enigma2    作者:BlackHole    | 项目源码 | 文件源码
def __init__(self, session, retvalue=1, timeout=-1, default_yes = True):
        self.retval = retvalue
        self.ptsmainloopvalue = retvalue
        recordings = session.nav.getRecordings()
        jobs = []
        for job in job_manager.getPendingJobs():
            if job.name != dgettext('vix', 'SoftcamCheck'):
                jobs.append(job)

        inTimeshift = Screens.InfoBar.InfoBar and Screens.InfoBar.InfoBar.instance and Screens.InfoBar.InfoBar.ptsGetTimeshiftStatus(Screens.InfoBar.InfoBar.instance)
        self.connected = False
        reason = ""
        next_rec_time = -1
        if not recordings:
            next_rec_time = session.nav.RecordTimer.getNextRecordingTime()
        if len(jobs):
            reason = (ngettext("%d job is running in the background!", "%d jobs are running in the background!", len(jobs)) % len(jobs)) + '\n'
            if len(jobs) == 1:
                job = jobs[0]
                reason += "%s: %s (%d%%)\n" % (job.getStatustext(), job.name, int(100*job.progress/float(job.end)))
            else:
                reason += (_("%d jobs are running in the background!") % len(jobs)) + '\n'
        if inTimeshift:
            reason = _("You seem to be in timeshift!") + '\n'
        if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360):
            default_yes = False
            reason = _("Recording(s) are in progress or coming up in few seconds!") + '\n'

        if reason and inStandby:
            session.nav.record_event.append(self.getRecordEvent)
            self.skinName = ""
        elif reason and not inStandby:
            text = { 1: _("Really shutdown now?"),
                2: _("Really reboot now?"),
                3: _("Really restart now?"),
                4: _("Really upgrade the frontprocessor and reboot now?"),
                42: _("Really upgrade your %s %s and reboot now?") % (getMachineBrand(), getMachineName()),
                43: _("Really reflash your %s %s and reboot now?") % (getMachineBrand(), getMachineName()) }.get(retvalue)
            if text:
                MessageBox.__init__(self, session, reason+text, type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
                self.skinName = "MessageBoxSimple"
                session.nav.record_event.append(self.getRecordEvent)
                self.connected = True
                self.onShow.append(self.__onShow)
                self.onHide.append(self.__onHide)
                return
        self.skin = """<screen position="1310,0" size="0,0"/>"""
        Screen.__init__(self, session)
        self.close(True)
项目:enigma2    作者:BlackHole    | 项目源码 | 文件源码
def addItems(self, list, parentNode):
        for x in parentNode:
            if not x.tag:
                continue
            if x.tag == 'item':
                item_level = int(x.get("level", 0))

                if not self.levelChanged in config.usage.setup_level.notifiers:
                    config.usage.setup_level.notifiers.append(self.levelChanged)
                    self.onClose.append(self.removeNotifier)

                if item_level > config.usage.setup_level.index:
                    continue

                requires = x.get("requires")
                if requires and requires.startswith('config.'):
                    item = eval(requires or "")
                    if item.value and not item.value == "0":
                        SystemInfo[requires] = True
                    else:
                        SystemInfo[requires] = False

                if requires and not SystemInfo.get(requires, False):
                    continue

                if self.PluginLanguageDomain:
                    item_text = dgettext(self.PluginLanguageDomain, x.get("text", "??").encode("UTF-8"))
                    item_description = dgettext(self.PluginLanguageDomain, x.get("description", " ").encode("UTF-8"))
                else:
                    item_text = _(x.get("text", "??").encode("UTF-8"))
                    item_description = _(x.get("description", " ").encode("UTF-8"))

                item_text = item_text.replace("%s %s","%s %s" % (getMachineBrand(), getMachineName()))
                item_description = item_description.replace("%s %s","%s %s" % (getMachineBrand(), getMachineName()))
                b = eval(x.text or "")
                if b == "":
                    continue
                #add to configlist
                item = b
                # the first b is the item itself, ignored by the configList.
                # the second one is converted to string.
                if not isinstance(item, ConfigNothing):
                    list.append((item_text, item, item_description))