1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-02 09:55:55 +00:00

Refactor code

Add const to variables.
No functionality change.
This commit is contained in:
Chocobo1 2018-05-11 21:34:08 +08:00
parent 92a4e73a22
commit 5ae926a376
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C

View File

@ -99,29 +99,28 @@ namespace
{ {
const QRegExp regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR(\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\])"); const QRegExp regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR(\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\])");
const QRegExp mnemonic("\\(?&([a-zA-Z]?\\))?"); const QRegExp mnemonic("\\(?&([a-zA-Z]?\\))?");
int i = 0;
bool found = true;
bool isTranslationNeeded = !locale.startsWith("en") const bool isTranslationNeeded = !locale.startsWith("en")
|| locale.startsWith("en_AU") || locale.startsWith("en_GB"); || locale.startsWith("en_AU") || locale.startsWith("en_GB");
int i = 0;
bool found = true;
while (i < data.size() && found) { while (i < data.size() && found) {
i = regex.indexIn(data, i); i = regex.indexIn(data, i);
if (i >= 0) { if (i >= 0) {
//qDebug("Found translatable string: %s", regex.cap(1).toUtf8().data()); const QString word = regex.cap(1);
QByteArray word = regex.cap(1).toUtf8(); const QString context = regex.cap(4);
QString translation = isTranslationNeeded
? qApp->translate(context.toUtf8().constData(), word.toUtf8().constData(), nullptr, 1)
: word;
QString translation = word;
if (isTranslationNeeded) {
QString context = regex.cap(4);
translation = qApp->translate(context.toUtf8().constData(), word.constData(), nullptr, 1);
}
// Remove keyboard shortcuts // Remove keyboard shortcuts
translation.replace(mnemonic, ""); translation.replace(mnemonic, "");
// Use HTML code for quotes to prevent issues with JS // Use HTML code for quotes to prevent issues with JS
translation.replace("'", "&#39;"); translation.replace('\'', "&#39;");
translation.replace("\"", "&#34;"); translation.replace('\"', "&#34;");
data.replace(i, regex.matchedLength(), translation); data.replace(i, regex.matchedLength(), translation);
i += translation.length(); i += translation.length();