如何在枚举中使用Flask-Babel?

时间:2018-06-06 16:29:01

标签: python flask enums flask-babel

在Jinja模板中,语法_()_l()有效。但是当我使用Enum时,该值未被翻译。我该怎么办?

from enum import Enum

from flask_babel import _
from flask_babel import lazy_gettext as _l

class DFNError(Enum):
    def __new__(cls, *args, **kwds):
        value = len(cls.__members__) + 1
        obj = object.__new__(cls)
        obj._value_ = value
        return obj

    def __init__(self, code, message, developer_message):
        self.code = code
        self.message = message
        self.developer_message = developer_message

    UNKNOWN_ERROR_CODE = (name + str(0), _l('Internal Server Error'), _('d'))

1 个答案:

答案 0 :(得分:0)

由于某种原因,它现在有效。我只是重新启动应用程序......