diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 1c1a97e4f..fea627f81 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -123,6 +123,7 @@ SET(cockatrice_SOURCES src/carddbparser/cockatricexml4.cpp src/filter_string.cpp src/customlineedit.cpp + src/translatecountername.cpp ${VERSION_STRING_CPP} ) diff --git a/cockatrice/src/abstractcounter.cpp b/cockatrice/src/abstractcounter.cpp index 3050803ed..eff49ce21 100644 --- a/cockatrice/src/abstractcounter.cpp +++ b/cockatrice/src/abstractcounter.cpp @@ -5,6 +5,7 @@ #include "pb/command_set_counter.pb.h" #include "player.h" #include "settingscache.h" +#include "translatecountername.h" #include #include @@ -32,7 +33,8 @@ AbstractCounter::AbstractCounter(Player *_player, shortcutActive = false; if (player->getLocalOrJudge()) { - menu = new TearOffMenu(name); + QString displayName = TranslateCounterName::getDisplayName(_name); + menu = new TearOffMenu(displayName); aSet = new QAction(this); connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter())); menu->addAction(aSet); diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index e0e83b258..43f307a21 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -7,6 +7,7 @@ #include "pb/serverinfo_user.pb.h" #include "player.h" #include "soundengine.h" +#include "translatecountername.h" #include @@ -681,9 +682,10 @@ void MessageLogWidget::logSetCounter(Player *player, QString counterName, int va soundEngine->playSound("life_change"); } + QString counterDisplayName = TranslateCounterName::getDisplayName(counterName); appendHtmlServerMessage(tr("%1 sets counter %2 to %3 (%4%5).") .arg(sanitizeHtml(player->getName())) - .arg(QString("%1").arg(sanitizeHtml(counterName))) + .arg(QString("%1").arg(sanitizeHtml(counterDisplayName))) .arg(QString("%1").arg(value)) .arg(value > oldValue ? "+" : "") .arg(value - oldValue)); diff --git a/cockatrice/src/translatecountername.cpp b/cockatrice/src/translatecountername.cpp new file mode 100644 index 000000000..0f2813883 --- /dev/null +++ b/cockatrice/src/translatecountername.cpp @@ -0,0 +1,11 @@ +#include "translatecountername.h" + +const QMap TranslateCounterName::translated = { + {"life", QT_TRANSLATE_NOOP("TranslateCounterName", "Life")}, + {"w", QT_TRANSLATE_NOOP("TranslateCounterName", "White")}, + {"u", QT_TRANSLATE_NOOP("TranslateCounterName", "Blue")}, + {"b", QT_TRANSLATE_NOOP("TranslateCounterName", "Black")}, + {"r", QT_TRANSLATE_NOOP("TranslateCounterName", "Red")}, + {"g", QT_TRANSLATE_NOOP("TranslateCounterName", "Green")}, + {"x", QT_TRANSLATE_NOOP("TranslateCounterName", "Colorless")}, + {"storm", QT_TRANSLATE_NOOP("TranslateCounterName", "Other")}}; diff --git a/cockatrice/src/translatecountername.h b/cockatrice/src/translatecountername.h new file mode 100644 index 000000000..a098a8a7d --- /dev/null +++ b/cockatrice/src/translatecountername.h @@ -0,0 +1,24 @@ +#ifndef TRANSLATECOUNTERNAME_H +#define TRANSLATECOUNTERNAME_H + +#include +#include + +class TranslateCounterName +{ + Q_DECLARE_TR_FUNCTIONS(TranslateCounterName) + + static const QMap translated; + +public: + static QString getDisplayName(const QString &name) + { + if (translated.contains(name)) { + return tr(translated[name].toLatin1()); + } else { + return name; + } + } +}; + +#endif // TRANSLATECOUNTERNAME_H