Re: [flask] Flask+i18n
- From:
- Italo Maia
- Date:
- 2010-09-02 @ 19:43
Hummm, thanks Wara = ]
2010/9/2 Wara Songkran <wsongk@gmail.com>
> On Thu, Sep 2, 2010 at 11:00 AM, Italo Maia <italo.maia@gmail.com> wrote:
> > Besides extending Flask class and adding 'jinja2.ext.i18n' to
> jinja_options,
> > is there anything else that needs to be done to activate translations for
> > jinja2 in flask? I have a persistent exception here: UndefinedError:
> > 'gettext' is undefined
> >
>
> Flask-Babel extension is already simplified those process for you.
> Please read the document http://packages.python.org/Flask-Babel/ and
> here's an examples
>
> == views.py ==
> from flask import Flask, render_template
> from flaskext.babel import Babel
>
> app = Flask(__name__)
> app.config['BABEL_DEFAULT_LOCALE'] = 'it'
> babel = Babel(app)
>
> @app.route('/')
> def hello():
> return render_template('hello.html')
>
> if __name__ == '__main__':
> app.run(debug=True)
>
>
> == templates/hello.html ==
> <h1>{{ _('Hello World') }}</h1>
>
>
> == translations/it/LC_MESSAGES/messages.po ==
> # Italian translations for PROJECT.
> # Copyright (C) 2010 ORGANIZATION
> # This file is distributed under the same license as the PROJECT project.
> # FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
> #
> msgid ""
> msgstr ""
> "Project-Id-Version: PROJECT VERSION\n"
> "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
> "POT-Creation-Date: 2010-09-02 22:13+0700\n"
> "PO-Revision-Date: 2010-09-02 22:18+0700\n"
> "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
> "Language-Team: it <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 0.9.5\n"
>
> #: templates/hello.html:1
> msgid "Hello World"
> msgstr "Ciao a tutti"
>
--
"A arrogância é a arma dos fracos."
===========================
Italo Moreira Campelo Maia
Graduado em Ciência da Computação - UECE
Desenvolvedor WEB e Desktop (Java, Python, Lua)
Coordenador do Pug-CE
-----------------------------------------------------
http://www.italomaia.com/
http://twitter.com/italomaia/
http://eusouolobomau.blogspot.com/
-----------------------------------------------------
turtle linux 910 - http://tiny.cc/blogturtle910
===========================