use qt resource system's recommended approach for translation files (v2) (#452)
This commit is contained in:
parent
f14bc593db
commit
dc589d4745
|
@ -0,0 +1 @@
|
||||||
|
QMAKEFEATURES += $$PWD
|
|
@ -3,6 +3,10 @@ QT += core gui printsupport network svg xml widgets
|
||||||
CONFIG += c++17
|
CONFIG += c++17
|
||||||
CONFIG += nokey
|
CONFIG += nokey
|
||||||
|
|
||||||
|
win32: CONFIG += lrelease_dosdevice
|
||||||
|
else: CONFIG += lrelease
|
||||||
|
CONFIG += 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 +543,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 +564,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 +573,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,10 @@ contains(QMAKE_HOST.arch, x86_64):{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
win32: CONFIG += lrelease_dosdevice
|
||||||
|
else: CONFIG += lrelease
|
||||||
|
CONFIG += 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,11 @@ CONFIG += c++17
|
||||||
CONFIG += nokey
|
CONFIG += nokey
|
||||||
CONFIG += staticlib
|
CONFIG += staticlib
|
||||||
|
|
||||||
|
win32: CONFIG += lrelease_dosdevice
|
||||||
|
else: CONFIG += lrelease
|
||||||
|
CONFIG += 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
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
# Automatically generate .qm files out of .ts files in TRANSLATIONS and
|
||||||
|
# EXTRA_TRANSLATIONS.
|
||||||
|
#
|
||||||
|
# If embed_translations is enabled, the generated .qm files are made available
|
||||||
|
# in the resource system under :/i18n/.
|
||||||
|
#
|
||||||
|
# Otherwise, the .qm files are available in the build directory in LRELEASE_DIR.
|
||||||
|
# They can also be automatically installed by setting QM_FILES_INSTALL_PATH.
|
||||||
|
|
||||||
|
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
|
||||||
|
QMAKE_EXTRA_COMPILERS += lrelease
|
||||||
|
|
||||||
|
# redpanda-cpp: fix dos device compatibility.
|
||||||
|
# When building in different drive letter from the source, the dependency `*.qm` for generating
|
||||||
|
# `qmake_qm_files.cpp` is missing in makefile. Adding `target_predeps` forces correct build order.
|
||||||
|
lrelease.CONFIG += target_predeps
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
embed_translations {
|
||||||
|
qmake_qm_files.files = $$QM_FILES
|
||||||
|
qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR
|
||||||
|
qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX
|
||||||
|
RESOURCES += qmake_qm_files
|
||||||
|
} else {
|
||||||
|
!isEmpty(QM_FILES_INSTALL_PATH) {
|
||||||
|
qm_files.files = $$QM_FILES
|
||||||
|
qm_files.path = $$QM_FILES_INSTALL_PATH
|
||||||
|
qm_files.CONFIG = no_check_exist
|
||||||
|
INSTALLS += qm_files
|
||||||
|
}
|
||||||
|
lrelease.CONFIG += target_predeps no_clean
|
||||||
|
}
|
51
xmake.lua
51
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 = [[
|
||||||
-- get qm file
|
|
||||||
local sourcefile_qm = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qm")
|
|
||||||
local sourcefile_dir = path.directory(sourcefile_qm)
|
|
||||||
-- prepare qrc file
|
|
||||||
local sourcefile_qrc = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qrc")
|
|
||||||
io.writefile(sourcefile_qrc, [[
|
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/i18n">
|
<qresource prefix="/i18n">
|
||||||
<file alias="]] .. path.filename(sourcefile_qm) .. [[">]] .. path.absolute(sourcefile_qm) .. [[</file>
|
]]
|
||||||
</qresource>
|
for _, sourcefile_ts in ipairs(sourcebatch.sourcefiles) do
|
||||||
|
if is_host("windows") then
|
||||||
|
sourcefile_ts = sourcefile_ts:gsub("\\", "/")
|
||||||
|
end
|
||||||
|
-- get qm file
|
||||||
|
local sourcefile_qm = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qm")
|
||||||
|
local sourcefile_dir = path.directory(sourcefile_qm)
|
||||||
|
-- build ts to qm file
|
||||||
|
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_ts)
|
||||||
|
batchcmds:mkdir(sourcefile_dir)
|
||||||
|
batchcmds:vrunv(lrelease, {sourcefile_ts, "-qm", sourcefile_qm})
|
||||||
|
|
||||||
|
qrc_content = qrc_content .. [[
|
||||||
|
<file alias="]] .. path.filename(sourcefile_qm) .. [[">]] .. path.absolute(sourcefile_qm) .. [[</file>
|
||||||
|
]]
|
||||||
|
end
|
||||||
|
qrc_content = qrc_content .. [[
|
||||||
|
</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