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]
评论列表
文章目录