I'm using Flask-Babel for translating string.
In some templates I'm reading the strings from the database(postgresql). How can I translate the strings from the database using Flask-Babel?
I'm using Flask-Babel for translating string.
In some templates I'm reading the strings from the database(postgresql). How can I translate the strings from the database using Flask-Babel?
I would suggest having a engineering text in the database. And in your HTML file (or preferably a HTML you can include everywhere) you have a script with the translations:
Now when you receive the engineering string you just do a lookup in your
translations
dictionary. So the .js file would look something like this:Then you can use babel as usual to extract your strings. And you will have all your translations in the same .po/mo file.
It's not possible to use Babel in database translations, as database content is dynamic and babel translations are static (they didn't change).
If you read the strings from the database you must save the translations on the database. You can create a translation table, something like (locale, source, destination), and get the translated values with a query.