wrap UI strings with tr()
This commit is contained in:
@@ -29,7 +29,7 @@ BlueprintPanel::BlueprintPanel(Simulation* sim, const GameConfig* config, QWidge
|
||||
layout->setContentsMargins(4, 4, 4, 4);
|
||||
layout->setSpacing(4);
|
||||
|
||||
m_createBtn = new QPushButton("Create Blueprint", this);
|
||||
m_createBtn = new QPushButton(tr("Create Blueprint"), this);
|
||||
m_createBtn->setFixedHeight(48);
|
||||
m_createBtn->setEnabled(false);
|
||||
layout->addWidget(m_createBtn);
|
||||
@@ -50,8 +50,8 @@ BlueprintPanel::BlueprintPanel(Simulation* sim, const GameConfig* config, QWidge
|
||||
connect(m_createBtn, &QPushButton::clicked, this, &BlueprintPanel::onCreateClicked);
|
||||
|
||||
QHBoxLayout* ioLayout = new QHBoxLayout();
|
||||
m_saveBtn = new QPushButton("Save", this);
|
||||
m_loadBtn = new QPushButton("Load", this);
|
||||
m_saveBtn = new QPushButton(tr("Save"), this);
|
||||
m_loadBtn = new QPushButton(tr("Load"), this);
|
||||
m_saveBtn->setFixedHeight(36);
|
||||
m_loadBtn->setFixedHeight(36);
|
||||
ioLayout->addWidget(m_saveBtn);
|
||||
@@ -93,7 +93,7 @@ void BlueprintPanel::onCreateClicked()
|
||||
|
||||
bool ok = false;
|
||||
const QString name = QInputDialog::getText(
|
||||
this, "Create Blueprint", "Blueprint name:", QLineEdit::Normal, QString(), &ok);
|
||||
this, tr("Create Blueprint"), tr("Blueprint name:"), QLineEdit::Normal, QString(), &ok);
|
||||
if (!ok || name.trimmed().isEmpty()) { return; }
|
||||
|
||||
bp.name = name.trimmed();
|
||||
@@ -223,7 +223,7 @@ void BlueprintPanel::rebuildButtons()
|
||||
{
|
||||
const Blueprint& bp = m_blueprints[static_cast<std::size_t>(i)];
|
||||
const int cost = computeBlueprintCost(bp);
|
||||
const QString label = bp.name + "\n" + QString::number(cost) + " Blocks";
|
||||
const QString label = bp.name + "\n" + tr("%1 Blocks").arg(cost);
|
||||
|
||||
QWidget* row = new QWidget(m_buttonsContainer);
|
||||
QHBoxLayout* rowLayout = new QHBoxLayout(row);
|
||||
@@ -266,26 +266,26 @@ void BlueprintPanel::onSaveClicked()
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox::critical(this, "Save Failed",
|
||||
QString("Could not open file for writing:\n%1").arg(path));
|
||||
QMessageBox::critical(this, tr("Save Failed"),
|
||||
tr("Could not open file for writing:\n%1").arg(path));
|
||||
return;
|
||||
}
|
||||
file.write(QByteArray::fromStdString(content));
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
QMessageBox::critical(this, "Save Failed",
|
||||
QString("Failed to save blueprints:\n%1").arg(e.what()));
|
||||
QMessageBox::critical(this, tr("Save Failed"),
|
||||
tr("Failed to save blueprints:\n%1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void BlueprintPanel::onLoadClicked()
|
||||
{
|
||||
QMessageBox box(this);
|
||||
box.setWindowTitle("Load Blueprints");
|
||||
box.setText("Load blueprints? This will replace all current blueprints.");
|
||||
QPushButton* confirmBtn = box.addButton("Confirm", QMessageBox::AcceptRole);
|
||||
box.addButton("Cancel", QMessageBox::RejectRole);
|
||||
box.setWindowTitle(tr("Load Blueprints"));
|
||||
box.setText(tr("Load blueprints? This will replace all current blueprints."));
|
||||
QPushButton* confirmBtn = box.addButton(tr("Confirm"), QMessageBox::AcceptRole);
|
||||
box.addButton(tr("Cancel"), QMessageBox::RejectRole);
|
||||
box.exec();
|
||||
if (box.clickedButton() != confirmBtn) { return; }
|
||||
|
||||
@@ -295,8 +295,8 @@ void BlueprintPanel::onLoadClicked()
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox::critical(this, "Load Failed",
|
||||
QString("Could not open file:\n%1").arg(path));
|
||||
QMessageBox::critical(this, tr("Load Failed"),
|
||||
tr("Could not open file:\n%1").arg(path));
|
||||
return;
|
||||
}
|
||||
const std::string content = file.readAll().toStdString();
|
||||
@@ -313,8 +313,8 @@ void BlueprintPanel::onLoadClicked()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
QMessageBox::critical(this, "Load Failed",
|
||||
QString("Failed to load blueprints:\n%1").arg(e.what()));
|
||||
QMessageBox::critical(this, tr("Load Failed"),
|
||||
tr("Failed to load blueprints:\n%1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
|
||||
m_costs[def.type] = def.cost;
|
||||
|
||||
const QString label = displayName(def.id)
|
||||
+ "\n" + QString::number(def.cost) + " Blocks";
|
||||
+ "\n" + tr("%1 Blocks").arg(def.cost);
|
||||
QPushButton* btn = new QPushButton(label, this);
|
||||
btn->setCheckable(true);
|
||||
btn->setFixedHeight(48);
|
||||
@@ -83,7 +83,7 @@ BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
|
||||
}
|
||||
connect(mapper, qOverload<int>(&QSignalMapper::mapped), this, &BuildButtonGrid::onBuildButton);
|
||||
|
||||
m_demolishButton = new QPushButton("Demolish", this);
|
||||
m_demolishButton = new QPushButton(tr("Demolish"), this);
|
||||
m_demolishButton->setCheckable(true);
|
||||
m_demolishButton->setFixedHeight(48);
|
||||
layout->addWidget(m_demolishButton, row, col);
|
||||
|
||||
@@ -21,8 +21,8 @@ HeaderBar::HeaderBar(QWidget* parent)
|
||||
layout->setSpacing(8);
|
||||
|
||||
m_timeLabel = new QLabel("00:00", this);
|
||||
m_blocksLabel = new QLabel("Blocks: 0", this);
|
||||
m_bossLabel = new QLabel("Boss Wave #1 Next boss: 5:00", this);
|
||||
m_blocksLabel = new QLabel(tr("Blocks: 0"), this);
|
||||
m_bossLabel = new QLabel(tr("Boss Wave #1 Next boss: 5:00"), this);
|
||||
layout->addWidget(m_timeLabel);
|
||||
layout->addWidget(m_blocksLabel);
|
||||
layout->addStretch();
|
||||
@@ -57,14 +57,14 @@ void HeaderBar::onStateUpdated(Tick tick, int buildingBlocks, double gameSpeed,
|
||||
.arg(minutes, 2, 10, QChar('0'))
|
||||
.arg(seconds, 2, 10, QChar('0')));
|
||||
|
||||
m_blocksLabel->setText(QString("Blocks: %1").arg(buildingBlocks));
|
||||
m_blocksLabel->setText(tr("Blocks: %1").arg(buildingBlocks));
|
||||
|
||||
const int bossSeconds = static_cast<int>(ticksToSeconds(
|
||||
bossCountdownTicks > 0 ? bossCountdownTicks : 0));
|
||||
const int bossMin = bossSeconds / 60;
|
||||
const int bossSec = bossSeconds % 60;
|
||||
m_bossLabel->setText(
|
||||
QString("Boss Wave #%1 Next boss: %2:%3")
|
||||
tr("Boss Wave #%1 Next boss: %2:%3")
|
||||
.arg(bossCounter)
|
||||
.arg(bossMin)
|
||||
.arg(bossSec, 2, 10, QChar('0')));
|
||||
|
||||
@@ -28,7 +28,7 @@ MainWindow::MainWindow(Simulation* sim, const std::string& configDir, QWidget* p
|
||||
, m_visuals(VisualsLoader::load(configDir + "/visuals.toml"))
|
||||
, m_sim(sim)
|
||||
{
|
||||
setWindowTitle("Dota Factory");
|
||||
setWindowTitle(tr("Dota Factory"));
|
||||
resize(1280, 768);
|
||||
|
||||
m_headerBar = new HeaderBar(this);
|
||||
@@ -127,8 +127,8 @@ MainWindow::MainWindow(Simulation* sim, const std::string& configDir, QWidget* p
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
QMessageBox::critical(this, "Load Error",
|
||||
QString("Failed to load ship_layouts.toml:\n%1").arg(e.what()));
|
||||
QMessageBox::critical(this, tr("Load Error"),
|
||||
tr("Failed to load ship_layouts.toml:\n%1").arg(e.what()));
|
||||
m_layoutBlueprints.clear();
|
||||
}
|
||||
}
|
||||
@@ -183,10 +183,10 @@ void MainWindow::onEscapeMenuRequested()
|
||||
m_gameWorldView->setGameSpeed(0.0);
|
||||
|
||||
QMessageBox box(this);
|
||||
box.setWindowTitle("Paused");
|
||||
QPushButton* continueBtn = box.addButton("Continue", QMessageBox::AcceptRole);
|
||||
QPushButton* restartBtn = box.addButton("Restart", QMessageBox::ResetRole);
|
||||
QPushButton* quitBtn = box.addButton("Quit", QMessageBox::DestructiveRole);
|
||||
box.setWindowTitle(tr("Paused"));
|
||||
QPushButton* continueBtn = box.addButton(tr("Continue"), QMessageBox::AcceptRole);
|
||||
QPushButton* restartBtn = box.addButton(tr("Restart"), QMessageBox::ResetRole);
|
||||
QPushButton* quitBtn = box.addButton(tr("Quit"), QMessageBox::DestructiveRole);
|
||||
box.setEscapeButton(continueBtn);
|
||||
box.exec();
|
||||
|
||||
@@ -202,8 +202,8 @@ void MainWindow::onEscapeMenuRequested()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
QMessageBox::critical(this, "Config Error",
|
||||
QString("Failed to reload config:\n%1").arg(e.what()));
|
||||
QMessageBox::critical(this, tr("Config Error"),
|
||||
tr("Failed to reload config:\n%1").arg(e.what()));
|
||||
m_gameWorldView->setGameSpeed(prevSpeed);
|
||||
return;
|
||||
}
|
||||
@@ -255,12 +255,12 @@ void MainWindow::onGameOver()
|
||||
const int seconds = totalSeconds % 60;
|
||||
|
||||
QMessageBox box(this);
|
||||
box.setWindowTitle("Game Over");
|
||||
box.setText(QString("HQ destroyed!\nSurvival time: %1:%2")
|
||||
box.setWindowTitle(tr("Game Over"));
|
||||
box.setText(tr("HQ destroyed!\nSurvival time: %1:%2")
|
||||
.arg(minutes, 2, 10, QChar('0'))
|
||||
.arg(seconds, 2, 10, QChar('0')));
|
||||
QPushButton* restartBtn = box.addButton("Restart", QMessageBox::AcceptRole);
|
||||
box.addButton("Quit", QMessageBox::RejectRole);
|
||||
QPushButton* restartBtn = box.addButton(tr("Restart"), QMessageBox::AcceptRole);
|
||||
box.addButton(tr("Quit"), QMessageBox::RejectRole);
|
||||
box.exec();
|
||||
|
||||
if (box.clickedButton() == restartBtn)
|
||||
@@ -274,8 +274,8 @@ void MainWindow::onGameOver()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
QMessageBox::critical(this, "Config Error",
|
||||
QString("Failed to reload config:\n%1").arg(e.what()));
|
||||
QMessageBox::critical(this, tr("Config Error"),
|
||||
tr("Failed to reload config:\n%1").arg(e.what()));
|
||||
return;
|
||||
}
|
||||
m_gameWorldView->resetForNewGame();
|
||||
|
||||
@@ -69,10 +69,10 @@ QString rotationLabel(Rotation r)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case Rotation::North: return "North (↑)";
|
||||
case Rotation::East: return "East (→)";
|
||||
case Rotation::South: return "South (↓)";
|
||||
case Rotation::West: return "West (←)";
|
||||
case Rotation::North: return QObject::tr("North (↑)");
|
||||
case Rotation::East: return QObject::tr("East (→)");
|
||||
case Rotation::South: return QObject::tr("South (↓)");
|
||||
case Rotation::West: return QObject::tr("West (←)");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -96,13 +96,13 @@ SelectedBuildingPanel::SelectedBuildingPanel(Simulation* sim,
|
||||
|
||||
m_titleLabel = new QLabel(this);
|
||||
m_recipeCombo = new QComboBox(this);
|
||||
m_clearBeltBtn = new QPushButton("Clear Items", this);
|
||||
m_clearBeltBtn = new QPushButton(tr("Clear Items"), this);
|
||||
m_filterALabel = new QLabel(this);
|
||||
m_filterAList = new QListWidget(this);
|
||||
m_filterBLabel = new QLabel(this);
|
||||
m_filterBList = new QListWidget(this);
|
||||
m_layoutPreview = new ShipLayoutPreview(this);
|
||||
m_configureLayoutBtn = new QPushButton("Configure Layout", this);
|
||||
m_configureLayoutBtn = new QPushButton(tr("Configure Layout"), this);
|
||||
m_buffersLabel = new QLabel(this);
|
||||
m_buffersLabel->setWordWrap(true);
|
||||
|
||||
@@ -192,7 +192,7 @@ void SelectedBuildingPanel::buildSingle(BuildingId id)
|
||||
QString progress;
|
||||
if (s->completesAt == 0)
|
||||
{
|
||||
progress = "Queued";
|
||||
progress = tr("Queued");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -207,15 +207,15 @@ void SelectedBuildingPanel::buildSingle(BuildingId id)
|
||||
const Tick elapsed = m_sim->currentTick() - (s->completesAt - duration);
|
||||
const int pct = static_cast<int>(
|
||||
std::max(Tick(0), std::min(duration, elapsed)) * 100 / duration);
|
||||
progress = QString::number(pct) + "% complete";
|
||||
progress = tr("%1% complete").arg(pct);
|
||||
}
|
||||
else
|
||||
{
|
||||
progress = "Building...";
|
||||
progress = tr("Building...");
|
||||
}
|
||||
}
|
||||
|
||||
m_titleLabel->setText("(Building) " + buildingTypeName(s->type));
|
||||
m_titleLabel->setText(tr("(Building) %1").arg(buildingTypeName(s->type)));
|
||||
m_titleLabel->show();
|
||||
m_buffersLabel->setText(progress);
|
||||
m_buffersLabel->show();
|
||||
@@ -231,7 +231,7 @@ void SelectedBuildingPanel::buildSingle(BuildingId id)
|
||||
m_recipeCombo->blockSignals(true);
|
||||
m_recipeCombo->clear();
|
||||
|
||||
m_recipeCombo->addItem("(none)", QString());
|
||||
m_recipeCombo->addItem(tr("(none)"), QString());
|
||||
|
||||
if (b->type == BuildingType::Shipyard)
|
||||
{
|
||||
@@ -333,7 +333,7 @@ void SelectedBuildingPanel::refreshBuffers(const Building* b)
|
||||
|
||||
if (!b->inputBuffer.counts.empty())
|
||||
{
|
||||
bufText += "Input: ";
|
||||
bufText += tr("Input: ");
|
||||
for (const std::pair<const ItemType, int>& entry : b->inputBuffer.counts)
|
||||
{
|
||||
int perCycle = 0;
|
||||
@@ -389,7 +389,7 @@ void SelectedBuildingPanel::refreshBuffers(const Building* b)
|
||||
{
|
||||
outCounts[item.type.id]++;
|
||||
}
|
||||
bufText += "Output: ";
|
||||
bufText += tr("Output: ");
|
||||
for (const RecipeOutput& out : recipe->outputs)
|
||||
{
|
||||
const std::map<std::string, int>::const_iterator it =
|
||||
@@ -407,7 +407,7 @@ void SelectedBuildingPanel::refreshBuffers(const Building* b)
|
||||
{
|
||||
outCounts[item.type.id]++;
|
||||
}
|
||||
bufText += "Output: ";
|
||||
bufText += tr("Output: ");
|
||||
for (const std::pair<const std::string, int>& entry : outCounts)
|
||||
{
|
||||
bufText += QString::fromStdString(entry.first)
|
||||
@@ -436,7 +436,7 @@ void SelectedBuildingPanel::refreshBuffers(const Building* b)
|
||||
}
|
||||
}
|
||||
|
||||
bufText += QString("Cycle: %1 s\n").arg(durationSeconds, 0, 'f', 1);
|
||||
bufText += tr("Cycle: %1 s\n").arg(durationSeconds, 0, 'f', 1);
|
||||
|
||||
if (b->production.has_value())
|
||||
{
|
||||
@@ -446,11 +446,11 @@ void SelectedBuildingPanel::refreshBuffers(const Building* b)
|
||||
const Tick elapsed = currentTick - (completesAt - cycleTicks);
|
||||
const int pct = static_cast<int>(
|
||||
std::max(Tick(0), std::min(cycleTicks, elapsed)) * 100 / cycleTicks);
|
||||
bufText += QString("Progress: %1%\n").arg(pct);
|
||||
bufText += tr("Progress: %1%\n").arg(pct);
|
||||
}
|
||||
else
|
||||
{
|
||||
bufText += "Progress: idle\n";
|
||||
bufText += tr("Progress: idle\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,7 +496,7 @@ void SelectedBuildingPanel::onStateUpdated(Tick /*tick*/, int /*blocks*/, double
|
||||
{
|
||||
// If the panel was last showing this id as a construction site, the
|
||||
// full building UI (recipe combo, ports, etc.) hasn't been built yet.
|
||||
if (m_titleLabel->text().startsWith("(Building) "))
|
||||
if (m_titleLabel->text().startsWith(tr("(Building) ")))
|
||||
{
|
||||
rebuild();
|
||||
}
|
||||
@@ -592,7 +592,7 @@ void SelectedBuildingPanel::buildSplitterFilters(QPoint splitterTile)
|
||||
const QString& dirLabel,
|
||||
const std::vector<ItemType>& filter)
|
||||
{
|
||||
label->setText(dirLabel + " filter (empty = all):");
|
||||
label->setText(tr("%1 filter (empty = all):").arg(dirLabel));
|
||||
list->blockSignals(true);
|
||||
list->clear();
|
||||
for (const std::string& itemId : items)
|
||||
|
||||
@@ -289,7 +289,7 @@ public:
|
||||
layout->setContentsMargins(4, 4, 4, 4);
|
||||
layout->setSpacing(4);
|
||||
|
||||
QPushButton* createBtn = new QPushButton("Create Blueprint", this);
|
||||
QPushButton* createBtn = new QPushButton(tr("Create Blueprint"), this);
|
||||
createBtn->setFixedHeight(36);
|
||||
layout->addWidget(createBtn);
|
||||
|
||||
@@ -308,7 +308,7 @@ public:
|
||||
connect(createBtn, &QPushButton::clicked, this, [this]() {
|
||||
bool ok = false;
|
||||
const QString name = QInputDialog::getText(
|
||||
this, "Create Blueprint", "Blueprint name:",
|
||||
this, tr("Create Blueprint"), tr("Blueprint name:"),
|
||||
QLineEdit::Normal, QString(), &ok);
|
||||
if (!ok || name.trimmed().isEmpty()) { return; }
|
||||
|
||||
@@ -398,7 +398,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
, m_removeButton(nullptr)
|
||||
, m_gridWidget(nullptr)
|
||||
{
|
||||
setWindowTitle("Configure Ship Layout");
|
||||
setWindowTitle(tr("Configure Ship Layout"));
|
||||
setModal(true);
|
||||
|
||||
// Find the ship's layout grid.
|
||||
@@ -482,7 +482,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
this, &ShipLayoutDialog::onModuleButtonClicked);
|
||||
|
||||
// Remove button.
|
||||
m_removeButton = new QPushButton("Remove", this);
|
||||
m_removeButton = new QPushButton(tr("Remove"), this);
|
||||
m_removeButton->setCheckable(true);
|
||||
m_removeButton->setFixedHeight(48);
|
||||
if (col > 0)
|
||||
@@ -513,8 +513,8 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
|
||||
// Confirm / Cancel buttons.
|
||||
QHBoxLayout* bottomBar = new QHBoxLayout();
|
||||
QPushButton* confirmBtn = new QPushButton("Confirm", this);
|
||||
QPushButton* cancelBtn = new QPushButton("Cancel", this);
|
||||
QPushButton* confirmBtn = new QPushButton(tr("Confirm"), this);
|
||||
QPushButton* cancelBtn = new QPushButton(tr("Cancel"), this);
|
||||
bottomBar->addWidget(confirmBtn);
|
||||
bottomBar->addWidget(cancelBtn);
|
||||
rightLayout->addLayout(bottomBar);
|
||||
|
||||
Reference in New Issue
Block a user