Flask Babel で動作する基本的な翻訳を取得できません。
これが私の手順です。
私はこれをページに持っています
{{_("Hello")}}
このコマンドを実行します。
pybabel extract -F babel.cfg -o messages.pot .
次に、ドイツ語に対してこのコマンドを実行します。
pybabel init -i messages.pot -d translations -l de
ドイツ語の mo ファイルは次のとおりです。
/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 <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.6\n" #: templates/baseh5.html:129 msgid "Hello" msgstr "Guten Tag"
このコマンドを実行します。
pybabel compile -d translations
これは私が得るものです。
catalog 'translations/de/LC_MESSAGES/messages.po' is marked as fuzzy, skipping
これをフラスコに設定します
app.config['BABEL_DEFAULT_LOCALE'] = 'de'
何を得るか?私は得るHello
。Flask Babel が機能しなかったのはなぜですか? ファジーにどう対処するか?これが基本だったはずです。