From 5535b6a6e3cdd83db8cb993d34ab71485a500cb9 Mon Sep 17 00:00:00 2001 From: ronoaer Date: Sat, 30 Sep 2023 17:36:06 +0800 Subject: [PATCH] embedded qm files into qrc file --- client/CMakeLists.txt | 42 +++++++++++++------------ client/amnezia_application.cpp | 7 +++-- client/translations/amneziavpn_ru.ts | 2 +- client/translations/amneziavpn_zh_CN.ts | 2 +- client/translations/translations.qrc.in | 5 +++ 5 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 client/translations/translations.qrc.in diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index f149e2045..21f4513ee 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -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) - - if (BUILD_TRANSLATIONS_AS_RESOURCES) - set(QM_FILE_LIST "") - foreach(FILE ${AMNEZIAVPN_QM_FILES}) - list(APPEND QM_FILE_LIST "${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 ) +file(GLOB_RECURSE AMNEZIAVPN_TS_SOURCES *.qrc *.cpp *.h *.ui) + +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 "${QM_FILE_NAME}") +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}) diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index d87f326e9..6203e3af9 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -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--------------" <setAppLanguage(locale); } diff --git a/client/translations/amneziavpn_ru.ts b/client/translations/amneziavpn_ru.ts index e6c60a33a..82393e389 100644 --- a/client/translations/amneziavpn_ru.ts +++ b/client/translations/amneziavpn_ru.ts @@ -4,7 +4,7 @@ AmneziaApplication - + Split tunneling for WireGuard is not implemented, the option was disabled diff --git a/client/translations/amneziavpn_zh_CN.ts b/client/translations/amneziavpn_zh_CN.ts index 257a3378c..c70b0f753 100644 --- a/client/translations/amneziavpn_zh_CN.ts +++ b/client/translations/amneziavpn_zh_CN.ts @@ -4,7 +4,7 @@ AmneziaApplication - + Split tunneling for WireGuard is not implemented, the option was disabled diff --git a/client/translations/translations.qrc.in b/client/translations/translations.qrc.in new file mode 100644 index 000000000..f49df6615 --- /dev/null +++ b/client/translations/translations.qrc.in @@ -0,0 +1,5 @@ + + + @QM_FILE_LIST@ + +