mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Remove unused identifiers
This commit is contained in:
parent
38d12bbe8c
commit
ae073ee35d
@ -1275,6 +1275,7 @@ void CMapLoaderJson::readTranslations()
|
||||
if(isExistArchive(language.identifier + ".json"))
|
||||
mapHeader->translations.Struct()[language.identifier] = getFromArchive(language.identifier + ".json");
|
||||
}
|
||||
mapHeader->registerMapStrings();
|
||||
}
|
||||
|
||||
|
||||
|
@ -400,6 +400,8 @@ void MainWindow::saveMap()
|
||||
else
|
||||
QMessageBox::information(this, "Map validation", "Map has some errors. Open Validator from the Map menu to see issues found");
|
||||
}
|
||||
|
||||
Translations::cleanupRemovedItems(*controller.map());
|
||||
|
||||
CMapService mapService;
|
||||
try
|
||||
|
@ -15,6 +15,44 @@
|
||||
#include "../../lib/CGeneralTextHandler.h"
|
||||
#include "../../lib/VCMI_Lib.h"
|
||||
|
||||
void Translations::cleanupRemovedItems(CMap & map)
|
||||
{
|
||||
std::set<std::string> existingObjects;
|
||||
for(auto object : map.objects)
|
||||
existingObjects.insert(object->instanceName);
|
||||
|
||||
for(auto & translations : map.translations.Struct())
|
||||
{
|
||||
auto updateTranslations = JsonNode(JsonNode::JsonType::DATA_STRUCT);
|
||||
for(auto & s : translations.second.Struct())
|
||||
{
|
||||
for(auto part : QString::fromStdString(s.first).split('.'))
|
||||
{
|
||||
if(existingObjects.count(part.toStdString()))
|
||||
{
|
||||
updateTranslations.Struct()[s.first] = s.second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
translations.second = updateTranslations;
|
||||
}
|
||||
}
|
||||
|
||||
void Translations::cleanupRemovedItems(CMap & map, const std::string & pattern)
|
||||
{
|
||||
for(auto & translations : map.translations.Struct())
|
||||
{
|
||||
auto updateTranslations = JsonNode(JsonNode::JsonType::DATA_STRUCT);
|
||||
for(auto & s : translations.second.Struct())
|
||||
{
|
||||
if(s.first.find(pattern) == std::string::npos)
|
||||
updateTranslations.Struct()[s.first] = s.second;
|
||||
}
|
||||
translations.second = updateTranslations;
|
||||
}
|
||||
}
|
||||
|
||||
Translations::Translations(CMapHeader & mh, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::Translations),
|
||||
@ -41,6 +79,7 @@ Translations::~Translations()
|
||||
|
||||
void Translations::fillTranslationsTable(const std::string & language)
|
||||
{
|
||||
Translations::cleanupRemovedItems(dynamic_cast<CMap&>(mapHeader));
|
||||
auto & translation = mapHeader.translations[language];
|
||||
ui->translationsTable->blockSignals(true);
|
||||
ui->translationsTable->setRowCount(0);
|
||||
|
@ -11,7 +11,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "../lib/mapping/CMapHeader.h"
|
||||
#include "../lib/mapping/CMap.h"
|
||||
|
||||
namespace Ui {
|
||||
class Translations;
|
||||
@ -26,6 +26,10 @@ class Translations : public QDialog
|
||||
public:
|
||||
explicit Translations(CMapHeader & mapHeader, QWidget *parent = nullptr);
|
||||
~Translations();
|
||||
|
||||
//removes unused string IDs from map translations
|
||||
static void cleanupRemovedItems(CMap & map);
|
||||
static void cleanupRemovedItems(CMap & map, const std::string & pattern);
|
||||
|
||||
private slots:
|
||||
void on_languageSelect_currentIndexChanged(int index);
|
||||
|
Loading…
Reference in New Issue
Block a user