From ea019f4fe450721eb932de81da6d3c38fd369e70 Mon Sep 17 00:00:00 2001 From: reionwong Date: Tue, 5 Oct 2021 19:38:08 +0800 Subject: [PATCH] Add translations --- CMakeLists.txt | 9 ++++++++- qml/Actions.qml | 5 +++++ src/application.cpp | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 371369a..57551bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -find_package(Qt5 COMPONENTS Core Quick DBus Widgets REQUIRED) +find_package(Qt5 COMPONENTS Core Quick DBus Widgets LinguistTools REQUIRED) find_package(Libmpv) qt5_add_dbus_interface(screensaver_inhibit_SRCS ./org.freedesktop.ScreenSaver.xml screensaverdbusinterface) @@ -53,3 +53,10 @@ install(FILES DESTINATION /usr/share/applications/ COMPONENT Runtime ) + +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-videoplayer translations) + +install(FILES ${QM_FILES} DESTINATION /usr/share/cutefish-videoplayer/translations) diff --git a/qml/Actions.qml b/qml/Actions.qml index 44790a2..f880320 100644 --- a/qml/Actions.qml +++ b/qml/Actions.qml @@ -101,6 +101,11 @@ QtObject { Component.onCompleted: list["playPauseAction"] = playPauseAction onTriggered: { + if (playList.playlistView.count === 0) { + fileDialog.open() + return + } + mpv.setProperty("pause", !mpv.getProperty("pause")) } } diff --git a/src/application.cpp b/src/application.cpp index 11ef370..b45607f 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -37,6 +37,9 @@ #include #include +#include +#include + #include static QApplication *createApplication(int &argc, char **argv, const QString &applicationName) @@ -66,6 +69,18 @@ Application::Application(int &argc, char **argv, const QString &applicationName) // requires the LC_NUMERIC category to be set to "C", so change it back. std::setlocale(LC_NUMERIC, "C"); + // Translations + QLocale locale; + QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-videoplayer/translations/").arg(locale.name()); + if (QFile::exists(qmFilePath)) { + QTranslator *translator = new QTranslator(QApplication::instance()); + if (translator->load(qmFilePath)) { + QApplication::installTranslator(translator); + } else { + translator->deleteLater(); + } + } + m_engine = new QQmlApplicationEngine(this); setupCommandLineParser(); registerQmlTypes();