Important: Please read the Qt Code of Conduct -

How to translate dynamic words at run-time instead of re-compile TS files?

  • I meet a problem when I teach Qt internationalization system and have no idea. My student (This boy is out-standing !) said:

    Suppose my boss want to build an application that read some records from database. The book name field "BOOK_NAME" contains characters in EN.US, but our consumers want it to be displayed in there mother language, how to translate it ?

    We know, Qt TS files and the lupdate-lrelease system is a static translation system. We should exactly know which words will present in the GUI. So, we can determine the button text, the group box title, even the column names of a table-view, but we can not predict the book names which does not exist in the database now.

    A fall-back solution is to prepair a JSON column, using key-value pairs for each book name, like : {'C':'The Last Emperor', 'zh-CN':'末代皇帝'......}. However, it seems a little fussy.

    Is there some easy-to-use solution for this purpose ?

  • This is not the job of linguist. this is not translating the UI, this is translating user data.
    You need a source of that translation, either a xml/json/database of translation or using a translator API (like Google's) and do web requests.

    Cockatrice, a magic card game simulator in C++/Qt, had to go through that problem to translate the cards text. If I'm not mistaken what they do is ask a central server for the translated version on a generic data and they get it back

  • Lifetime Qt Champion


    In addition to @VRonin, from your definition, the service you are contacting should provide translated versions of its content on demand using e.g. a query string or an endpoint that has the language in its URI, etc.

  • @VRonin thank you!

  • @SGaist said in How to translate dynamic words at run-time instead of re-compile TS files?:


    Thank you! may be we can put the locale into URI, "&locale=zh-CN", this is good.

  • Lifetime Qt Champion

    It depends a bit on what you use as a backend to get data from your database.

Log in to reply