Skip to content

Commit 2e02f1d

Browse files
Chr1sNoCalcProgrammer1
authored andcommitted
Adding ability to switch language files at runtime to resolve #2743
* Removing .qm files from Windows build as they are inbuilt as of a7adfe2 * Moving translation change code to the OpenRGBSettingsPage * Adding a changeEvent() to applicable Widgets to facilitate language updates * Workaround added to TabLabel to accomodate translation context origin * Added zh_TW locale to OpenRGB.pro * Updated all translations to include the latest untranslated strings
1 parent 530d667 commit 2e02f1d

86 files changed

Lines changed: 6075 additions & 5125 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitlab-ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,6 @@ before_script:
547547
- Pop-Location
548548
- _fold_final_
549549

550-
- _fold_start_ 'Generate qm files'
551-
- .\_qt\5.15.0\msvc2019\bin\lrelease OpenRGB.pro
552-
- _fold_final_
553-
554550
- _fold_start_ 'run qmake and generate the msvc nmake makefile'
555551
- mkdir _build; cd _build
556552
- ..\_qt\5.15.0\msvc2019\bin\qmake ..\OpenRGB.pro
@@ -627,10 +623,6 @@ before_script:
627623
- Pop-Location
628624
- _fold_final_
629625

630-
- _fold_start_ 'Generate qm files'
631-
- .\_qt\5.15.0\msvc2019_64\bin\lrelease OpenRGB.pro
632-
- _fold_final_
633-
634626
- _fold_start_ 'run qmake and generate the msvc nmake makefile'
635627
- mkdir _build; cd _build
636628
- ..\_qt\5.15.0\msvc2019_64\bin\qmake ..\OpenRGB.pro

OpenRGB.pro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,15 +1263,16 @@ RESOURCES +=
12631263
qt/resources.qrc \
12641264

12651265
TRANSLATIONS += \
1266+
qt/i18n/OpenRGB_de.ts \
12661267
qt/i18n/OpenRGB_en.ts \
12671268
qt/i18n/OpenRGB_en_AU.ts \
12681269
qt/i18n/OpenRGB_en_GB.ts \
1269-
qt/i18n/OpenRGB_de.ts \
12701270
qt/i18n/OpenRGB_es.ts \
12711271
qt/i18n/OpenRGB_fr.ts \
12721272
qt/i18n/OpenRGB_ru.ts \
1273-
qt/i18n/OpenRGB_zh.ts \
12741273
qt/i18n/OpenRGB_pt_BR.ts \
1274+
qt/i18n/OpenRGB_zh.ts \
1275+
qt/i18n/OpenRGB_zh_TW.ts \
12751276

12761277
FORMS += \
12771278
qt/OpenRGBClientInfoPage.ui \

main.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <stdio.h>
1919
#include <stdlib.h>
2020
#include <thread>
21-
#include <QTranslator>
2221

2322
#ifdef _MACOSX_X86_X64
2423
#include "macUSPCIOAccess.h"
@@ -346,36 +345,6 @@ int main(int argc, char* argv[])
346345
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
347346
QApplication a(argc, argv);
348347

349-
/*---------------------------------------------------------*\
350-
| App translation |
351-
| To add a new language: |
352-
| Create a file under qt/i18n/OpenRGB_<locale>.ts |
353-
| Add it to TRANSLATIONS in OpenRGB.pro |
354-
| Edit this file (manually or with |
355-
| linguist qt/i18n/OpenRGB_en.ts qt/i18n/OpenRGB_XX.ts |
356-
\*---------------------------------------------------------*/
357-
QTranslator translator;
358-
359-
QLocale locale = QLocale(QLocale::system());
360-
QLocale::setDefault(locale);
361-
362-
// For local tests without changing the PC locale, override this value.
363-
//locale = QLocale(QLocale::French, QLocale::France);
364-
365-
a.removeTranslator(&translator);
366-
367-
QString path = ":/i18n/";
368-
369-
if(translator.load(path + QString("OpenRGB_%1.qm").arg(locale.name())))
370-
{
371-
a.installTranslator(&translator);
372-
printf("Current Language changed to %s\n", locale.name().toStdString().c_str());
373-
}
374-
else
375-
{
376-
printf("Failed to load translation file for default locale '%s'\n", locale.name().toStdString().c_str());
377-
}
378-
379348
/*---------------------------------------------------------*\
380349
| Main UI widget |
381350
\*---------------------------------------------------------*/

qt/OpenRGBClientInfoPage.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ OpenRGBClientInfoPage::~OpenRGBClientInfoPage()
5050

5151
}
5252

53+
void OpenRGBClientInfoPage::changeEvent(QEvent *event)
54+
{
55+
if(event->type() == QEvent::LanguageChange)
56+
{
57+
ui->retranslateUi(this);
58+
}
59+
}
60+
5361
void OpenRGBClientInfoPage::AddClient(NetworkClient* new_client)
5462
{
5563
/*-----------------------------------------------------*\
@@ -82,7 +90,6 @@ void OpenRGBClientInfoPage::UpdateInfo()
8290
ui->ClientTree->setColumnWidth(1, 100);
8391
ui->ClientTree->setColumnWidth(2, 100);
8492
ui->ClientTree->setColumnWidth(3, 100);
85-
ui->ClientTree->setHeaderLabels(QStringList() << tr("Connected Clients") << tr("Protocol Version") << tr("Save Connection") << "");
8693

8794
/*-----------------------------------------------------*\
8895
| Set up a signal mapper to handle disconnect buttons |

qt/OpenRGBClientInfoPage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public slots:
2424
void UpdateInfo();
2525

2626
private slots:
27+
void changeEvent(QEvent *event);
2728
void on_ClientConnectButton_clicked();
2829
void onClientDisconnectButton_clicked(QObject * arg);
2930
void onClientSaveCheckBox_clicked(QObject * arg);

qt/OpenRGBClientInfoPage.ui

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,28 @@
6464
<item row="1" column="3" colspan="6">
6565
<widget class="QTreeWidget" name="ClientTree">
6666
<property name="columnCount">
67-
<number>0</number>
67+
<number>4</number>
6868
</property>
69+
<column>
70+
<property name="text">
71+
<string>Connected Clients</string>
72+
</property>
73+
</column>
74+
<column>
75+
<property name="text">
76+
<string>Protocol Version</string>
77+
</property>
78+
</column>
79+
<column>
80+
<property name="text">
81+
<string>Save Connection</string>
82+
</property>
83+
</column>
84+
<column>
85+
<property name="text">
86+
<string/>
87+
</property>
88+
</column>
6989
</widget>
7090
</item>
7191
</layout>

qt/OpenRGBConsolePage.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,11 @@ OpenRGBConsolePage::~OpenRGBConsolePage()
7373
{
7474
delete ui;
7575
}
76+
77+
void OpenRGBConsolePage::changeEvent(QEvent *event)
78+
{
79+
if(event->type() == QEvent::LanguageChange)
80+
{
81+
ui->retranslateUi(this);
82+
}
83+
}

qt/OpenRGBConsolePage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Ui::OpenRGBConsolePage : public QFrame
1717
~OpenRGBConsolePage();
1818

1919
private slots:
20+
void changeEvent(QEvent *event);
2021
void on_log_level_currentIndexChanged(int);
2122
void on_clear_clicked();
2223
void on_refresh_clicked();

qt/OpenRGBDeviceInfoPage.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ OpenRGBDeviceInfoPage::~OpenRGBDeviceInfoPage()
2525
delete ui;
2626
}
2727

28+
void OpenRGBDeviceInfoPage::changeEvent(QEvent *event)
29+
{
30+
if(event->type() == QEvent::LanguageChange)
31+
{
32+
ui->retranslateUi(this);
33+
}
34+
}
35+
2836
RGBController* OpenRGBDeviceInfoPage::GetController()
2937
{
3038
return controller;

qt/OpenRGBDeviceInfoPage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class Ui::OpenRGBDeviceInfoPage : public QFrame
2222
private:
2323
RGBController* controller;
2424
Ui::OpenRGBDeviceInfoPageUi* ui;
25+
26+
private slots:
27+
void changeEvent(QEvent *event);
2528
};
2629

2730
#endif // OPENRGBDEVICEINFOPAGE_H

0 commit comments

Comments
 (0)