def initGetText(domain, install=False, fallback=True):
locale_paths = [
Path(__file__).parent / ".." / "locale",
Path(sys.prefix) / "share" / "locale",
]
locale_dir, translation = None, None
for locale_dir in [d for d in locale_paths if d.exists()]:
if gettext.find(domain, str(locale_dir)):
log.debug("Loading message catalogs from {}".format(locale_dir))
translation = gettext.translation(domain, str(locale_dir))
break
if translation is None:
# This with either throw FileNotFoundError (fallback=False) or set a
# gettext.NullTranslations
translation = gettext.translation(domain, str(locale_dir),
fallback=fallback)
assert translation
if install:
gettext.install(domain, str(locale_dir), names=["ngettext"])
return translation
评论列表
文章目录