Skip to content

Commit

Permalink
Make it translatable (#32)
Browse files Browse the repository at this point in the history
* Add translation folder and automatic translations

* Add translation infra for Qt5

* Add qt linguistic tools

* Attempt to fix Qt6 Linguistic tool

* Attempt to set target directory to fix Qt6 Linguistic tool

* Add translation for qt6 later than executable

* Do not link another time for qt6

* Clean up CI

* Unify qt5 and qt6 command to include translations

* Improve chinese translations

* Fix Qt5 search in cmake
  • Loading branch information
Inokinoki authored Nov 20, 2024
1 parent 558aeb0 commit e35f78a
Show file tree
Hide file tree
Showing 8 changed files with 1,003 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-freebsd-amd64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
os-version: ['13.2', '14.1']
os-version: ['14.1']
# Don't abort runners if a single one fails
fail-fast: false
steps:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/cmake-linux-amd64-appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
include:
- os: ubuntu-20.04
qt-ver: 5
qt-pkg: qtbase5-dev
qt-pkg: qtbase5-dev qttools5-dev
- os: ubuntu-24.04
qt-ver: 6
qt-pkg: qt6-base-dev
qt-pkg: qt6-base-dev qt6-tools-dev
runs-on: ${{matrix.os}}

steps:
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Install libefivar, libefiboot and their dev files
run: |
sudo apt update -y
sudo apt install -y libefivar-dev libefiboot-dev ${{matrix.qt-pkg}} fuse
sudo apt install -y ${{matrix.qt-pkg}} fuse
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand Down
25 changes: 23 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Network REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Network LinguistTools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Network REQUIRED)

set(PROJECT_SOURCES
Expand Down Expand Up @@ -46,18 +46,39 @@ set(PROJECT_SOURCES
qefivar/qefidpmessage.cpp
)

# Add translations files here
set(TRANSLATIONS
translations/app_en.ts
translations/app_fr.ts
translations/app_zh.ts
)
set_source_files_properties(
${TRANSLATIONS} PROPERTIES
# Set OUTPUT_LOCATION to the directory where the .qm files should be generated in Qt5
OUTPUT_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/translations
# Set TARGET_DIRECTORY to the directory where the .qm files should be generated in Qt6
TARGET_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/translations
)

if(WIN32)
list(PREPEND PROJECT_SOURCES WIN32)
set(CMAKE_EXE_LINKER_FLAGS "/MANIFESTUAC:\"level='requireAdministrator'\"")
endif()

# TODO: Set the linguist tools to optional
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(QEFIEntryManager
find_package(Qt6LinguistTools REQUIRED)
qt_create_translation(QM_FILES ${TRANSLATIONS} ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(QEFIEntryManager
${PROJECT_SOURCES}
translations/translations.qrc
)
else()
find_package(Qt5LinguistTools REQUIRED)
qt5_create_translation(QM_FILES ${TRANSLATIONS} ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(QEFIEntryManager
${PROJECT_SOURCES}
translations/translations.qrc
)
endif()

Expand Down
16 changes: 15 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "mainwindow.h"

#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include <QResource>
#include <QTranslator>
#include <qefientrystaticlist.h>
#include <qefi.h>

Expand All @@ -11,7 +14,18 @@ int main(int argc, char *argv[])
a.setDesktopFileName("qefientrymanager");
a.setWindowIcon(QIcon("../cc.inoki.qefientrymanager.png"));

if (!qefi_is_available() || !qefi_has_privilege()) {
QTranslator translator;
if (translator.load(QLocale(), QStringLiteral("app"), QStringLiteral("_"), QStringLiteral(":/translations"), QStringLiteral(".qm")))
{
a.installTranslator(&translator);
}
else
{
qDebug() << "Failed to load translation";
}

if (!qefi_is_available() || !qefi_has_privilege())
{
QMessageBox::critical(nullptr, QObject::tr("Error"),
QObject::tr("Permission insufficient or no EFI environment"));
return 1;
Expand Down
Loading

0 comments on commit e35f78a

Please sign in to comment.