Search code examples
pythonjinja2python-babel

Get translatable text from an external source into catalog


Possibly i am overlooking an obvious solution or thinking the wrong way...

I have a limited amount of text, words in a database, that I want to display translated to users in a flask/jinja/babel webapp. eg. "running" is a possible value of an "activity" column and that should be "laufen" for my german users.

Words in templates and code are extracted and put into the catalog, but how do i get additional words into the catalog? Is there a simple text file extractor?

The only thing i could think of is, just create a .py file and put lots of _('...') lines in them, but that feels just wrong... is it?


Solution

  • I created a messages.txt with my "words" like gettext function calls:

    _('cycling')
    _('running')
    

    and added it to my babel.cfg as python source:

    [python: messages.txt]
    

    plain, simple, stupid, but works.