Skip to content

Commit

Permalink
Support translations for strings from libopenrazer
Browse files Browse the repository at this point in the history
z3ntu committed Jun 1, 2024

Verified

This commit was signed with the committer’s verified signature.
ajlouie Aaron Louie
1 parent c949eb4 commit 515398b
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/devicewidget/ledwidget.cpp
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@

#include "util.h"

#include <QApplication>
#include <QColorDialog>
#include <QComboBox>
#include <QHBoxLayout>
@@ -22,7 +23,8 @@ LedWidget::LedWidget(QWidget *parent, libopenrazer::Led *led)
auto *verticalLayout = new QVBoxLayout(this);

// Set appropriate text
QLabel *lightingLocationLabel = new QLabel(tr("Effect %1").arg(libopenrazer::ledIdToStringTable.value(led->getLedId(), "error")));
QString lightingLocation = qApp->translate("libopenrazer", libopenrazer::ledIdToStringTable.value(led->getLedId(), "error"));
QLabel *lightingLocationLabel = new QLabel(tr("Effect %1").arg(lightingLocation));

auto *lightingHBox = new QHBoxLayout();
verticalLayout->addWidget(lightingLocationLabel);
@@ -51,7 +53,7 @@ LedWidget::LedWidget(QWidget *parent, libopenrazer::Led *led)
// Add items from capabilities
for (auto ledFx : libopenrazer::ledFxList) {
if (led->hasFx(ledFx.getIdentifier())) {
comboBox->addItem(ledFx.getDisplayString(), QVariant::fromValue(ledFx));
comboBox->addItem(qApp->translate("libopenrazer", ledFx.getDisplayString()), QVariant::fromValue(ledFx));
// Set selection to current effect
if (ledFx.getIdentifier() == currentEffect) {
comboBox->setCurrentIndex(comboBox->count() - 1);
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -31,9 +31,14 @@ int main(int argc, char *argv[])
QString translationsDirectory = QString(RAZERGENIE_DATADIR) + "/translations/";
#endif
bool ret = translator.load(QLocale::system(), QString(), QString(), translationsDirectory);
qDebug() << "Translation loaded:" << ret;
qDebug() << "RazerGenie translation loaded:" << ret;
app.installTranslator(&translator);

QTranslator libopenrazerTranslator;
ret = libopenrazer::loadTranslations(&libopenrazerTranslator);
qDebug() << "libopenrazer translations loaded:" << ret;
app.installTranslator(&libopenrazerTranslator);

RazerGenie w;
w.show();

0 comments on commit 515398b

Please sign in to comment.