Qt translate strings from non-source files

后端 未结 2 504
无人及你
无人及你 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:47

    You can translate anything you want at runtime by using tr(), as long as the .qm file has a matching translation/context. It shouldn't make any difference whether lupdate extracted it or not.

    I don't know how to make lupdate to extract strings from arbitrary XML, but that doesn't mean you can't use linguist.

    1. .ts files are also XML; it should be easy to make an XSLT that transforms your XML into a .ts file. If you want to target something standard instead of just Qt, lupdate(and linguist) can process also XLIFF files.
    2. you can have multiple .ts files (just call QTranslator::load more than once when setting it up)

    If you really want to have it all in one file for the translator, have your XSLT copy the lupdate-generated file into its output.

    As long as you use a context name that doesn't duplicate something used in the source code, this shouldn't be any different (from Qt's point of view) from the way many apps load a .qm for each DLL that has GUI.

提交回复
热议问题