Skip to content

Instantly share code, notes, and snippets.

@shinux
Last active August 29, 2015 14:14
Show Gist options
  • Save shinux/5e41e6f7fc1a28946dd2 to your computer and use it in GitHub Desktop.
Save shinux/5e41e6f7fc1a28946dd2 to your computer and use it in GitHub Desktop.
[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_
# Chinese translations for PROJECT.
# Copyright (C) 2015 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2015.
#
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2015-02-03 15:45+0800\n"
"PO-Revision-Date: 2015-02-03 15:45+0800\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: zh <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 1.3\n"
#: translations.py:9
msgid "My App"
msgstr "我的应用"
# -*- coding: utf-8 -*-
from flask import Flask, redirect
from flask.ext.admin import Admin, BaseView, expose
from flask.ext.babel import lazy_gettext
from flask_babelex import Babel
babel = Babel()
@babel.localeselector
def get_locale():
return 'zh'
app = Flask(__name__)
babel.init_app(app)
admin = Admin(app, name=lazy_gettext('My App'))
@app.route('/')
def to_admin():
return redirect('/admin')
if __name__ == '__main__':
app.run(debug=True)
@shinux
Copy link
Author

shinux commented Feb 3, 2015

put the file above in same level. run

pybabel init -i messages.pot -d translations -l zh

pybabel compile -d translations

python my_app.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment