Set up translations

This commit is contained in:
Konstantinos Sideris 2017-05-29 19:09:12 +03:00
parent 36940e2972
commit 384fe7067e
12 changed files with 658 additions and 48 deletions

View file

@ -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);

View file

@ -82,14 +82,14 @@ LoginPage::LoginPage(QSharedPointer<MatrixClient> 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<MatrixClient> 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();

View file

@ -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"));
}
}

View file

@ -69,27 +69,27 @@ RegisterPage::RegisterPage(QSharedPointer<MatrixClient> 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<MatrixClient> 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();

View file

@ -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);

View file

@ -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, [=]() {

View file

@ -34,21 +34,18 @@ WelcomePage::WelcomePage(QWidget *parent)
intro_banner_->setAlignment(Qt::AlignCenter);
intro_text_ = new QLabel(this);
intro_text_->setText(QApplication::translate("WelcomePage",
"<html>"
"<head/>"
"<body>"
" <p align=\"center\" style=\"margin: 0; line-height: 2pt\">"
" <span style=\" font-size:18px; color:#515151;\"> "
" Welcome to nheko! The desktop client for the Matrix protocol."
" </span>"
" </p>\n"
" <p align=\"center\" style=\"margin: 1pt; line-height: 2pt;\">"
" <span style=\" font-size:18px; color:#515151;\">Enjoy your stay!</span>"
" </p>"
"</body>"
"</html>",
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("<p align=\"center\" style=\"margin: 0; line-height: 2pt\">"
" <span style=\" font-size:18px; color:#515151;\"> %1 </span>"
"</p>"
"<p align=\"center\" style=\"margin: 1pt; line-height: 2pt;\">"
" <span style=\" font-size:18px; color:#515151;\"> %2 </span>"
"</p>")
.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);

View file

@ -18,6 +18,8 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QFontDatabase>
#include <QLibraryInfo>
#include <QTranslator>
#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