English 中文(简体)
How to generate a single translation file for a large Qt project?
原标题:

I have a large project with one qmake project file defining all project components using a subdirs template. Currently I define translation files in the qmake files of each sub-project. This results in separate translation files for each sub-project, which quickly becomes too cumbersome to maintain.

How do I get lupdate to produce a single translation file containing all translation strings for all of the sub-projects?

最佳回答

First of all split all your pro files into pro and pri files. Then put all the pri files into one global pro file and generate the language file for that pro file.

Special language pro file looks like this:

TEMPLATE = app
DEPENDPATH +=  Proj1 Proj2 Proj3    

include(Proj1/Proj1.pri)  
include(Proj2/Proj2.pri)
include(Proj3/Proj3.pri)

TRANSLATIONS = en.ts fr.ts it.main.ts ja.main.ts nl.main.ts

A script can easily generate this project language file for you.

问题回答

I know this question is pretty old but I will still append my solution. This ends up with several single translation files, but this is what I actually wanted to reach.You can then run lupdate on the main project file and it will generate/update the .ts files in every subdir.

Therefore, in every pro file you must specify a TARGET and this project has to be in a folder with exactly this name.

In every project file I included one shared pri file:

# Including shared configurations
!include(../common/shared.pri) {
  error(shared.pri not found)
}

Then, in this pri file:

# Including traslations for every language
exists($$_PRO_FILE_PWD_/translations/) {
    TRANSLATIONS += $$_PRO_FILE_PWD_/translations/$${TARGET}_de_DE.ts
    message(> Found Translations for $${TARGET}: $$_PRO_FILE_PWD_/translations/$${TARGET}_de_DE.ts)
}

For more translated languages you can add a little bit of logic.





相关问题
How does gettext handle dynamic content?

In php (or maybe gettext in general), what does gettext do when it sees a variable to dynamic content? I have 2 cases in mind. 1) Let s say I have <?=$user1?> poked John <?=$user2?>. ...

Explain the Need for Mutexes in Locales, Please

Reading the question Why doesn’t C++ STL support atoi(const string& ) like functions?, I encountered a comment which warned that GCC (at least) has a bug that can slow down multi-threaded ...

How does Vistalizer work

How does Vistalizer manage to override the language limit in Windows Vista Home edition. Which api s does it use to allow installation of Multiple language packages.

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

Rails Globalize plugin help

Has anyone gotten the Globalize plugin to work Rails 2.3.2 or later? If so, could you direct me to some useful info?

热门标签