Sto usando Flask, Flask-Babel e Jinja2. Sto cercando di generare il file .pot. Quello che ho fatto finora.Pybabel genera un file vuoto con jinja2
mio babel.cfg assomiglia a questo:
[python: **.py]
[jinja2: **.html]
encoding = utf-8
extensions=jinja2.ext.autoescape,jinja2.ext.with_
Sono inizializzare Flask-Babel con la mia app come questo:
# Babel init
babel = Babel(app)
app.config['BABEL_DEFAULT_LOCALE'] = 'en'
Nel mio elenco dei modelli che faccio avere homepage.html:
...
<div class="news-wrapper">
<p class="quote">{{ gettext('Hey there') }}</p>
<p class="quote">{% trans %}Trying 42{% endtrans %}</p>
<p class="quote">{{ _('Maybe like this?') }}</p>
</div>
...
poi eseguire questo comando (mentre io sono nel mio virtualenv):
pybabel extract -F babel.cfg -o messages.pot .
Una delle linee uscite è:
extracting messages from templates/homepage.html (extensions="jinja2.ext.autoescape,jinja2.ext.with_", encoding="utf-8")
Ed è genera un messaggio. file pot con questo contenuto:
# Translations template for PROJECT.
# Copyright (C) 2015 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <[email protected]>, 2015.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2015-04-21 10:06+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\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"
Il file non ha le mie traduzioni.
Non ricevo errori o avvisi, pybabel non riesce a trovare le variazioni gettext
nei file jinja2. MA quando uso lo gettext
in un file .py è che funziona bene.
Mi manca qualcosa? Grazie
impostazione 'silenzio = FALSE nel vostro' babel.cfg' aiuterà a individuare il problema: cosa è, questo dovrebbe davvero essere il default :( Grazie per aver segnalato l'estensione Jinja2 dei webassets! – Manuel
Phew, questo era un bug oscuro - grazie per aver postato la tua correzione, ha funzionato perfettamente. – rlafuente