Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask Babel - 'translations/de/LC_MESSAGES/messages.po' is marked as fuzzy, skipping

I cant get a basic translationto work in Flask Babel.

Here are my steps.

  1. I have this in a page {{_("Hello")}}

  2. I run this command.

    pybabel extract -F babel.cfg -o messages.pot .
    
  3. I then run this command for German.

    pybabel init -i messages.pot -d translations -l de
    
  4. 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"
    
  5. 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
    
  6. 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.

like image 424
Tampa Avatar asked Sep 23 '12 19:09

Tampa


2 Answers

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.

like image 180
Martijn Pieters Avatar answered Oct 18 '22 01:10

Martijn Pieters


As pybabel said: The catalog itself was marked as "fuzzy" (6th line). If you remove that line, you don't need the 'force' option.

like image 24
Felix Schwarz Avatar answered Oct 18 '22 01:10

Felix Schwarz