如何为大型 Qt 项目生成单个翻译文件?

发布于 2024-08-13 07:19:23 字数 153 浏览 2 评论 0原文

我有一个大型项目,其中有一个 qmake 项目文件,使用“子目录”模板定义所有项目组件。目前我在每个子项目的qmake文件中定义翻译文件。这会导致每个子项目都有单独的翻译文件,这很快就会变得难以维护。

如何让 lupdate 生成包含所有子项目的所有翻译字符串的单个翻译文件?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阿楠 2024-08-20 07:19:24

首先,将所有 pro 文件 拆分为 propri 文件。然后将所有 pri 文件放入一个全局 pro 文件,并为该 pro 文件生成语言文件。

特殊语言 pro 文件如下所示:

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

脚本可以轻松地为您生成该项目语言文件。

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.

陪你到最终 2024-08-20 07:19:24

我知道这个问题已经很老了,但我仍然会附加我的解决方案。最终得到几个单独的翻译文件,但这正是我真正想要达到的目标。然后您可以在主项目文件上运行 lupdate ,它将生成/更新每个子目录中的 .ts 文件。

因此,在每个 pro 文件中,您必须指定一个 TARGET 并且该项目必须位于具有完全相同名称的文件夹中。

在每个项目文件中,我都包含一个共享的 pri 文件:

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

然后,在此 pri 文件中:

# 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)
}

对于更多翻译语言,您可以添加一点逻辑。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文