[vlc-commits] qt: make player identifiers translatable
Fatih Uzunoglu
git at videolan.org
Tue Apr 6 09:55:07 UTC 2021
vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Fri Apr 2 01:22:34 2021 +0300| [eb9b3a03783aff3ee4af9c566aaa1439e2ebe9d8] | committer: Pierre Lamot
qt: make player identifiers translatable
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=eb9b3a03783aff3ee4af9c566aaa1439e2ebe9d8
---
modules/gui/qt/player/player_controlbar_model.cpp | 23 +++++++++++++++++++++--
modules/gui/qt/player/player_controlbar_model.hpp | 8 ++++++++
po/POTFILES.in | 2 ++
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/modules/gui/qt/player/player_controlbar_model.cpp b/modules/gui/qt/player/player_controlbar_model.cpp
index cc36cb2228..ba55088597 100644
--- a/modules/gui/qt/player/player_controlbar_model.cpp
+++ b/modules/gui/qt/player/player_controlbar_model.cpp
@@ -21,8 +21,15 @@
#include <QMetaEnum>
#include <QJSEngine>
+#include "qt.hpp"
#include "control_list_model.hpp"
+decltype (PlayerControlbarModel::playerIdentifierDictionary)
+ PlayerControlbarModel::playerIdentifierDictionary {
+ {Mainplayer, N_("Mainplayer")},
+ {Miniplayer, N_("Miniplayer")}
+ };
+
QJSValue PlayerControlbarModel::getPlaylistIdentifierListModel(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
@@ -35,8 +42,20 @@ QJSValue PlayerControlbarModel::getPlaylistIdentifierListModel(QQmlEngine *engin
{
QJSValue obj = scriptEngine->newObject();
- obj.setProperty("identifier", metaEnum.value(i));
- obj.setProperty("name", metaEnum.key(i));
+ const int val = metaEnum.value(i);
+ obj.setProperty("identifier", val);
+
+ QString key;
+ if ( playerIdentifierDictionary.contains(static_cast<PlayerControlbarModel::PlayerIdentifier>(i)) )
+ {
+ key = qtr( playerIdentifierDictionary[static_cast<PlayerControlbarModel::PlayerIdentifier>(i)] );
+ }
+ else
+ {
+ key = metaEnum.key(i);
+ }
+
+ obj.setProperty("name", key);
array.setProperty(i, obj);
}
diff --git a/modules/gui/qt/player/player_controlbar_model.hpp b/modules/gui/qt/player/player_controlbar_model.hpp
index 3bf7e4c08c..a6d3b3389e 100644
--- a/modules/gui/qt/player/player_controlbar_model.hpp
+++ b/modules/gui/qt/player/player_controlbar_model.hpp
@@ -21,6 +21,8 @@
#include <QObject>
#include <QJSValue>
+#include <QMap>
+
#include <array>
class ControlListModel;
@@ -40,6 +42,9 @@ public:
// add its identifier in this enum and set QML buttons layout
// identifier to it. Such as `property int identifier =
// PlayerControlbarModel.Mainplayer`.
+ // To make it translatable, add a corresponding entry to
+ // the static member playerIdentifierDictionary which is
+ // initalized in the source file.
enum PlayerIdentifier {
Mainplayer = 0,
Miniplayer
@@ -51,6 +56,9 @@ public:
// Thanks to MOC, adding an entry to this enum
// is enough for the editor to consider the
// added entry without any other modification.
+ // (except for the translation)
+
+ static const QMap<PlayerIdentifier, const char*> playerIdentifierDictionary;
static QJSValue getPlaylistIdentifierListModel(class QQmlEngine *engine,
class QJSEngine *scriptEngine);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2631ce0715..3128f9f62a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -799,6 +799,8 @@ modules/gui/qt/widgets/native/searchlineedit.hpp
modules/gui/qt/util/singleton.hpp
modules/gui/qt/util/validators.cpp
modules/gui/qt/util/validators.hpp
+modules/gui/qt/player/player_controlbar_model.cpp
+modules/gui/qt/player/player_controlbar_model.hpp
modules/gui/qt/dialogs/dialogs/qml/CustomDialog.qml
modules/gui/qt/dialogs/dialogs/qml/Dialogs.qml
modules/gui/qt/dialogs/dialogs/qml/WindowDialog.qml
More information about the vlc-commits
mailing list