From 384fe7067ec6628ff4e09bc8f75cc3a4a69a1d29 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Mon, 29 May 2017 19:09:12 +0300 Subject: [PATCH] Set up translations --- CMakeLists.txt | 18 +++- resources/langs/nheko_de.ts | 195 ++++++++++++++++++++++++++++++++++++ resources/langs/nheko_el.ts | 195 ++++++++++++++++++++++++++++++++++++ resources/langs/nheko_nl.ts | 195 ++++++++++++++++++++++++++++++++++++ src/EmojiPanel.cc | 16 +-- src/LoginPage.cc | 12 +-- src/MatrixClient.cc | 8 +- src/RegisterPage.cc | 18 ++-- src/TextInputWidget.cc | 2 +- src/TrayIcon.cc | 4 +- src/WelcomePage.cc | 31 +++--- src/main.cc | 12 +++ 12 files changed, 658 insertions(+), 48 deletions(-) create mode 100644 resources/langs/nheko_de.ts create mode 100644 resources/langs/nheko_el.ts create mode 100644 resources/langs/nheko_nl.ts diff --git a/CMakeLists.txt b/CMakeLists.txt index d83fb8d1..4b36ad11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ option(BUILD_TESTS "Build all tests" OFF) find_package(Qt5Widgets REQUIRED) find_package(Qt5Network REQUIRED) +find_package(Qt5LinguistTools REQUIRED) set(CMAKE_C_COMPILER gcc) @@ -191,6 +192,21 @@ qt5_wrap_cpp(MOC_HEADERS include/ui/ThemeManager.h ) +FILE(GLOB LANG_TS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/langs/*.ts") + +qt5_add_translation(QM_SRC ${LANG_TS_SRC}) +add_custom_target(LANG_QRC ALL DEPENDS ${QM_SRC}) + +# Generate a qrc file for the translations +set(_qrc ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) +file(WRITE ${_qrc} " ") +foreach(_lang ${QM_SRC}) + get_filename_component(_filename ${_lang} NAME) + file(APPEND ${_qrc} "${_filename}") +endforeach(_lang) +file(APPEND ${_qrc} " ") + +qt5_add_resources(LANG_QRC ${_qrc}) qt5_add_resources(QRC resources/res.qrc) add_library(matrix_events ${MATRIX_EVENTS} src/Deserializable.cc) @@ -215,7 +231,7 @@ if (BUILD_TESTS) add_test(MatrixEventCollection event_collection_test) add_test(MatrixMessageEvents message_events) else() - add_executable (nheko ${OS_BUNDLE} ${SRC_FILES} ${UI_HEADERS} ${MOC_HEADERS} ${QRC}) + add_executable (nheko ${OS_BUNDLE} ${SRC_FILES} ${UI_HEADERS} ${MOC_HEADERS} ${QRC} ${LANG_QRC} ${QM_SRC}) target_link_libraries (nheko matrix_events Qt5::Widgets Qt5::Network) if(WIN32) diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts new file mode 100644 index 00000000..0b17ab44 --- /dev/null +++ b/resources/langs/nheko_de.ts @@ -0,0 +1,195 @@ + + + + + EmojiPanel + + + Smileys & People + + + + + Animals & Nature + + + + + Food & Drink + + + + + Activity + + + + + Travel & Places + + + + + Objects + + + + + Symbols + + + + + Flags + + + + + LoginPage + + + Matrix ID + + + + + e.g @joe:matrix.org + + + + + Password + + + + + LOGIN + + + + + Invalid Matrix ID + + + + + Empty password + + + + + MatrixClient + + + Wrong username or password + + + + + Login endpoint was not found on the server + + + + + An unknown error occured. Please try again. + + + + + Malformed response. Possibly not a Matrix server + + + + + RegisterPage + + + Username + + + + + Password + + + + + Password confirmation + + + + + Home Server + + + + + REGISTER + + + + + Invalid username + + + + + Password is not long enough (min 8 chars) + + + + + Passwords don't match + + + + + Invalid server name + + + + + TextInputWidget + + + Write a message... + + + + + TrayIcon + + + Show + + + + + Quit + + + + + WelcomePage + + + Welcome to nheko! The desktop client for the Matrix protocol. + + + + + Enjoy your stay! + + + + + REGISTER + + + + + LOGIN + + + + diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts new file mode 100644 index 00000000..0cc9aa13 --- /dev/null +++ b/resources/langs/nheko_el.ts @@ -0,0 +1,195 @@ + + + + + EmojiPanel + + + Smileys & People + Πρόσωπα + + + + Animals & Nature + Ζώα & Φύση + + + + Food & Drink + Φαγητά & Ποτά + + + + Activity + Δραστηριότητες + + + + Travel & Places + Ταξίδια & Τοποθεσίες + + + + Objects + Αντικείμενα + + + + Symbols + Σύμβολα + + + + Flags + Σημαίες + + + + LoginPage + + + Matrix ID + Matrix ID + + + + e.g @joe:matrix.org + π.χ @john:matrix.org + + + + Password + Κωδικός + + + + LOGIN + ΕΙΣΟΔΟΣ + + + + Invalid Matrix ID + Μη έγκυρο Matrix ID + + + + Empty password + Κενός κωδικός + + + + MatrixClient + + + Wrong username or password + Λάθος ψευδώνυμο ή κωδικός. + + + + Login endpoint was not found on the server + Δεν παρέχεται δυνατότητα εισόδου από το διακομιστή. + + + + An unknown error occured. Please try again. + Σφάλμα άγνωστης προεύλευσης. Παρακαλώ προσπαθήστε ξανά. + + + + Malformed response. Possibly not a Matrix server + Ο διακόμιστής δεν χρησιμοποιεί το πρωτόκολλο Matrix. + + + + RegisterPage + + + Username + Ψευδώνυμο + + + + Password + Κωδικός + + + + Password confirmation + Επαλήθευση κωδικού + + + + Home Server + Διακομιστής + + + + REGISTER + ΕΓΓΡΑΦΗ + + + + Invalid username + Μη έγκυρο ψευδώνυμο + + + + Password is not long enough (min 8 chars) + Ο κωδικός δεν αποτελείται από αρκετούς χαρακτήρες (τουλάχιστον 8) + + + + Passwords don't match + Οι κωδικοί δεν ταιριάζουν + + + + Invalid server name + Μη έγκυρος διακομιστής + + + + TextInputWidget + + + Write a message... + Γράψε κάτι... + + + + TrayIcon + + + Show + Εμφάνιση + + + + Quit + Έξοδος + + + + WelcomePage + + + Welcome to nheko! The desktop client for the Matrix protocol. + Καλώς ήρθες στο nheko! + + + + Enjoy your stay! + Τη desktop εφαρμογή για το πρωτόκολλο επικοινωνίας Matrix. + + + + REGISTER + ΕΓΓΡΑΦΗ + + + + LOGIN + ΕΙΣΟΔΟΣ + + + diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts new file mode 100644 index 00000000..0b17ab44 --- /dev/null +++ b/resources/langs/nheko_nl.ts @@ -0,0 +1,195 @@ + + + + + EmojiPanel + + + Smileys & People + + + + + Animals & Nature + + + + + Food & Drink + + + + + Activity + + + + + Travel & Places + + + + + Objects + + + + + Symbols + + + + + Flags + + + + + LoginPage + + + Matrix ID + + + + + e.g @joe:matrix.org + + + + + Password + + + + + LOGIN + + + + + Invalid Matrix ID + + + + + Empty password + + + + + MatrixClient + + + Wrong username or password + + + + + Login endpoint was not found on the server + + + + + An unknown error occured. Please try again. + + + + + Malformed response. Possibly not a Matrix server + + + + + RegisterPage + + + Username + + + + + Password + + + + + Password confirmation + + + + + Home Server + + + + + REGISTER + + + + + Invalid username + + + + + Password is not long enough (min 8 chars) + + + + + Passwords don't match + + + + + Invalid server name + + + + + TextInputWidget + + + Write a message... + + + + + TrayIcon + + + Show + + + + + Quit + + + + + WelcomePage + + + Welcome to nheko! The desktop client for the Matrix protocol. + + + + + Enjoy your stay! + + + + + REGISTER + + + + + LOGIN + + + + diff --git a/src/EmojiPanel.cc b/src/EmojiPanel.cc index 02fe2f14..63b408c0 100644 --- a/src/EmojiPanel.cc +++ b/src/EmojiPanel.cc @@ -117,28 +117,28 @@ EmojiPanel::EmojiPanel(QWidget *parent) scroll_layout_->setMargin(0); scroll_area_->setWidget(scroll_widget_); - auto people_emoji = new EmojiCategory("Smileys & People", emoji_provider_.people, scroll_widget_); + auto people_emoji = new EmojiCategory(tr("Smileys & People"), emoji_provider_.people, scroll_widget_); scroll_layout_->addWidget(people_emoji); - auto nature_emoji = new EmojiCategory("Animals & Nature", emoji_provider_.nature, scroll_widget_); + auto nature_emoji = new EmojiCategory(tr("Animals & Nature"), emoji_provider_.nature, scroll_widget_); scroll_layout_->addWidget(nature_emoji); - auto food_emoji = new EmojiCategory("Food & Drink", emoji_provider_.food, scroll_widget_); + auto food_emoji = new EmojiCategory(tr("Food & Drink"), emoji_provider_.food, scroll_widget_); scroll_layout_->addWidget(food_emoji); - auto activity_emoji = new EmojiCategory("Activity", emoji_provider_.activity, scroll_widget_); + auto activity_emoji = new EmojiCategory(tr("Activity"), emoji_provider_.activity, scroll_widget_); scroll_layout_->addWidget(activity_emoji); - auto travel_emoji = new EmojiCategory("Travel & Places", emoji_provider_.travel, scroll_widget_); + auto travel_emoji = new EmojiCategory(tr("Travel & Places"), emoji_provider_.travel, scroll_widget_); scroll_layout_->addWidget(travel_emoji); - auto objects_emoji = new EmojiCategory("Objects", emoji_provider_.objects, scroll_widget_); + auto objects_emoji = new EmojiCategory(tr("Objects"), emoji_provider_.objects, scroll_widget_); scroll_layout_->addWidget(objects_emoji); - auto symbols_emoji = new EmojiCategory("Symbols", emoji_provider_.symbols, scroll_widget_); + auto symbols_emoji = new EmojiCategory(tr("Symbols"), emoji_provider_.symbols, scroll_widget_); scroll_layout_->addWidget(symbols_emoji); - auto flags_emoji = new EmojiCategory("Flags", emoji_provider_.flags, scroll_widget_); + auto flags_emoji = new EmojiCategory(tr("Flags"), emoji_provider_.flags, scroll_widget_); scroll_layout_->addWidget(flags_emoji); content_layout->addStretch(1); diff --git a/src/LoginPage.cc b/src/LoginPage.cc index 02ab92c6..4514b607 100644 --- a/src/LoginPage.cc +++ b/src/LoginPage.cc @@ -82,14 +82,14 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) matrixid_input_ = new TextField(this); matrixid_input_->setTextColor("#333333"); - matrixid_input_->setLabel("Matrix ID"); + matrixid_input_->setLabel(tr("Matrix ID")); matrixid_input_->setInkColor("#555459"); matrixid_input_->setBackgroundColor("#f9f9f9"); - matrixid_input_->setPlaceholderText("e.g @joe:matrix.org"); + matrixid_input_->setPlaceholderText(tr("e.g @joe:matrix.org")); password_input_ = new TextField(this); password_input_->setTextColor("#333333"); - password_input_->setLabel("Password"); + password_input_->setLabel(tr("Password")); password_input_->setInkColor("#555459"); password_input_->setBackgroundColor("#f9f9f9"); password_input_->setEchoMode(QLineEdit::Password); @@ -101,7 +101,7 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) button_layout_->setSpacing(0); button_layout_->setContentsMargins(0, 0, 0, 30); - login_button_ = new RaisedButton("LOGIN", this); + login_button_ = new RaisedButton(tr("LOGIN"), this); login_button_->setBackgroundColor(QColor("#333333")); login_button_->setForegroundColor(QColor("white")); login_button_->setMinimumSize(350, 65); @@ -147,9 +147,9 @@ void LoginPage::onLoginButtonClicked() error_label_->setText(""); if (!matrixid_input_->hasAcceptableInput()) { - loginError("Invalid Matrix ID"); + loginError(tr("Invalid Matrix ID")); } else if (password_input_->text().isEmpty()) { - loginError("Empty password"); + loginError(tr("Empty password")); } else { QString user = matrixid_input_->text().split(":").at(0).split("@").at(1); QString password = password_input_->text(); diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 23cbbb5e..a605623f 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -72,18 +72,18 @@ void MatrixClient::onLoginResponse(QNetworkReply *reply) int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (status_code == 403) { - emit loginError("Wrong username or password"); + emit loginError(tr("Wrong username or password")); return; } if (status_code == 404) { - emit loginError("Login endpoint was not found on the server"); + emit loginError(tr("Login endpoint was not found on the server")); return; } if (status_code >= 400) { qWarning() << "Login error: " << reply->errorString(); - emit loginError("An unknown error occured. Please try again."); + emit loginError(tr("An unknown error occured. Please try again.")); return; } @@ -97,7 +97,7 @@ void MatrixClient::onLoginResponse(QNetworkReply *reply) emit loginSuccess(response.getUserId(), server_.host(), response.getAccessToken()); } catch (DeserializationException &e) { qWarning() << "Malformed JSON response" << e.what(); - emit loginError("Malformed response. Possibly not a Matrix server"); + emit loginError(tr("Malformed response. Possibly not a Matrix server")); } } diff --git a/src/RegisterPage.cc b/src/RegisterPage.cc index d5c60918..33df0b62 100644 --- a/src/RegisterPage.cc +++ b/src/RegisterPage.cc @@ -69,27 +69,27 @@ RegisterPage::RegisterPage(QSharedPointer client, QWidget *parent) username_input_ = new TextField(); username_input_->setTextColor("#333333"); - username_input_->setLabel("Username"); + username_input_->setLabel(tr("Username")); username_input_->setInkColor("#555459"); username_input_->setBackgroundColor("#f9f9f9"); password_input_ = new TextField(); password_input_->setTextColor("#333333"); - password_input_->setLabel("Password"); + password_input_->setLabel(tr("Password")); password_input_->setInkColor("#555459"); password_input_->setBackgroundColor("#f9f9f9"); password_input_->setEchoMode(QLineEdit::Password); password_confirmation_ = new TextField(); password_confirmation_->setTextColor("#333333"); - password_confirmation_->setLabel("Password confirmation"); + password_confirmation_->setLabel(tr("Password confirmation")); password_confirmation_->setInkColor("#555459"); password_confirmation_->setBackgroundColor("#f9f9f9"); password_confirmation_->setEchoMode(QLineEdit::Password); server_input_ = new TextField(); server_input_->setTextColor("#333333"); - server_input_->setLabel("Home Server"); + server_input_->setLabel(tr("Home Server")); server_input_->setInkColor("#555459"); server_input_->setBackgroundColor("#f9f9f9"); @@ -105,7 +105,7 @@ RegisterPage::RegisterPage(QSharedPointer client, QWidget *parent) error_label_ = new QLabel(this); error_label_->setStyleSheet("margin-bottom: 10px; color: #E22826; font-size: 11pt;"); - register_button_ = new RaisedButton("REGISTER", this); + register_button_ = new RaisedButton(tr("REGISTER"), this); register_button_->setBackgroundColor(QColor("#333333")); register_button_->setForegroundColor(QColor("white")); register_button_->setMinimumSize(350, 65); @@ -156,13 +156,13 @@ void RegisterPage::onRegisterButtonClicked() error_label_->setText(""); if (!username_input_->hasAcceptableInput()) { - registerError("Invalid username"); + registerError(tr("Invalid username")); } else if (!password_input_->hasAcceptableInput()) { - registerError("Password is not long enough (min 8 chars)"); + registerError(tr("Password is not long enough (min 8 chars)")); } else if (password_input_->text() != password_confirmation_->text()) { - registerError("Passwords don't match"); + registerError(tr("Passwords don't match")); } else if (!server_input_->hasAcceptableInput()) { - registerError("Invalid server name"); + registerError(tr("Invalid server name")); } else { QString username = username_input_->text(); QString password = password_input_->text(); diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc index ab73a98f..cda00c2c 100644 --- a/src/TextInputWidget.cc +++ b/src/TextInputWidget.cc @@ -59,7 +59,7 @@ TextInputWidget::TextInputWidget(QWidget *parent) input_ = new FilteredTextEdit(this); input_->setFixedHeight(45); - input_->setPlaceholderText("Write a message..."); + input_->setPlaceholderText(tr("Write a message...")); input_->setStyleSheet("color: #333333; font-size: 13px; border-radius: 0; padding-top: 10px;"); send_message_button_ = new FlatButton(this); diff --git a/src/TrayIcon.cc b/src/TrayIcon.cc index 3a227087..beaf00df 100644 --- a/src/TrayIcon.cc +++ b/src/TrayIcon.cc @@ -70,8 +70,8 @@ TrayIcon::TrayIcon(const QString &filename, QWidget *parent) setIcon(QIcon(icon_)); QMenu *menu = new QMenu(parent); - viewAction_ = new QAction("Show", parent); - quitAction_ = new QAction("Quit", parent); + viewAction_ = new QAction(tr("Show"), parent); + quitAction_ = new QAction(tr("Quit"), parent); connect(viewAction_, SIGNAL(triggered()), parent, SLOT(show())); connect(quitAction_, &QAction::triggered, this, [=]() { diff --git a/src/WelcomePage.cc b/src/WelcomePage.cc index d6668e7b..b88c4db1 100644 --- a/src/WelcomePage.cc +++ b/src/WelcomePage.cc @@ -34,21 +34,18 @@ WelcomePage::WelcomePage(QWidget *parent) intro_banner_->setAlignment(Qt::AlignCenter); intro_text_ = new QLabel(this); - intro_text_->setText(QApplication::translate("WelcomePage", - "" - "" - "" - "

" - " " - " Welcome to nheko! The desktop client for the Matrix protocol." - " " - "

\n" - "

" - " Enjoy your stay!" - "

" - "" - "", - Q_NULLPTR)); + + QString heading(tr("Welcome to nheko! The desktop client for the Matrix protocol.")); + QString main(tr("Enjoy your stay!")); + + intro_text_->setText(QString("

" + " %1 " + "

" + "

" + " %2 " + "

") + .arg(heading) + .arg(main)); top_layout_->addStretch(1); top_layout_->addWidget(intro_banner_); @@ -60,7 +57,7 @@ WelcomePage::WelcomePage(QWidget *parent) button_layout_->setSpacing(0); button_layout_->setContentsMargins(0, 20, 0, 80); - register_button_ = new RaisedButton("REGISTER", this); + register_button_ = new RaisedButton(tr("REGISTER"), this); register_button_->setBackgroundColor(QColor("#333333")); register_button_->setForegroundColor(QColor("white")); register_button_->setMinimumSize(240, 60); @@ -68,7 +65,7 @@ WelcomePage::WelcomePage(QWidget *parent) register_button_->setFontSize(14); register_button_->setCornerRadius(3); - login_button_ = new RaisedButton("LOGIN", this); + login_button_ = new RaisedButton(tr("LOGIN"), this); login_button_->setBackgroundColor(QColor("#333333")); login_button_->setForegroundColor(QColor("white")); login_button_->setMinimumSize(240, 60); diff --git a/src/main.cc b/src/main.cc index 993eea82..e6d4c4e7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "MainWindow.h" @@ -44,6 +46,16 @@ int main(int argc, char *argv[]) QFont font("Open Sans"); app.setFont(font); + QString lang = QLocale::system().name(); + + QTranslator qtTranslator; + qtTranslator.load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + app.installTranslator(&qtTranslator); + + QTranslator appTranslator; + appTranslator.load("nheko_" + lang, ":/translations"); + app.installTranslator(&appTranslator); + MainWindow w; // Move the MainWindow to the center