pip install Flask-Babel python from flask import Flask from flask_babel import Babel app = Flask(__name__) babel = Babel(app) app.config['BABEL_DEFAULT_LOCALE'] = 'en' app.config['BABEL_TRANSLATION_DIRECTORIES'] = 'translations' msgid "Hello, World!" python from flask import render_template from flask_babel import _ @app.route('/') def index(): message = _('Hello, World!') return render_template('index.html', message=message) html <!DOCTYPE html> <html> <head> <title>Multi-Language Support</title> </head> <body> </body> </html> python @babel.localeselector def get_locale(): return request.accept_languages.best_match(['en', 'zh_CN'])


上一篇:
下一篇:
切换中文