Qt translate strings from non-source files

后端 未结 2 507
无人及你
无人及你 2021-02-14 08:39

I have a Qt project which uses XML files. Those XML files contain human-readable text and this text should be translated by using the Qt tools (lupdate, lrelease, QtLinguist).

2条回答
  •  粉色の甜心
    2021-02-14 08:56

    We had the same problem : XML files containing human readable strings.

    Our solution was to make sure that human readable strings in the XML files were easy to extract (we put them in a LABEL attribute) and we developped a small tool which would parse the XML files, extract the strings, generate a context (by extracting data from the XML file), and then generating a CPP header file containing a list of QT_TR_NOOP().

    This file was added to our project file (.pro) that was used by lupdate.

    This solution was fine for us but we had to be very careful about two things :

    • run this tool each time the content of an XML file changed.
    • make sure the XML files are UTF-8 encoded.

提交回复
热议问题