Skip to content

Commit

Permalink
fix build with linguist support
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanChain committed Jan 31, 2025
1 parent 6087cb6 commit 861ed92
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: |
mkdir build
cd build
qt-cmake -DCMAKE_BUILD_TYPE=MinSizeRel ..
qt-cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DWITH_TRANSLATIONS=1 ..
cmake --build . --parallel --config Release
- name: Packing
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
run: |
mkdir build
cd build
qt-cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" ..
qt-cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DWITH_TRANSLATIONS=1 -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" ..
cmake --build . --parallel
- uses: apple-actions/import-codesign-certs@v3
Expand Down Expand Up @@ -142,13 +142,13 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake qt6-base-dev qt6-multimedia-dev libxss-dev
sudo apt-get install -y cmake qt6-base-dev qt6-multimedia-dev qt6-tools-dev libxss-dev
- name: Build Project
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DSANE_MAKE_DEB=1 ..
cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DWITH_TRANSLATIONS=1 -DSANE_MAKE_DEB=1 ..
cmake --build . --parallel
- name: Packing
Expand Down Expand Up @@ -193,7 +193,7 @@ jobs:
- name: Install dependencies
run: |
apt-get update
apt-get install -y nodejs g++ cmake qt6-base-dev qt6-multimedia-dev qt6-wayland-dev
apt-get install -y nodejs g++ cmake qt6-base-dev qt6-multimedia-dev qt6-tools-dev qt6-wayland-dev
- name: Install additional dependencies
if: matrix.tag == 'trixie'
Expand All @@ -203,7 +203,7 @@ jobs:
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DSANE_MAKE_DEB=1 ..
cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DWITH_TRANSLATIONS=1 -DSANE_MAKE_DEB=1 ..
cmake --build . --parallel
- name: Packing
Expand Down
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ endif()

include(GNUInstallDirs)

find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia LinguistTools)
find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia)

file(GLOB PROJECT_SOURCES "src/*.cpp" "src/*.h" "src/*.ui" "resources/index.qrc")

Expand All @@ -34,12 +34,16 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND PROJECT_SOURCES ${PROJECT_SOURCES_WINDOWS} ${RESOURCE_WINDOWS})
endif()

qt_standard_project_setup(I18N_TRANSLATED_LANGUAGES en zh)
qt_add_translations(sane-break TS_FILE_DIR resources/translations)
qt_add_executable(sane-break
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
option(WITH_TRANSLATIONS "Enable translations" OFF)
if(WITH_TRANSLATIONS)
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
file(GLOB TS_FILES "resources/translations/*.ts")
qt_add_translations(sane-break TS_FILES ${TS_FILES})
endif()

target_include_directories(sane-break PRIVATE "src" ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(sane-break PRIVATE Qt6::Widgets Qt6::Multimedia)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ sudo cmake --install .
The above command will automatically enable X11 or Wayland support based on libraries found.
You can disable X11 or Wayland support using the option `-DAUTO_ENABLE_X11=OFF` or `-DAUTO_ENABLE_WAYLAND=OFF` during `cmake`.

To build with translations, add `-DWITH_TRANSLATIONS=1` and install `qt6-tools` package (name may vary).

##### Arch-based distros

For Arch-based distros, it's recommended to directly install the AUR package:
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) {

QTranslator translator;
if (SanePreferences::language->get().length() > 0) {
if (translator.load("sane-break_" + SanePreferences::language->get(), ":/i18n"))
if (translator.load(SanePreferences::language->get(), ":/i18n"))
a.installTranslator(&translator);
} else {
if (translator.load(QLocale::system(), "sane-break", "_", ":/i18n"))
Expand Down
2 changes: 1 addition & 1 deletion src/welcome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void WelcomeWindow::onLanguageSelect() {
if (translator->load(QLocale::system(), "sane-break", "_", ":/i18n"))
qApp->installTranslator(translator);
} else {
if (translator->load("sane-break_" + language, ":/i18n")) {
if (translator->load(language, ":/i18n")) {
qApp->installTranslator(translator);
}
}
Expand Down

0 comments on commit 861ed92

Please sign in to comment.