po_views.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pyramid_i18n_helper 作者: sahama 项目源码 文件源码
def __init__(self, context, request: Request):
        self.request = request
        self.context = context
        _ = request.translate
        self.helper = request.registry['i18n_helper']
        self.lang = request.matchdict['lang']
        self.domain = request.matchdict['domain']

        self.locale = babel.Locale(*babel.parse_locale(self.lang))

        self.pot_file_path = os.path.join(self.helper.locale_dir, '{0}.pot'.format(self.domain))
        self.po_file_path = os.path.join(self.helper.locale_dir, self.lang, 'LC_MESSAGES',
                                         '{0}.po'.format(self.domain))
        self.mo_file_path = os.path.join(self.helper.locale_dir, self.lang, 'LC_MESSAGES',
                                         '{0}.mo'.format(self.domain))

        if os.path.exists(self.po_file_path):
            self.po = polib.pofile(self.po_file_path, encoding='UTF-8')
        else:
            self.po = polib.POFile(encoding='UTF-8')

        self.po.metadata= {'Content-Transfer-Encoding': '8bit',
                           'Content-Type': 'text/plain; charset=UTF-8',
                           'Language': self.lang}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号