Create backwards compatibility with Python 3.7 for formatters_i18n

This commit is contained in:
Frisk 2021-05-22 16:07:08 +02:00
parent 938f2432ba
commit 0109f7e165
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC

View file

@ -19,6 +19,11 @@ logger = logging.getLogger("rcgcdw.i18n")
# Setup translation
def python37_pgettext_backward_compatibility(context: str, string: str):
"""Creates backward compatibility with Python 3.7 as pgettext has been introduced only in Python 3.8"""
return formatters_i18n.gettext(string)
try:
if settings["lang"] != "en":
rcgcdw = gettext.translation('rcgcdw', localedir='locale', languages=[settings["lang"]])
@ -28,6 +33,7 @@ try:
redaction = gettext.translation('redaction', localedir='locale', languages=[settings["lang"]])
else:
rcgcdw, discussion_formatters, rc, formatters_i18n, misc, redaction = gettext.NullTranslations(), gettext.NullTranslations(), gettext.NullTranslations(), gettext.NullTranslations(), gettext.NullTranslations(), gettext.NullTranslations()
formatters_i18n.pgettext = python37_pgettext_backward_compatibility
except FileNotFoundError:
logger.critical("No language files have been found. Make sure locale folder is located in the directory.")
sys.exit(1)