我开始将 Babel 与 WTForms 和 Flask 一起使用。下面我尝试 gettext 我的用户名和密码的占位符关键字字段的占位符关键字:
\n\n#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nfrom flask_babel import gettext\nfrom flask_wtf import FlaskForm\nfrom wtforms import PasswordField, StringField\nfrom wtforms.validators import DataRequired\n\n\nclass LoginForm(FlaskForm):\n username = StringField(label=\'username\',\n validators=[DataRequired()],\n render_kw={"placeholder": gettext(\'Username\')})\n password = PasswordField(label=\'password\',\n validators=[DataRequired()],\n render_kw={"placeholder": gettext(\'Password\')})\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的法语 .po 文件(当然已经编译过):
\n\n# French (France) translations for PROJECT.\n# Copyright (C) 2017 ORGANIZATION\n# This file is distributed under the same license as the PROJECT project.\n# FIRST AUTHOR <EMAIL@ADDRESS>, 2017.\n#\nmsgid ""\nmsgstr ""\n"Project-Id-Version: PROJECT …Run Code Online (Sandbox Code Playgroud)