13

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 <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"
    
  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.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Tampa
  • 75,446
  • 119
  • 278
  • 425
  • Are you certain there are no `fuzzy` lines in your .po file? Apart from the line at the top, that is. You can force babel to compile it anyway with the `-f` flag. – Martijn Pieters Sep 23 '12 at 20:03
  • where do I place that flag? what d the command line look like? Can you post an answer? – Tampa Sep 23 '12 at 20:14

2 Answers2

16

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 2
    I don't think answer fits very well. Clearly forcing the compilation is the wrong solution - instead, an explanation why there's a "weird" (empty) fuzzy message would be more useful. For example, I have no idea if i should mark it as non-fuzzy or just remove it alltogether. – ThiefMaster Oct 18 '13 at 17:19
  • @ThiefMaster: My answer *already* touches upon that. You'd remove the `#, fuzzy` line; translation tools take care of that flag for you, usually. – Martijn Pieters Oct 18 '13 at 17:21
5

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

Felix Schwarz
  • 2,938
  • 4
  • 28
  • 41