I cant get a basic translationto work in Flask Babel.
Here are my steps.
I have this in a page {{_("Hello")}}
I run this command.
pybabel extract -F babel.cfg -o messages.pot .
I then run this command for German.
pybabel init -i messages.pot -d translations -l de
Here is the mo file for german in /app/translations/de/LC_MESSAGES/messages.po
# German translations for PROJECT.
# Copyright (C) 2012 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2012-09-24 03:36+0800\n"
"PO-Revision-Date: 2012-09-24 03:37+0800\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: de <[email protected]>\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.6\n"
#: templates/baseh5.html:129
msgid "Hello"
msgstr "Guten Tag"
I run this command.
pybabel compile -d translations
This is what I get.
catalog 'translations/de/LC_MESSAGES/messages.po' is marked as fuzzy, skipping
set this is flask
app.config['BABEL_DEFAULT_LOCALE'] = 'de'
What do I get? I get Hello
. Why did Flask Babel not work? How do I deal with fuzzy? This should have been basic.
You can force pybabel compile
to compile messages marked as fuzzy with the -f
(or --use-fuzzy
) command line switch:
pybabel compile -f -d translations
'Fuzzy' messages are marked with a #, fuzzy
line above the msgid
line, and are the result of a merge where a message is deemed slightly changed from the previous version. A message marked as fuzzy
is supposed to be looked at by a human to make sure the translation doesn't need updating, after which the human translator removes that flag.
As pybabel said: The catalog itself was marked as "fuzzy" (6th line). If you remove that line, you don't need the 'force' option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With