From c6b13dd919a926aef05115dae913edb62cc5db2a Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Mon, 4 Dec 2023 21:03:36 -0600 Subject: [PATCH] Prep for translations --- CMakeLists.txt | 69 ++++++---- README.md | 26 ++++ gen_ts.sh | 11 ++ src/main.cpp | 12 ++ src/translations.qrc | 7 + .../lubuntu-installer-prompt_en_US.ts | 123 ++++++++++++++++++ .../lubuntu-installer-prompt_es_ES.ts | 123 ++++++++++++++++++ .../lubuntu-installer-prompt_zh_CN.ts | 123 ++++++++++++++++++ 8 files changed, 471 insertions(+), 23 deletions(-) create mode 100755 gen_ts.sh create mode 100644 src/translations.qrc create mode 100644 src/translations/lubuntu-installer-prompt_en_US.ts create mode 100644 src/translations/lubuntu-installer-prompt_es_ES.ts create mode 100644 src/translations/lubuntu-installer-prompt_zh_CN.ts diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b79428..cdda9d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,38 +1,61 @@ -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 3.16) -project(lubuntu-installer-prompt VERSION 1.0.0 LANGUAGES CXX) +project(lubuntu-installer-prompt VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) -# Find the required Qt and KDE packages find_package(ECM REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) -find_package(Qt5 REQUIRED COMPONENTS Core Widgets Network) +find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Widgets Network LinguistTools) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network LinguistTools) find_package(KF5 REQUIRED COMPONENTS NetworkManagerQt Notifications) -# Set the CMAKE variables for automatic code generation with Qt -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(TS_FILES + src/translations/lubuntu-installer-prompt_en_US.ts + src/translations/lubuntu-installer-prompt_es_ES.ts + src/translations/lubuntu-installer-prompt_zh_CN.ts +) -# Specify project source files -include_directories(${PROJECT_SOURCE_DIR}/src) -file(GLOB PROJECT_SOURCES - "${PROJECT_SOURCE_DIR}/src/*.cpp" - "${PROJECT_SOURCE_DIR}/src/*.h" - "${PROJECT_SOURCE_DIR}/src/*.ui" +set(PROJECT_SOURCES + src/main.cpp + src/installerprompt.cpp + src/installerprompt.h + src/installerprompt.ui + src/resource.qrc ) -# Add executable target with project source files -add_executable(lubuntu-installer-prompt ${PROJECT_SOURCES} src/resource.qrc) +set(TRANSLATION_RESOURCES "src/translations.qrc") + +configure_file(${TRANSLATION_RESOURCES} translations.qrc COPYONLY) +qt5_add_translation(QM_FILES ${TS_FILES}) +qt5_add_resources(QM_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) -# Link libraries with the executable target -target_link_libraries(lubuntu-installer-prompt Qt5::Widgets Qt5::Network KF5::NetworkManagerQt KF5::Notifications) -target_link_libraries(lubuntu-installer-prompt Qt5::Widgets KF5::NetworkManagerQt KF5::Notifications) +add_custom_target(translations ALL DEPENDS ${QM_FILES}) + +add_executable(lubuntu-installer-prompt + ${PROJECT_SOURCES} + ${QM_RESOURCES} +) -install(TARGETS lubuntu-installer-prompt DESTINATION bin) +add_dependencies(lubuntu-installer-prompt translations) + +target_link_libraries(lubuntu-installer-prompt PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt5::Network KF5::NetworkManagerQt KF5::Notifications) + +install(TARGETS lubuntu-installer-prompt + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) install(PROGRAMS "scripts/lubuntu-installer" DESTINATION libexec) install(PROGRAMS "scripts/start-lubuntu-live-env" DESTINATION bin) -install(FILES "img/background.png" DESTINATION share/lubuntu/installer-prompt) install(FILES "lubuntu-live-environment.desktop" DESTINATION share/xsessions) install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink /etc/xdg/xdg-Lubuntu /etc/xdg/xdg-lubuntu-live-environment)") + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(lubuntu-installer-prompt) +endif() diff --git a/README.md b/README.md index 22b0058..20c1127 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,29 @@ This section serves to explain how lubuntu-installer-prompt's various components 10. If Calamares closes, the installer prompt detects this and exits. 11. When the installer prompt exits, start-lubuntu-live-env kills Openbox, then runs startlxqt. 12. If "Try Lubuntu" is clicked, steps 10 and 11 are executed immediately. + +## Translations + +Run the `gen_ts.sh` script after making any code modifications to ensure that the translations files are up-to-date for translators to work on. + +To add a new language to be translated: + +* Open the `gen_ts.sh` script and add the locale code for the new language to the `langList` array. +* Run the script after doing this - a new template .ts file will be generated under `src/translations/`. +* Next, add the new template file to the `TS_FILES` list in `CMakeLists.txt` - it will be named `src/translations/lubuntu-installer-prompt-locale_CODE.ts`, where `locale_CODE` is the locale code of the added language. +* Finally, add a line in the src/translations.qrc resource file to include the new translation file. The line should look like `lubuntu-installer-prompt_locale_CODE.qm`, where `locale_CODE` is the locale code of the added language. This line should go inside the `` tag. + +For instance, if I were to add Chinese to the list of languages that could be translated into, I would do this: + + vim gen_ts.sh + # add this code to the langList array: + # 'zh_CN' + ./gen_ts.sh + vim CMakeLists.txt + # add this line to the TS_FILES list: + # src/translations/lubuntu-installer-prompt_zh_CN.ts + vim src/translations.qrc + # add this line to the list of file resources: + # lubuntu-installer-prompt_zh_CN.qm + +The program will now pick up the added language at build time. Any translations added to the newly created .ts file will be shown to program users who select the new language. diff --git a/gen_ts.sh b/gen_ts.sh new file mode 100755 index 0000000..c20b8e3 --- /dev/null +++ b/gen_ts.sh @@ -0,0 +1,11 @@ +#!/bin/bash +langList=('en_US' 'es_ES' 'zh_CN') +for i in ${langList[@]}; do + targetFile="src/translations/lubuntu-installer-prompt_$i.ts" + if [ ! -e $targetFile ]; then + echo "" > $targetFile + echo "" >> $targetFile + echo "" >> $targetFile + fi +done +lupdate src/*.cpp src/*.h src/*.ui -ts src/translations/* diff --git a/src/main.cpp b/src/main.cpp index 8ac796c..b710a5b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,22 @@ #include "installerprompt.h" #include #include +#include int main(int argc, char *argv[]) { QApplication app(argc, argv); + + QTranslator translator; + const QStringList uiLanguages = QLocale::system().uiLanguages(); + for (const QString &locale : uiLanguages) { + const QString baseName = QLocale(locale).name(); + if (translator.load(":/i18n/" + baseName)) { + app.installTranslator(&translator); + break; + } + } + QList ws; // Iterate through all available screens diff --git a/src/translations.qrc b/src/translations.qrc new file mode 100644 index 0000000..7674ed5 --- /dev/null +++ b/src/translations.qrc @@ -0,0 +1,7 @@ + + + lubuntu-installer-prompt_en_US.qm + lubuntu-installer-prompt_es_ES.qm + lubuntu-installer-prompt_zh_CN.qm + + diff --git a/src/translations/lubuntu-installer-prompt_en_US.ts b/src/translations/lubuntu-installer-prompt_en_US.ts new file mode 100644 index 0000000..f7d6e2c --- /dev/null +++ b/src/translations/lubuntu-installer-prompt_en_US.ts @@ -0,0 +1,123 @@ + + + + + InstallerPrompt + + + Try or Install Lubuntu + + + + + Select Your Language: + + + + + Select a Wi-Fi Network: + + + + + + Connect + + + + + (For advanced network configuration, select "Try Lubuntu") + + + + + <html><head/><body><p><span style=" font-size:12pt;">Try Lubuntu without installing it on your system. Allows you to use programs, browse the Web, and even temporarily install apps without modifying your system. Changes made within the live environment will be lost when the computer shuts down.</span></p></body></html> + + + + + Try Lubuntu + + + + + <html><head/><body><p><span style=" font-size:12pt;">Install Lubuntu onto your system. You can install Lubuntu by itself, or alongside an existing operating system.</span></p></body></html> + + + + + Install Lubuntu + + + + + Connection Status: + + + + + Error + + + + + Background image cannot be loaded. + + + + + Not Connected + + + + + Connected + + + + + Connecting... + + + + + Disconnecting... + + + + + Unknown Status + + + + + Enter Wi-Fi Password for %1: + + + + + Wrong Wi-Fi password for %1. Try again: + + + + + Connection Failed + + + + + Unable to connect to the network. + + + + + WiFi Not Available + + + + + No WiFi devices were found on this system. + + + + diff --git a/src/translations/lubuntu-installer-prompt_es_ES.ts b/src/translations/lubuntu-installer-prompt_es_ES.ts new file mode 100644 index 0000000..c117128 --- /dev/null +++ b/src/translations/lubuntu-installer-prompt_es_ES.ts @@ -0,0 +1,123 @@ + + + + + InstallerPrompt + + + Try or Install Lubuntu + + + + + Select Your Language: + + + + + Select a Wi-Fi Network: + + + + + + Connect + + + + + (For advanced network configuration, select "Try Lubuntu") + + + + + <html><head/><body><p><span style=" font-size:12pt;">Try Lubuntu without installing it on your system. Allows you to use programs, browse the Web, and even temporarily install apps without modifying your system. Changes made within the live environment will be lost when the computer shuts down.</span></p></body></html> + + + + + Try Lubuntu + + + + + <html><head/><body><p><span style=" font-size:12pt;">Install Lubuntu onto your system. You can install Lubuntu by itself, or alongside an existing operating system.</span></p></body></html> + + + + + Install Lubuntu + + + + + Connection Status: + + + + + Error + + + + + Background image cannot be loaded. + + + + + Not Connected + + + + + Connected + + + + + Connecting... + + + + + Disconnecting... + + + + + Unknown Status + + + + + Enter Wi-Fi Password for %1: + + + + + Wrong Wi-Fi password for %1. Try again: + + + + + Connection Failed + + + + + Unable to connect to the network. + + + + + WiFi Not Available + + + + + No WiFi devices were found on this system. + + + + diff --git a/src/translations/lubuntu-installer-prompt_zh_CN.ts b/src/translations/lubuntu-installer-prompt_zh_CN.ts new file mode 100644 index 0000000..ccb3a91 --- /dev/null +++ b/src/translations/lubuntu-installer-prompt_zh_CN.ts @@ -0,0 +1,123 @@ + + + + + InstallerPrompt + + + Try or Install Lubuntu + + + + + Select Your Language: + + + + + Select a Wi-Fi Network: + + + + + + Connect + + + + + (For advanced network configuration, select "Try Lubuntu") + + + + + <html><head/><body><p><span style=" font-size:12pt;">Try Lubuntu without installing it on your system. Allows you to use programs, browse the Web, and even temporarily install apps without modifying your system. Changes made within the live environment will be lost when the computer shuts down.</span></p></body></html> + + + + + Try Lubuntu + + + + + <html><head/><body><p><span style=" font-size:12pt;">Install Lubuntu onto your system. You can install Lubuntu by itself, or alongside an existing operating system.</span></p></body></html> + + + + + Install Lubuntu + + + + + Connection Status: + + + + + Error + + + + + Background image cannot be loaded. + + + + + Not Connected + + + + + Connected + + + + + Connecting... + + + + + Disconnecting... + + + + + Unknown Status + + + + + Enter Wi-Fi Password for %1: + + + + + Wrong Wi-Fi password for %1. Try again: + + + + + Connection Failed + + + + + Unable to connect to the network. + + + + + WiFi Not Available + + + + + No WiFi devices were found on this system. + + + +