def gettext_for(lang):
"""
Return a GNUTranslation class for the given language.
Example:
>>> trans = gettext_for('pt_BR')
>>> _ = trans.gettext
>>> _('hello world!') # doctest: +SKIP
'olá mundo!'
"""
lang = lang.replace('-', '_')
try:
with open(os.path.join(L10N_PATH, lang + '.mo'), 'rb') as F:
result = gettext.GNUTranslations(F)
except FileNotFoundError:
result = gettext.NullTranslations()
return result
评论列表
文章目录