From 8e922e41c3f460e59112337045b638d99785c0b4 Mon Sep 17 00:00:00 2001 From: reionwong Date: Tue, 27 Jul 2021 23:02:51 +0800 Subject: [PATCH] Add translations --- CMakeLists.txt | 27 ++++++++++++++++++++++++++- screenlocker/main.cpp | 15 +++++++++++++++ translations/en_US.ts | 27 +++++++++++++++++++++++++++ translations/zh_CN.ts | 27 +++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 translations/en_US.ts create mode 100644 translations/zh_CN.ts diff --git a/CMakeLists.txt b/CMakeLists.txt index b0f071e..a40b5a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ include(CheckIncludeFiles) include(CheckSymbolExists) include(FeatureSummary) -find_package(Qt5 COMPONENTS Core DBus Widgets X11Extras Quick REQUIRED) +find_package(Qt5 COMPONENTS Core DBus Widgets X11Extras Quick LinguistTools REQUIRED) find_package(X11) # ----------- Check -------------------- @@ -64,3 +64,28 @@ add_subdirectory(screenlocker) add_subdirectory(checkpass) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) + + +# Get the installation directory from qmake +get_target_property(QT_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE} IMPORTED_LOCATION) +if(NOT QT_QMAKE_EXECUTABLE) + message(FATAL_ERROR "qmake is not found.") +endif() + +execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_QML + OUTPUT_VARIABLE INSTALL_QMLDIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) +if(INSTALL_QMLDIR) + message(STATUS "qml directory:" "${INSTALL_QMLDIR}") +else() + message(FATAL_ERROR "qml directory cannot be detected.") +endif() + +# Install translations +file(GLOB TS_FILES translations/*.ts) +qt5_create_translation(QM_FILES ${TS_FILES}) +add_custom_target(translations DEPENDS ${QM_FILES} SOURCES ${TS_FILES}) +add_dependencies(cutefish-screenlocker translations) +install(FILES ${QM_FILES} DESTINATION /usr/share/cutefish-screenlocker/translations) + diff --git a/screenlocker/main.cpp b/screenlocker/main.cpp index 22fbf04..15ab5f3 100644 --- a/screenlocker/main.cpp +++ b/screenlocker/main.cpp @@ -1,8 +1,23 @@ #include "application.h" +#include +#include int main(int argc, char *argv[]) { Application app(argc, argv); + + // Translations + QLocale locale; + QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-screenlocker/translations/").arg(locale.name()); + if (QFile::exists(qmFilePath)) { + QTranslator *translator = new QTranslator(app.instance()); + if (translator->load(qmFilePath)) { + app.installTranslator(translator); + } else { + translator->deleteLater(); + } + } + app.setQuitOnLastWindowClosed(false); app.initialViewSetup(); return app.exec(); diff --git a/translations/en_US.ts b/translations/en_US.ts new file mode 100644 index 0000000..402448d --- /dev/null +++ b/translations/en_US.ts @@ -0,0 +1,27 @@ + + + + + LockScreen + + + Password + + + + + Unlock + + + + + Please enter your password + + + + + Unlocking failed + + + + diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts new file mode 100644 index 0000000..32a88b9 --- /dev/null +++ b/translations/zh_CN.ts @@ -0,0 +1,27 @@ + + + + + LockScreen + + + Password + 密码 + + + + Unlock + 解锁 + + + + Please enter your password + 请输入您的密码 + + + + Unlocking failed + 解锁失败 + + +