translating strings from database flask-babel

后端 未结 2 940
予麋鹿
予麋鹿 2021-01-05 06:28

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 da

2条回答
  •  心在旅途
    2021-01-05 06:37

    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:

    function receiveDBCallback(response) {
        $('.guestWishes').text(translations[response]);
    }
    

    Then you can use babel as usual to extract your strings. And you will have all your translations in the same .po/mo file.

提交回复
热议问题