Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://packages.python.org/Flask-Babel/" rel="nofollow">Flask-Babel</a> is really great project. If you looking for jinja, i18n and Flask on google, you will find some useful examples. Please see <a href="http://jinja.pocoo.org/docs/templates" rel="nofollow">docs</a> for more info. Here I'll provide a little example:</p> <p><strong>1. Create the translations dir</strong>:</p> <pre><code>my_website/translations/pt/LC_MESSAGES/ my_website/translations/en/LC_MESSAGES/ </code></pre> <p>Assuming that your site is in Portuguese and English. It is a manual way to do that. You'd better use <code>pybabel init</code> <a href="https://pythonhosted.org/Flask-BabelEx/" rel="nofollow">command</a>. </p> <p><strong>2. Create a file named messages.po (these files will contain translated strings):</strong></p> <pre><code>$ touch my_website/translations/pt/LC_MESSAGES/messages.po $ printf "msgid \"Hello world\"\nmsgstr \"Olá mundo\"" &gt; my_website/translations/pt/LC_MESSAGES/messages.po $ cat my_website/translations/pt/LC_MESSAGES/messages.po </code></pre> <p>It will create a file with the follow content:</p> <pre><code>msgid "HELLO WORLD" msgstr "Olá mundo" </code></pre> <p><strong>3. Compile translation</strong></p> <pre><code> $ pybabel compile -d translations </code></pre> <p><strong>4. Added line code this to your flask's main app file.</strong></p> <pre><code>app.config['BABEL_DEFAULT_LOCALE'] = 'pt_BR' #(context locale to load language). </code></pre> <p><strong>5. Use <code>_()</code> function in your jinja's template file in order to see <em>Olá mundo</em> string.</strong></p> <pre><code>&lt;h1&gt;{{ _('HELLO WORLD') }}&lt;/h1&gt; </code></pre> <p>I hope it'll be useful.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload