embedded qm files into qrc file

This commit is contained in:
ronoaer 2023-09-30 17:36:06 +08:00
parent 68095700a2
commit 5535b6a6e3
5 changed files with 32 additions and 24 deletions

View file

@ -50,29 +50,31 @@ endif()
qt6_add_resources(QRC ${QRC} ${CMAKE_CURRENT_LIST_DIR}/resources.qrc)
set(AMNEZIAVPN_TR_FILES
# -- i18n begin
set(CMAKE_AUTORCC ON)
set(AMNEZIAVPN_TS_FILES
${CMAKE_CURRENT_LIST_DIR}/translations/amneziavpn_ru.ts
${CMAKE_CURRENT_LIST_DIR}/translations/amneziavpn_zh_CN.ts
)
file(GLOB_RECURSE AMNEZIAVPN_TR_SOURCES *.qrc *.cpp *.h *.ui)
if ( BUILD_TRANSLATIONS )
qt_create_translation(AMNEZIAVPN_MESSAGES ${AMNEZIAVPN_TR_SOURCES} ${AMNEZIAVPN_TR_FILES})
qt_add_translation(AMNEZIAVPN_QM_FILES ${AMNEZIAVPN_TR_FILES})
add_custom_target(amnezia_messages DEPENDS ${AMNEZIAVPN_MESSAGES})
add_custom_target(amnezia_translations DEPENDS ${AMNEZIAVPN_QM_FILES} amnezia_messages)
add_dependencies(${PROJECT} amnezia_translations)
file(GLOB_RECURSE AMNEZIAVPN_TS_SOURCES *.qrc *.cpp *.h *.ui)
if (BUILD_TRANSLATIONS_AS_RESOURCES)
set(QM_FILE_LIST "")
foreach(FILE ${AMNEZIAVPN_QM_FILES})
list(APPEND QM_FILE_LIST "<file>${FILE}</file>")
endforeach()
string(REPLACE ";" "" QM_FILE_LIST ${QM_FILE_LIST})
configure_file(${CMAKE_CURRENT_LIST_DIR}/translations/translations.qrc ${CMAKE_CURRENT_LIST_DIR}/translations.qrc)
target_sources(${PROJECT} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/translations.qrc)
endif()
endif( BUILD_TRANSLATIONS )
qt_create_translation(AMNEZIAVPN_QM_FILES ${AMNEZIAVPN_TS_SOURCES} ${AMNEZIAVPN_TS_FILES})
#add_custom_target(amnezia_messages DEPENDS ${AMNEZIAVPN_MESSAGES})
#add_custom_target(amnezia_translations DEPENDS ${AMNEZIAVPN_QM_FILES} amnezia_messages)
#add_dependencies(${PROJECT} amnezia_translations)
set(QM_FILE_LIST "")
foreach(FILE ${AMNEZIAVPN_QM_FILES})
get_filename_component(QM_FILE_NAME ${FILE} NAME)
list(APPEND QM_FILE_LIST "<file>${QM_FILE_NAME}</file>")
endforeach()
string(REPLACE ";" "" QM_FILE_LIST ${QM_FILE_LIST})
configure_file(${CMAKE_CURRENT_LIST_DIR}/translations/translations.qrc.in ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc)
qt6_add_resources(QRC ${I18NQRC} ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc)
# -- i18n end
if(IOS)
#execute_process(COMMAND bash ${CMAKE_CURRENT_LIST_DIR}/scripts/run-build-cloak.sh)
@ -342,5 +344,5 @@ if(NOT IOS AND NOT ANDROID)
endif()
target_sources(${PROJECT} PRIVATE ${SOURCES} ${HEADERS} ${RESOURCES} ${QRC})
target_sources(${PROJECT} PRIVATE ${SOURCES} ${HEADERS} ${RESOURCES} ${QRC} ${I18NQRC})
qt_finalize_target(${PROJECT})

View file

@ -227,15 +227,16 @@ void AmneziaApplication::loadTranslator()
void AmneziaApplication::updateTranslator(const QLocale &locale)
{
QResource::registerResource(":/translations.qrc");
if (!m_translator->isEmpty()) {
QCoreApplication::removeTranslator(m_translator.get());
}
m_settings->setAppLanguage(locale);
QString strFileName = QString("amneziavpn")+QLatin1String("_")+locale.name()+".qm";
if (m_translator->load(strFileName, "../../../")) {
QString strFileName = QString(":/translations/amneziavpn")+QLatin1String("_")+locale.name()+".qm";
if (m_translator->load(strFileName)) {
qDebug() << "yyyyyyxxxxxxxx--------------" <<strFileName;
if (QCoreApplication::installTranslator(m_translator.get())) {
m_settings->setAppLanguage(locale);
}

View file

@ -4,7 +4,7 @@
<context>
<name>AmneziaApplication</name>
<message>
<location filename="../amnezia_application.cpp" line="299"/>
<location filename="../amnezia_application.cpp" line="300"/>
<source>Split tunneling for WireGuard is not implemented, the option was disabled</source>
<translation type="unfinished"></translation>
</message>

View file

@ -4,7 +4,7 @@
<context>
<name>AmneziaApplication</name>
<message>
<location filename="../amnezia_application.cpp" line="299"/>
<location filename="../amnezia_application.cpp" line="300"/>
<source>Split tunneling for WireGuard is not implemented, the option was disabled</source>
<translation type="unfinished"></translation>
</message>

View file

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/translations">
@QM_FILE_LIST@
</qresource>
</RCC>