Skip to content

Commit

Permalink
embedded qm files into qrc file
Browse files Browse the repository at this point in the history
  • Loading branch information
ronoaer committed Sep 30, 2023
1 parent 6809570 commit 5535b6a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
42 changes: 22 additions & 20 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>${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 )
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 "<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)
Expand Down Expand Up @@ -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})
7 changes: 4 additions & 3 deletions client/amnezia_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion client/translations/amneziavpn_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion client/translations/amneziavpn_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions client/translations/translations.qrc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/translations">
@QM_FILE_LIST@
</qresource>
</RCC>

0 comments on commit 5535b6a

Please sign in to comment.