Python locale 模块,LC_MESSAGES 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用locale.LC_MESSAGES

项目:enigma2    作者:OpenLD    | 项目源码 | 文件源码
def activateLanguage(self, index):
        try:
            lang = self.lang[index]
            print "Activating language " + lang[0]
            self.catalog = gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[index], fallback=True)
            self.catalog.install(names=("ngettext", "pgettext"))
            self.activeLanguage = index
            for x in self.callbacks:
                if x:
                    x()
        except:
            print "Selected language does not exist!"
        # NOTE: we do not use LC_ALL, because LC_ALL will not set any of the categories, when one of the categories fails.
        # We'd rather try to set all available categories, and ignore the others
        for category in [locale.LC_CTYPE, locale.LC_COLLATE, locale.LC_TIME, locale.LC_MONETARY, locale.LC_MESSAGES, locale.LC_NUMERIC]:
            try:
                locale.setlocale(category, (self.getLanguage(), 'UTF-8'))
            except:
                pass
        # HACK: sometimes python 2.7 reverts to the LC_TIME environment value, so make sure it has the correct value
        os.environ["LC_TIME"] = self.getLanguage() + '.UTF-8'
        os.environ["LANGUAGE"] = self.getLanguage() + '.UTF-8'
        os.environ["GST_SUBTITLE_ENCODING"] = self.getGStreamerSubtitleEncoding()
项目:enigma2    作者:Openeight    | 项目源码 | 文件源码
def activateLanguage(self, index):
        try:
            lang = self.lang[index]
            print "Activating language " + lang[0]
            self.catalog = gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[index], fallback=True)
            self.catalog.install(names=("ngettext", "pgettext"))
            self.activeLanguage = index
            for x in self.callbacks:
                x()
        except:
            print "Selected language does not exist!"
        # NOTE: we do not use LC_ALL, because LC_ALL will not set any of the categories, when one of the categories fails.
        # We'd rather try to set all available categories, and ignore the others
        for category in [locale.LC_CTYPE, locale.LC_COLLATE, locale.LC_TIME, locale.LC_MONETARY, locale.LC_MESSAGES, locale.LC_NUMERIC]:
            try:
                locale.setlocale(category, (self.getLanguage(), 'UTF-8'))
            except:
                pass
        # HACK: sometimes python 2.7 reverts to the LC_TIME environment value, so make sure it has the correct value
        os.environ["LC_TIME"] = self.getLanguage() + '.UTF-8'
        os.environ["LANGUAGE"] = self.getLanguage() + '.UTF-8'
        os.environ["GST_SUBTITLE_ENCODING"] = self.getGStreamerSubtitleEncoding()
项目:enigma2    作者:BlackHole    | 项目源码 | 文件源码
def activateLanguage(self, index):
        try:
            lang = self.lang[index]
            print "[Language] Activating language " + lang[0]
            self.catalog = gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[index])
            self.catalog.install(names=("ngettext", "pgettext"))
            self.activeLanguage = index
            for x in self.callbacks:
                if x:
                    x()
        except:
            print "[Language] Selected language does not exist!"
        # NOTE: we do not use LC_ALL, because LC_ALL will not set any of the categories, when one of the categories fails.
        # We'd rather try to set all available categories, and ignore the others
        for category in [locale.LC_CTYPE, locale.LC_COLLATE, locale.LC_TIME, locale.LC_MONETARY, locale.LC_MESSAGES, locale.LC_NUMERIC]:
            try:
                locale.setlocale(category, (self.getLanguage(), 'UTF-8'))
            except:
                pass
        # HACK: sometimes python 2.7 reverts to the LC_TIME environment value, so make sure it has the correct value
        os.environ["LC_TIME"] = self.getLanguage() + '.UTF-8'
        os.environ["LANGUAGE"] = self.getLanguage() + '.UTF-8'
        os.environ["GST_SUBTITLE_ENCODING"] = self.getGStreamerSubtitleEncoding()
项目:crossplatform_iptvplayer    作者:j00zek    | 项目源码 | 文件源码
def activateLanguage(self, index):
        try:
            lang = self.lang[index]
            print "Activating language " + lang[0]
            if pathExists(resolveFilename(SCOPE_GOSLANGUAGE, "%s/LC_MESSAGES/enigma2.mo") % str(lang[1]) ):
                self.catalog = gettext.translation('enigma2', resolveFilename(SCOPE_GOSLANGUAGE, ""), languages=[index])
            else:
                self.catalog = gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[index])
            self.catalog.install(names=("ngettext", "pgettext"))
            self.activeLanguage = index
            for x in self.callbacks:
                x()
        except:
            print "Selected language does not exist!"
        # NOTE: we do not use LC_ALL, because LC_ALL will not set any of the categories, when one of the categories fails.
        # We'd rather try to set all available categories, and ignore the others
        for category in [locale.LC_CTYPE, locale.LC_COLLATE, locale.LC_TIME, locale.LC_MONETARY, locale.LC_MESSAGES, locale.LC_NUMERIC]:
            try:
                locale.setlocale(category, (self.getLanguage(), 'UTF-8'))
            except:
                pass
        # HACK: sometimes python 2.7 reverts to the LC_TIME environment value, so make sure it has the correct value
        os.environ["LC_TIME"] = self.getLanguage() + '.UTF-8'
        os.environ["GST_SUBTITLE_ENCODING"] = self.getGStreamerSubtitleEncoding()
项目:enigma2-openpli-fulan    作者:Taapat    | 项目源码 | 文件源码
def activateLanguage(self, index):
        try:
            if index not in self.lang:
                print "Selected language %s does not exist, fallback to en_EN!" % index
                index = "en_EN"
            lang = self.lang[index]
            print "Activating language " + lang[0]
            self.catalog = gettext.translation('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), languages=[index])
            self.catalog.install(names=("ngettext", "pgettext"))
            self.activeLanguage = index
            for x in self.callbacks:
                x()
        except:
            print "Error in activating language!"
        # NOTE: we do not use LC_ALL, because LC_ALL will not set any of the categories, when one of the categories fails.
        # We'd rather try to set all available categories, and ignore the others
        for category in [locale.LC_CTYPE, locale.LC_COLLATE, locale.LC_TIME, locale.LC_MONETARY, locale.LC_MESSAGES, locale.LC_NUMERIC]:
            try:
                locale.setlocale(category, (self.getLanguage(), 'UTF-8'))
            except:
                pass
        # HACK: sometimes python 2.7 reverts to the LC_TIME environment value, so make sure it has the correct value
        os.environ["LC_TIME"] = self.getLanguage() + '.UTF-8'
        #os.environ["GST_SUBTITLE_ENCODING"] = self.getGStreamerSubtitleEncoding()
项目:crossplatform_iptvplayer    作者:j00zek    | 项目源码 | 文件源码
def addLanguage(self, name, lang, country, encoding):
        if pathExists(resolveFilename(SCOPE_LANGUAGE, "%s/LC_MESSAGES/enigma2.mo") % str(lang)) is True or \
            pathExists(resolveFilename(SCOPE_GOSLANGUAGE, "%s/LC_MESSAGES/enigma2.mo") % str(lang)) is True:
            try:
                self.lang[str(lang + "_" + country)] = ((name, lang, country, encoding))
                self.langlist.append(str(lang + "_" + country))
                print "Language " + str(name) + " added"
            except:
                print "Language " + str(name) + " not found"