mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-17 00:07:41 +02:00
Remove unused identifiers
This commit is contained in:
@ -1275,6 +1275,7 @@ void CMapLoaderJson::readTranslations()
|
|||||||
if(isExistArchive(language.identifier + ".json"))
|
if(isExistArchive(language.identifier + ".json"))
|
||||||
mapHeader->translations.Struct()[language.identifier] = getFromArchive(language.identifier + ".json");
|
mapHeader->translations.Struct()[language.identifier] = getFromArchive(language.identifier + ".json");
|
||||||
}
|
}
|
||||||
|
mapHeader->registerMapStrings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -401,6 +401,8 @@ void MainWindow::saveMap()
|
|||||||
QMessageBox::information(this, "Map validation", "Map has some errors. Open Validator from the Map menu to see issues found");
|
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;
|
CMapService mapService;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -15,6 +15,44 @@
|
|||||||
#include "../../lib/CGeneralTextHandler.h"
|
#include "../../lib/CGeneralTextHandler.h"
|
||||||
#include "../../lib/VCMI_Lib.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) :
|
Translations::Translations(CMapHeader & mh, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::Translations),
|
ui(new Ui::Translations),
|
||||||
@ -41,6 +79,7 @@ Translations::~Translations()
|
|||||||
|
|
||||||
void Translations::fillTranslationsTable(const std::string & language)
|
void Translations::fillTranslationsTable(const std::string & language)
|
||||||
{
|
{
|
||||||
|
Translations::cleanupRemovedItems(dynamic_cast<CMap&>(mapHeader));
|
||||||
auto & translation = mapHeader.translations[language];
|
auto & translation = mapHeader.translations[language];
|
||||||
ui->translationsTable->blockSignals(true);
|
ui->translationsTable->blockSignals(true);
|
||||||
ui->translationsTable->setRowCount(0);
|
ui->translationsTable->setRowCount(0);
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "../lib/mapping/CMapHeader.h"
|
#include "../lib/mapping/CMap.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Translations;
|
class Translations;
|
||||||
@ -27,6 +27,10 @@ public:
|
|||||||
explicit Translations(CMapHeader & mapHeader, QWidget *parent = nullptr);
|
explicit Translations(CMapHeader & mapHeader, QWidget *parent = nullptr);
|
||||||
~Translations();
|
~Translations();
|
||||||
|
|
||||||
|
//removes unused string IDs from map translations
|
||||||
|
static void cleanupRemovedItems(CMap & map);
|
||||||
|
static void cleanupRemovedItems(CMap & map, const std::string & pattern);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_languageSelect_currentIndexChanged(int index);
|
void on_languageSelect_currentIndexChanged(int index);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user