[client] If on object creation id and name are equal the client tries to set a language aware name
e.g. "train_1" -> "Train 1"
Dieser Commit ist enthalten in:
Ursprung
c3056d7977
Commit
b4939fc83e
@ -46,6 +46,7 @@
|
||||
#include "../network/object/nxbuttonrailtile.hpp"
|
||||
#include "../theme/theme.hpp"
|
||||
#include "../utils/enum.hpp"
|
||||
#include "../utils/trysetlocalename.hpp"
|
||||
#include "../settings/boardsettings.hpp"
|
||||
#include <traintastic/utils/clamp.hpp>
|
||||
|
||||
@ -554,8 +555,15 @@ void BoardWidget::tileClicked(int16_t x, int16_t y)
|
||||
const Qt::KeyboardModifiers kbMod = QApplication::keyboardModifiers();
|
||||
if(kbMod == Qt::NoModifier || kbMod == Qt::ControlModifier)
|
||||
m_object->addTile(x, y, m_boardArea->mouseMoveTileRotate(), classId, kbMod == Qt::ControlModifier,
|
||||
[](const bool& /*r*/, std::optional<const Error> /*error*/)
|
||||
[this, x, y](const bool& r, std::optional<const Error> /*error*/)
|
||||
{
|
||||
if(r)
|
||||
{
|
||||
if(auto object = m_object->getTileObject({x, y}))
|
||||
{
|
||||
trySetLocaleName(*object);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
46
client/src/utils/trysetlocalename.cpp
Normale Datei
46
client/src/utils/trysetlocalename.cpp
Normale Datei
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* This file is part of Traintastic,
|
||||
* see <https://github.com/traintastic/traintastic>.
|
||||
*
|
||||
* Copyright (C) 2025 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "trysetlocalename.hpp"
|
||||
#include <traintastic/locale/locale.hpp>
|
||||
#include "../network/abstractproperty.hpp"
|
||||
#include "../network/object.hpp"
|
||||
|
||||
void trySetLocaleName(Object& object)
|
||||
{
|
||||
if(auto* name = object.getProperty("name"))
|
||||
{
|
||||
if(auto* id = object.getProperty("id"); id && id->toString() == name->toString())
|
||||
{
|
||||
auto value = id->toString();
|
||||
if(int pos = value.lastIndexOf("_"); pos >= 0)
|
||||
{
|
||||
auto prefix = value.first(pos);
|
||||
auto number = value.last(value.size() - pos - 1);
|
||||
auto term = QString("default_name:").append(prefix);
|
||||
if(Locale::instance->exists(term))
|
||||
{
|
||||
name->setValueString(QString("%1 %2").arg(Locale::tr(term)).arg(number));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
client/src/utils/trysetlocalename.hpp
Normale Datei
29
client/src/utils/trysetlocalename.hpp
Normale Datei
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* This file is part of Traintastic,
|
||||
* see <https://github.com/traintastic/traintastic>.
|
||||
*
|
||||
* Copyright (C) 2025 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef TRAINTASTIC_CLIENT_UTILS_TRYSETLOCALENAME_HPP
|
||||
#define TRAINTASTIC_CLIENT_UTILS_TRYSETLOCALENAME_HPP
|
||||
|
||||
class Object;
|
||||
|
||||
void trySetLocaleName(Object& object);
|
||||
|
||||
#endif
|
||||
@ -36,7 +36,7 @@
|
||||
#include "../../misc/methodaction.hpp"
|
||||
#include "../../dialog/objectselectlistdialog.hpp"
|
||||
#include "../../utils/enum.hpp"
|
||||
|
||||
#include "../../utils/trysetlocalename.hpp"
|
||||
|
||||
#include "../../mainwindow.hpp"
|
||||
|
||||
@ -70,6 +70,7 @@ ObjectListWidget::ObjectListWidget(const ObjectPtr& object_, QWidget* parent) :
|
||||
m_requestIdCreate = Connection::invalidRequestId;
|
||||
if(addedObject)
|
||||
{
|
||||
trySetLocaleName(*addedObject);
|
||||
objectCreated(addedObject);
|
||||
}
|
||||
// TODO: show error
|
||||
@ -109,6 +110,7 @@ ObjectListWidget::ObjectListWidget(const ObjectPtr& object_, QWidget* parent) :
|
||||
m_requestIdCreate = Connection::invalidRequestId;
|
||||
if(addedObject)
|
||||
{
|
||||
trySetLocaleName(*addedObject);
|
||||
objectCreated(addedObject);
|
||||
}
|
||||
// TODO: show error
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019-2020,2023 Reinder Feenstra
|
||||
* Copyright (C) 2019-2025 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -74,6 +74,14 @@ void Locale::enableMissingLogging()
|
||||
}
|
||||
|
||||
#ifdef QT_CORE_LIB
|
||||
bool Locale::exists(const QString& id) const
|
||||
{
|
||||
QByteArray b = id.toLatin1();
|
||||
return
|
||||
m_strings.contains({b.data(), static_cast<std::string_view::size_type>(b.length())}) ||
|
||||
(m_fallback && m_fallback->exists(id));
|
||||
}
|
||||
|
||||
QString Locale::translate(const QString& id) const
|
||||
{
|
||||
QByteArray b = id.toLatin1();
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019-2020,2023 Reinder Feenstra
|
||||
* Copyright (C) 2019-2025 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -62,6 +62,7 @@ class Locale
|
||||
void enableMissingLogging();
|
||||
|
||||
#ifdef QT_CORE_LIB
|
||||
bool exists(const QString& id) const;
|
||||
QString translate(const QString& id) const;
|
||||
QString parse(const QString& text) const;
|
||||
#else
|
||||
|
||||
@ -587,6 +587,66 @@
|
||||
"term": "decoupler_state:deactivated",
|
||||
"definition": "Deactivated"
|
||||
},
|
||||
{
|
||||
"term": "default_name:block",
|
||||
"definition": "Block"
|
||||
},
|
||||
{
|
||||
"term": "default_name:board",
|
||||
"definition": "Board"
|
||||
},
|
||||
{
|
||||
"term": "default_name:decoupler",
|
||||
"definition": "Decoupler"
|
||||
},
|
||||
{
|
||||
"term": "default_name:direction",
|
||||
"definition": "Direction"
|
||||
},
|
||||
{
|
||||
"term": "default_name:link",
|
||||
"definition": "Link"
|
||||
},
|
||||
{
|
||||
"term": "default_name:nx_button",
|
||||
"definition": "NX button"
|
||||
},
|
||||
{
|
||||
"term": "default_name:push_button",
|
||||
"definition": "Push button"
|
||||
},
|
||||
{
|
||||
"term": "default_name:script",
|
||||
"definition": "Script"
|
||||
},
|
||||
{
|
||||
"term": "default_name:sensor",
|
||||
"definition": "Sensor"
|
||||
},
|
||||
{
|
||||
"term": "default_name:signal",
|
||||
"definition": "Signal"
|
||||
},
|
||||
{
|
||||
"term": "default_name:switch",
|
||||
"definition": "Switch"
|
||||
},
|
||||
{
|
||||
"term": "default_name:train",
|
||||
"definition": "Train"
|
||||
},
|
||||
{
|
||||
"term": "default_name:turnout",
|
||||
"definition": "Turnout"
|
||||
},
|
||||
{
|
||||
"term": "default_name:vehicle",
|
||||
"definition": "Vehicle"
|
||||
},
|
||||
{
|
||||
"term": "default_name:zone",
|
||||
"definition": "Zone"
|
||||
},
|
||||
{
|
||||
"term": "direction:forward",
|
||||
"definition": "Forward"
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren