use qt resource system's recommended approach for translation files (#449)
This commit is contained in:
parent
dac24ec57d
commit
e2934072d1
|
@ -3,6 +3,8 @@ QT += core gui printsupport network svg xml widgets
|
||||||
CONFIG += c++17
|
CONFIG += c++17
|
||||||
CONFIG += nokey
|
CONFIG += nokey
|
||||||
|
|
||||||
|
CONFIG += lrelease embed_translations
|
||||||
|
|
||||||
# uncomment the following line to enable vcs (git) support
|
# uncomment the following line to enable vcs (git) support
|
||||||
# CONFIG += ENABLE_VCS
|
# CONFIG += ENABLE_VCS
|
||||||
|
|
||||||
|
@ -539,13 +541,6 @@ TRANSLATIONS += \
|
||||||
translations/RedPandaIDE_zh_TW.ts \
|
translations/RedPandaIDE_zh_TW.ts \
|
||||||
translations/RedPandaIDE_pt_BR.ts
|
translations/RedPandaIDE_pt_BR.ts
|
||||||
|
|
||||||
EXTRA_TRANSLATIONS += \
|
|
||||||
../libs/redpanda_qt_utils/qt_utils_zh_CN.ts \
|
|
||||||
../libs/qsynedit/qsynedit_zh_CN.ts
|
|
||||||
|
|
||||||
|
|
||||||
#CONFIG += lrelease embed_translations
|
|
||||||
|
|
||||||
win32: {
|
win32: {
|
||||||
!isEmpty(PREFIX) {
|
!isEmpty(PREFIX) {
|
||||||
target.path = $${PREFIX}
|
target.path = $${PREFIX}
|
||||||
|
@ -567,31 +562,6 @@ RESOURCES += \
|
||||||
|
|
||||||
RC_ICONS = images/devcpp.ico images/associations/c.ico images/associations/cpp.ico images/associations/dev.ico images/associations/c.ico images/associations/cpp.ico images/associations/h.ico images/associations/hpp.ico
|
RC_ICONS = images/devcpp.ico images/associations/c.ico images/associations/cpp.ico images/associations/dev.ico images/associations/c.ico images/associations/cpp.ico images/associations/h.ico images/associations/hpp.ico
|
||||||
|
|
||||||
# fixed lrelease.prf
|
|
||||||
qtPrepareTool(QMAKE_LRELEASE, lrelease)
|
|
||||||
|
|
||||||
isEmpty(LRELEASE_DIR): LRELEASE_DIR = .qm
|
|
||||||
isEmpty(QM_FILES_RESOURCE_PREFIX): QM_FILES_RESOURCE_PREFIX = i18n
|
|
||||||
|
|
||||||
lrelease.name = lrelease
|
|
||||||
lrelease.input = TRANSLATIONS EXTRA_TRANSLATIONS
|
|
||||||
lrelease.output = $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm
|
|
||||||
lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} $$QMAKE_LRELEASE_FLAGS -qm ${QMAKE_FILE_OUT}
|
|
||||||
silent: lrelease.commands = @echo lrelease ${QMAKE_FILE_IN} && $$lrelease.commands
|
|
||||||
lrelease.CONFIG = no_link target_predeps
|
|
||||||
QMAKE_EXTRA_COMPILERS += lrelease
|
|
||||||
|
|
||||||
all_translations = $$TRANSLATIONS $$EXTRA_TRANSLATIONS
|
|
||||||
for (translation, all_translations) {
|
|
||||||
# mirrors $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm above
|
|
||||||
translation = $$basename(translation)
|
|
||||||
QM_FILES += $$OUT_PWD/$$LRELEASE_DIR/$$replace(translation, \\..*$, .qm)
|
|
||||||
}
|
|
||||||
|
|
||||||
qmake_qm_files.files = $$QM_FILES
|
|
||||||
qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR
|
|
||||||
qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX
|
|
||||||
|
|
||||||
iconsets_files.files += $$files(resources/iconsets/*.svg, true)
|
iconsets_files.files += $$files(resources/iconsets/*.svg, true)
|
||||||
iconsets_files.files += $$files(resources/iconsets/*.json, true)
|
iconsets_files.files += $$files(resources/iconsets/*.json, true)
|
||||||
|
|
||||||
|
@ -601,7 +571,6 @@ theme_files.files += $$files(resources/themes/*.png, false)
|
||||||
|
|
||||||
colorscheme_files.files += $$files(resources/colorschemes/*.scheme, false)
|
colorscheme_files.files += $$files(resources/colorschemes/*.scheme, false)
|
||||||
|
|
||||||
RESOURCES += qmake_qm_files
|
|
||||||
RESOURCES += iconsets_files
|
RESOURCES += iconsets_files
|
||||||
RESOURCES += theme_files
|
RESOURCES += theme_files
|
||||||
RESOURCES += colorscheme_files
|
RESOURCES += colorscheme_files
|
||||||
|
|
|
@ -280,6 +280,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
|
||||||
|
ExternalResource resource;
|
||||||
|
|
||||||
QLockFile lockFile(QDir::tempPath()+QDir::separator()+"RedPandaDevCppStartUp.lock");
|
QLockFile lockFile(QDir::tempPath()+QDir::separator()+"RedPandaDevCppStartUp.lock");
|
||||||
{
|
{
|
||||||
bool firstRun;
|
bool firstRun;
|
||||||
|
|
|
@ -784,3 +784,13 @@ QByteArray reformatContentUsingAstyle(const QByteArray &content, const QStringLi
|
||||||
env);
|
env);
|
||||||
return newContent;
|
return newContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExternalResource::ExternalResource() {
|
||||||
|
Q_INIT_RESOURCE(qsynedit_qmake_qmake_qm_files);
|
||||||
|
Q_INIT_RESOURCE(redpanda_qt_utils_qmake_qmake_qm_files);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExternalResource::~ExternalResource() {
|
||||||
|
Q_CLEANUP_RESOURCE(qsynedit_qmake_qmake_qm_files);
|
||||||
|
Q_CLEANUP_RESOURCE(redpanda_qt_utils_qmake_qmake_qm_files);
|
||||||
|
}
|
||||||
|
|
|
@ -204,4 +204,9 @@ std::tuple<QString, QStringList, PNonExclusiveTemporaryFileOwner> wrapCommandFor
|
||||||
|
|
||||||
std::tuple<QString, QStringList, PNonExclusiveTemporaryFileOwner> wrapCommandForTerminalEmulator(const QString &terminal, const QString &argsPattern, const QStringList &payloadArgsWithArgv0);
|
std::tuple<QString, QStringList, PNonExclusiveTemporaryFileOwner> wrapCommandForTerminalEmulator(const QString &terminal, const QString &argsPattern, const QStringList &payloadArgsWithArgv0);
|
||||||
|
|
||||||
|
struct ExternalResource {
|
||||||
|
ExternalResource();
|
||||||
|
~ExternalResource();
|
||||||
|
};
|
||||||
|
|
||||||
#endif // UTILS_H
|
#endif // UTILS_H
|
||||||
|
|
|
@ -228,11 +228,7 @@ target("RedPandaIDE")
|
||||||
|
|
||||||
-- libs
|
-- libs
|
||||||
|
|
||||||
if is_plat("windows") then
|
add_links("redpanda_qt_utils", "qsynedit")
|
||||||
add_links("redpanda_qt_utils", "qsynedit") -- xmake 2.8.6 workaround
|
|
||||||
else
|
|
||||||
add_linkgroups("redpanda_qt_utils", "qsynedit", {whole = true})
|
|
||||||
end
|
|
||||||
if is_os("windows") then
|
if is_os("windows") then
|
||||||
add_links("psapi", "shlwapi")
|
add_links("psapi", "shlwapi")
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,8 @@ contains(QMAKE_HOST.arch, x86_64):{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CONFIG += lrelease embed_translations
|
||||||
|
QMAKE_RESOURCE_FLAGS += -name $(QMAKE_TARGET)_${QMAKE_FILE_BASE}
|
||||||
|
|
||||||
win32: {
|
win32: {
|
||||||
DEFINES += _WIN32_WINNT=0x0501
|
DEFINES += _WIN32_WINNT=0x0501
|
||||||
|
|
|
@ -39,6 +39,8 @@ target("qsynedit")
|
||||||
|
|
||||||
add_ui_classes()
|
add_ui_classes()
|
||||||
|
|
||||||
|
add_files("*.ts")
|
||||||
|
|
||||||
add_includedirs(".", {interface = true})
|
add_includedirs(".", {interface = true})
|
||||||
|
|
||||||
-- do not install
|
-- do not install
|
||||||
|
|
|
@ -7,6 +7,9 @@ CONFIG += c++17
|
||||||
CONFIG += nokey
|
CONFIG += nokey
|
||||||
CONFIG += staticlib
|
CONFIG += staticlib
|
||||||
|
|
||||||
|
CONFIG += lrelease embed_translations
|
||||||
|
QMAKE_RESOURCE_FLAGS += -name $(QMAKE_TARGET)_${QMAKE_FILE_BASE}
|
||||||
|
|
||||||
win32: {
|
win32: {
|
||||||
DEFINES += _WIN32_WINNT=0x0501
|
DEFINES += _WIN32_WINNT=0x0501
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ target("redpanda_qt_utils")
|
||||||
|
|
||||||
add_files("qt_utils/utils.cpp")
|
add_files("qt_utils/utils.cpp")
|
||||||
add_moc_classes("qt_utils/charsetinfo")
|
add_moc_classes("qt_utils/charsetinfo")
|
||||||
|
add_files("*.ts")
|
||||||
add_includedirs(".", {interface = true})
|
add_includedirs(".", {interface = true})
|
||||||
|
|
||||||
-- do not install
|
-- do not install
|
||||||
|
|
43
xmake.lua
43
xmake.lua
|
@ -75,35 +75,48 @@ rule("qt.ts")
|
||||||
-- save lrelease
|
-- save lrelease
|
||||||
target:data_set("qt.lrelease", lrelease)
|
target:data_set("qt.lrelease", lrelease)
|
||||||
end)
|
end)
|
||||||
on_buildcmd_file(function (target, batchcmds, sourcefile_ts, opt)
|
on_buildcmd_files(function (target, batchcmds, sourcebatch, opt)
|
||||||
-- get tools
|
|
||||||
local lrelease = target:data("qt.lrelease")
|
local lrelease = target:data("qt.lrelease")
|
||||||
local rcc = target:data("qt.rcc")
|
local qrc_content = [[
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/i18n">
|
||||||
|
]]
|
||||||
|
for _, sourcefile_ts in ipairs(sourcebatch.sourcefiles) do
|
||||||
|
if is_host("windows") then
|
||||||
|
sourcefile_ts = sourcefile_ts:gsub("\\", "/")
|
||||||
|
end
|
||||||
-- get qm file
|
-- get qm file
|
||||||
local sourcefile_qm = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qm")
|
local sourcefile_qm = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qm")
|
||||||
local sourcefile_dir = path.directory(sourcefile_qm)
|
local sourcefile_dir = path.directory(sourcefile_qm)
|
||||||
-- prepare qrc file
|
-- build ts to qm file
|
||||||
local sourcefile_qrc = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qrc")
|
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_ts)
|
||||||
io.writefile(sourcefile_qrc, [[
|
batchcmds:mkdir(sourcefile_dir)
|
||||||
<RCC>
|
batchcmds:vrunv(lrelease, {sourcefile_ts, "-qm", sourcefile_qm})
|
||||||
<qresource prefix="/i18n">
|
|
||||||
|
qrc_content = qrc_content .. [[
|
||||||
<file alias="]] .. path.filename(sourcefile_qm) .. [[">]] .. path.absolute(sourcefile_qm) .. [[</file>
|
<file alias="]] .. path.filename(sourcefile_qm) .. [[">]] .. path.absolute(sourcefile_qm) .. [[</file>
|
||||||
|
]]
|
||||||
|
end
|
||||||
|
qrc_content = qrc_content .. [[
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
]])
|
]]
|
||||||
|
|
||||||
|
local rcc = target:data("qt.rcc")
|
||||||
|
local name = target:name() .. "_qmake_qmake_qm_files" -- same as qmake
|
||||||
|
local sourcefile_qrc = path.join(target:autogendir(), "rules", "qt", "ts", name .. ".qrc")
|
||||||
|
io.writefile(sourcefile_qrc, qrc_content)
|
||||||
-- get c++ source file for qrc
|
-- get c++ source file for qrc
|
||||||
local sourcefile_cpp = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".cpp")
|
local sourcefile_cpp = path.join(target:autogendir(), "rules", "qt", "ts", name .. ".cpp")
|
||||||
-- add objectfile
|
-- add objectfile
|
||||||
local objectfile = target:objectfile(sourcefile_cpp)
|
local objectfile = target:objectfile(sourcefile_cpp)
|
||||||
table.insert(target:objectfiles(), objectfile)
|
table.insert(target:objectfiles(), objectfile)
|
||||||
-- add commands
|
-- add commands
|
||||||
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_ts)
|
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_cpp)
|
||||||
batchcmds:mkdir(sourcefile_dir)
|
batchcmds:vrunv(rcc, {"-name", name, sourcefile_qrc, "-o", sourcefile_cpp})
|
||||||
batchcmds:vrunv(lrelease, {sourcefile_ts, "-qm", sourcefile_qm})
|
|
||||||
batchcmds:vrunv(rcc, {"-name", path.basename(sourcefile_qrc), sourcefile_qrc, "-o", sourcefile_cpp})
|
|
||||||
batchcmds:compile(sourcefile_cpp, objectfile)
|
batchcmds:compile(sourcefile_cpp, objectfile)
|
||||||
-- add deps
|
-- add deps
|
||||||
batchcmds:add_depfiles(sourcefile_ts)
|
batchcmds:add_depfiles(sourcebatch.sourcefiles)
|
||||||
batchcmds:set_depmtime(os.mtime(objectfile))
|
batchcmds:set_depmtime(os.mtime(objectfile))
|
||||||
batchcmds:set_depcache(target:dependfile(objectfile))
|
batchcmds:set_depcache(target:dependfile(objectfile))
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue