mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 00:55:09 -07:00
[Client] Show localized card names, texts and pictures (#7294)
* [Client] Show localized card names, texts and pictures
Localization wiring now runs end to end: the oracle importer collects
foreignData for the configured language and the client renders it.
- [Oracle] Import localized names and rules texts for the selected cardLang
- single-face cards store their foreignData name and full text
- multi-face (split/adventure/aftermath/prepare) cards collect the joined
name once and join each face's translated text with the same separator
as the English merge; an incomplete translation falls back to English;
the joined text follows the same highest-priority-set policy as the
single-face path and is only collected when localization is enabled
- the wizard switching languages re-imports the card database
- [Client] Display localized card info throughout the client
- card info text/picture widgets and the game board re-render on language
change
- pictures resolve cardLang art through Scryfall's named endpoint using the
localized name, falling back to id-based art when no match exists
- deck editor keeps canonical English names as card identity (EditRole)
while showing localized names (DisplayRole), so decks and wire names
stay stable
- [Card] Add CardLocalization-backed name/text lookup and cards.xml v4
localization elements with a bounded-size translation cache
- [Tests] Cover oracle foreignData import (incl. multi-face joins, priority
and fallback paths), XML v4 localization parsing, deck model localized
display and the language-aware settings default
Existing installations need to re-run Oracle to see translations: localized
data only lands in cards.xml when the Oracle app is started with the
preferred language selected — launch the separate "Oracle" program that
ships with Cockatrice, pick the language in the wizard and let it re-import
the card database.
The client's database cache (cards.xml.cache) is invalidated by the cache
format bump and the source-hash checks, but a cache written before the
re-import can still hold English-only entries (the hash uses file size and
mtime, so a same-size/same-timestamp rewrite may be served as-is); delete
cards.xml.cache and relaunch if no localized names/texts show up after
re-importing.
* [Card] Pass localized card names and texts into CardInfo construction
Address review: instead of constructing the card and then calling
setLocalizedName/setLocalizedText (which emit a cardInfoChanged signal per
language), both constructors, both newInstance overloads and their callers
(cards.xml v4 parser and the binary cache reader) now pass the localized maps
as constructor arguments.
* [Client] Rename LocalizedCard:: helpers namespace to CardLocalization
The namespace now matches its header file name, as the review pointed out;
LocalizedCard reads more like a class or struct. Callers (card info text
widget, board card name rendering) are updated to match.
* [Client] Drop unused info member from the card info text widget
The CardInfoPtr member was only ever initialized to nullptr and never read;
remove it together with its initializer.
* [PictureLoader] Add the localized picture URL explicitly, not implicitly
Address review: silently prepending the Scryfall named-picture URL to the
download list whenever a non-English card language was active was surprising,
consumed quota per card when it failed, and could grab the wrong (canon) art on
name collisions, with no way to turn it off.
The insert is now opt-in and user-controlled: changing the card language adds
the template to the top of the download URLs once (persisted, documented in the
re-import prompt, and editable/removable in the deck editor settings), while the
picture loader no longer injects it at request time.
* [Card] Show card languages in the same native (English) format as the UI
Address review: the card text & images language dropdown listed bare native
names, some in inconsistent lowercase (e.g. "čeština", "español de España"),
which makes the languages easy to mix up for users that do not read the script
(e.g. 日本語 vs 한국어). It now mirrors the UI language dropdown and always pairs
the native name with its English name (e.g. "Deutsch (German)",
"日本語 (Japanese)"), using the same fixed casing.
---------
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
5ace88c111
commit
1c93309952
37 changed files with 1199 additions and 41 deletions
|
|
@ -5,6 +5,7 @@ set(CMAKE_AUTORCC ON)
|
|||
set(HEADERS
|
||||
libcockatrice/card/card_info.h
|
||||
libcockatrice/card/card_info_comparator.h
|
||||
libcockatrice/card/card_localization.h
|
||||
libcockatrice/card/lazy_properties_hash.h
|
||||
libcockatrice/card/database/card_database.h
|
||||
libcockatrice/card/database/card_database_loader.h
|
||||
|
|
@ -27,6 +28,7 @@ add_library(
|
|||
${MOC_SOURCES}
|
||||
libcockatrice/card/card_info.cpp
|
||||
libcockatrice/card/card_info_comparator.cpp
|
||||
libcockatrice/card/card_localization.cpp
|
||||
libcockatrice/card/lazy_properties_hash.cpp
|
||||
libcockatrice/card/database/card_database.cpp
|
||||
libcockatrice/card/database/card_database_cache.cpp
|
||||
|
|
|
|||
|
|
@ -40,8 +40,11 @@ CardInfo::CardInfo(const QString &_name,
|
|||
const QList<CardRelation *> &_relatedCards,
|
||||
const QList<CardRelation *> &_reverseRelatedCards,
|
||||
SetToPrintingsMap _sets,
|
||||
const UiAttributes _uiAttributes)
|
||||
: name(_name), text(_text), isToken(_isToken), properties(LazyPropertiesHash(_properties)),
|
||||
const UiAttributes _uiAttributes,
|
||||
QMap<QString, QString> _localizedNames,
|
||||
QMap<QString, QString> _localizedTexts)
|
||||
: name(_name), text(_text), isToken(_isToken), localizedNames(std::move(_localizedNames)),
|
||||
localizedTexts(std::move(_localizedTexts)), properties(LazyPropertiesHash(_properties)),
|
||||
relatedCards(_relatedCards), reverseRelatedCards(_reverseRelatedCards), setsToPrintings(std::move(_sets)),
|
||||
uiAttributes(_uiAttributes)
|
||||
{
|
||||
|
|
@ -59,8 +62,11 @@ CardInfo::CardInfo(const QString &_name,
|
|||
SetToPrintingsMap _sets,
|
||||
const UiAttributes _uiAttributes,
|
||||
QString _simpleName,
|
||||
QSet<QString> _altNames)
|
||||
QSet<QString> _altNames,
|
||||
QMap<QString, QString> _localizedNames,
|
||||
QMap<QString, QString> _localizedTexts)
|
||||
: name(_name), simpleName(std::move(_simpleName)), text(_text), isToken(_isToken),
|
||||
localizedNames(std::move(_localizedNames)), localizedTexts(std::move(_localizedTexts)),
|
||||
properties(LazyPropertiesHash(_propertiesBlob)), relatedCards(_relatedCards),
|
||||
reverseRelatedCards(_reverseRelatedCards), setsToPrintings(std::move(_sets)), uiAttributes(_uiAttributes),
|
||||
altNames(std::move(_altNames))
|
||||
|
|
@ -83,10 +89,12 @@ CardInfoPtr CardInfo::newInstance(const QString &_name,
|
|||
const QList<CardRelation *> &_relatedCards,
|
||||
const QList<CardRelation *> &_reverseRelatedCards,
|
||||
SetToPrintingsMap _sets,
|
||||
const UiAttributes _uiAttributes)
|
||||
const UiAttributes _uiAttributes,
|
||||
QMap<QString, QString> _localizedNames,
|
||||
QMap<QString, QString> _localizedTexts)
|
||||
{
|
||||
CardInfoPtr ptr(
|
||||
new CardInfo(_name, _text, _isToken, _properties, _relatedCards, _reverseRelatedCards, _sets, _uiAttributes));
|
||||
CardInfoPtr ptr(new CardInfo(_name, _text, _isToken, _properties, _relatedCards, _reverseRelatedCards, _sets,
|
||||
_uiAttributes, std::move(_localizedNames), std::move(_localizedTexts)));
|
||||
ptr->setSmartPointer(ptr);
|
||||
|
||||
for (const auto &printings : _sets) {
|
||||
|
|
@ -109,11 +117,13 @@ CardInfoPtr CardInfo::newInstance(const QString &_name,
|
|||
const UiAttributes _uiAttributes,
|
||||
QString _simpleName,
|
||||
QSet<QString> _altNames,
|
||||
bool _appendToSets)
|
||||
bool _appendToSets,
|
||||
QMap<QString, QString> _localizedNames,
|
||||
QMap<QString, QString> _localizedTexts)
|
||||
{
|
||||
CardInfoPtr ptr(new CardInfo(_name, _text, _isToken, std::move(_propertiesBlob), _relatedCards,
|
||||
_reverseRelatedCards, _sets, _uiAttributes, std::move(_simpleName),
|
||||
std::move(_altNames)));
|
||||
std::move(_altNames), std::move(_localizedNames), std::move(_localizedTexts)));
|
||||
ptr->setSmartPointer(ptr);
|
||||
|
||||
if (_appendToSets) {
|
||||
|
|
|
|||
|
|
@ -77,6 +77,9 @@ private:
|
|||
QString text; ///< Text description or rules text of the card.
|
||||
bool isToken; ///< Whether this card is a token or not.
|
||||
|
||||
QMap<QString, QString> localizedNames; ///< Localized card names, keyed by language code.
|
||||
QMap<QString, QString> localizedTexts; ///< Localized rules text, keyed by language code.
|
||||
|
||||
LazyPropertiesHash properties; ///< Key-value store of dynamic card properties.
|
||||
|
||||
QList<CardRelation *> relatedCards; ///< Forward references to related cards.
|
||||
|
|
@ -100,6 +103,8 @@ public:
|
|||
* @param _reverseRelatedCards Backward references to related cards.
|
||||
* @param _sets Map of set names to printing information.
|
||||
* @param _uiAttributes Attributes that affect display and game logic
|
||||
* @param _localizedNames Localized card names, keyed by language code.
|
||||
* @param _localizedTexts Localized rules text, keyed by language code.
|
||||
*/
|
||||
explicit CardInfo(const QString &_name,
|
||||
const QString &_text,
|
||||
|
|
@ -108,7 +113,9 @@ public:
|
|||
const QList<CardRelation *> &_relatedCards,
|
||||
const QList<CardRelation *> &_reverseRelatedCards,
|
||||
SetToPrintingsMap _sets,
|
||||
UiAttributes _uiAttributes);
|
||||
UiAttributes _uiAttributes,
|
||||
QMap<QString, QString> _localizedNames = {},
|
||||
QMap<QString, QString> _localizedTexts = {});
|
||||
|
||||
/**
|
||||
* @brief Constructs a CardInfo from a cache snapshot with precomputed derived
|
||||
|
|
@ -130,6 +137,8 @@ public:
|
|||
* @param _uiAttributes Attributes that affect display and game logic.
|
||||
* @param _simpleName Precomputed simplified name.
|
||||
* @param _altNames Precomputed alternate names.
|
||||
* @param _localizedNames Localized card names, keyed by language code.
|
||||
* @param _localizedTexts Localized rules text, keyed by language code.
|
||||
*/
|
||||
explicit CardInfo(const QString &_name,
|
||||
const QString &_text,
|
||||
|
|
@ -140,7 +149,9 @@ public:
|
|||
SetToPrintingsMap _sets,
|
||||
UiAttributes _uiAttributes,
|
||||
QString _simpleName,
|
||||
QSet<QString> _altNames);
|
||||
QSet<QString> _altNames,
|
||||
QMap<QString, QString> _localizedNames = {},
|
||||
QMap<QString, QString> _localizedTexts = {});
|
||||
|
||||
/**
|
||||
* @brief Copy constructor for CardInfo.
|
||||
|
|
@ -151,7 +162,8 @@ public:
|
|||
*/
|
||||
CardInfo(const CardInfo &other)
|
||||
: QObject(other.parent()), name(other.name), simpleName(other.simpleName), text(other.text),
|
||||
isToken(other.isToken), properties(other.properties), relatedCards(other.relatedCards),
|
||||
isToken(other.isToken), localizedNames(other.localizedNames), localizedTexts(other.localizedTexts),
|
||||
properties(other.properties), relatedCards(other.relatedCards),
|
||||
reverseRelatedCards(other.reverseRelatedCards), reverseRelatedCardsToMe(other.reverseRelatedCardsToMe),
|
||||
setsToPrintings(other.setsToPrintings), uiAttributes(other.uiAttributes), setsNames(other.setsNames),
|
||||
altNames(other.altNames)
|
||||
|
|
@ -179,6 +191,8 @@ public:
|
|||
* @param _reverseRelatedCards Reverse relationships.
|
||||
* @param _sets Printing information per set.
|
||||
* @param _uiAttributes Attributes that affect display and game logic
|
||||
* @param _localizedNames Localized card names, keyed by language code.
|
||||
* @param _localizedTexts Localized rules text, keyed by language code.
|
||||
* @return Shared pointer to the new CardInfo instance.
|
||||
*/
|
||||
static CardInfoPtr newInstance(const QString &_name,
|
||||
|
|
@ -188,7 +202,9 @@ public:
|
|||
const QList<CardRelation *> &_relatedCards,
|
||||
const QList<CardRelation *> &_reverseRelatedCards,
|
||||
SetToPrintingsMap _sets,
|
||||
UiAttributes _uiAttributes);
|
||||
UiAttributes _uiAttributes,
|
||||
QMap<QString, QString> _localizedNames = {},
|
||||
QMap<QString, QString> _localizedTexts = {});
|
||||
|
||||
/**
|
||||
* @brief Creates a new instance from a cache snapshot with precomputed
|
||||
|
|
@ -208,6 +224,8 @@ public:
|
|||
* its CardSets. Pass false when building cards in parallel so the
|
||||
* (non-thread-safe) set membership is populated in a later
|
||||
* single-threaded pass.
|
||||
* @param _localizedNames Localized card names, keyed by language code.
|
||||
* @param _localizedTexts Localized rules text, keyed by language code.
|
||||
* @return Shared pointer to the new CardInfo instance.
|
||||
*/
|
||||
static CardInfoPtr newInstance(const QString &_name,
|
||||
|
|
@ -220,7 +238,9 @@ public:
|
|||
UiAttributes _uiAttributes,
|
||||
QString _simpleName,
|
||||
QSet<QString> _altNames,
|
||||
bool _appendToSets = true);
|
||||
bool _appendToSets = true,
|
||||
QMap<QString, QString> _localizedNames = {},
|
||||
QMap<QString, QString> _localizedTexts = {});
|
||||
|
||||
/**
|
||||
* @brief Clones the current CardInfo instance.
|
||||
|
|
@ -270,6 +290,96 @@ public:
|
|||
text = _text;
|
||||
emit cardInfoChanged(smartThis);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the card name in the given language, falling back to the
|
||||
* English name when no localization is available.
|
||||
*
|
||||
* @param lang Language code (e.g. "de", "ja", "zhs").
|
||||
* @return The localized name, or the English name as fallback.
|
||||
*/
|
||||
[[nodiscard]] const QString &getLocalizedName(const QString &lang) const
|
||||
{
|
||||
const auto it = localizedNames.constFind(lang);
|
||||
return it != localizedNames.constEnd() ? it.value() : name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the rules text in the given language, falling back to the
|
||||
* English text when no localization is available.
|
||||
*
|
||||
* @param lang Language code (e.g. "de", "ja", "zhs").
|
||||
* @return The localized text, or the English text as fallback.
|
||||
*/
|
||||
[[nodiscard]] const QString &getLocalizedText(const QString &lang) const
|
||||
{
|
||||
const auto it = localizedTexts.constFind(lang);
|
||||
return it != localizedTexts.constEnd() ? it.value() : text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the localized card names keyed by language code.
|
||||
*
|
||||
* Only languages that have an entry are present; there is no English
|
||||
* fallback in this map.
|
||||
*/
|
||||
[[nodiscard]] const QMap<QString, QString> &getLocalizedNames() const
|
||||
{
|
||||
return localizedNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the localized rules text keyed by language code.
|
||||
*
|
||||
* Only languages that have an entry are present; there is no English
|
||||
* fallback in this map.
|
||||
*/
|
||||
[[nodiscard]] const QMap<QString, QString> &getLocalizedTexts() const
|
||||
{
|
||||
return localizedTexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the card name for the given language.
|
||||
*
|
||||
* @param lang Language code.
|
||||
* @param _localizedName The localized card name.
|
||||
*/
|
||||
void setLocalizedName(const QString &lang, const QString &_localizedName)
|
||||
{
|
||||
if (localizedNames.value(lang) == _localizedName) {
|
||||
return;
|
||||
}
|
||||
localizedNames.insert(lang, _localizedName);
|
||||
emit cardInfoChanged(smartThis);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the rules text for the given language.
|
||||
*
|
||||
* @param lang Language code.
|
||||
* @param _localizedText The localized rules text.
|
||||
*/
|
||||
void setLocalizedText(const QString &lang, const QString &_localizedText)
|
||||
{
|
||||
if (localizedTexts.value(lang) == _localizedText) {
|
||||
return;
|
||||
}
|
||||
localizedTexts.insert(lang, _localizedText);
|
||||
emit cardInfoChanged(smartThis);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the language codes for which this card has a localized
|
||||
* name or rules text.
|
||||
*/
|
||||
[[nodiscard]] QStringList localizationLanguages() const
|
||||
{
|
||||
QStringList languages = localizedNames.keys();
|
||||
languages.append(localizedTexts.keys());
|
||||
languages.removeDuplicates();
|
||||
return languages;
|
||||
}
|
||||
[[nodiscard]] bool getIsToken() const
|
||||
{
|
||||
return isToken;
|
||||
|
|
|
|||
38
libcockatrice_card/libcockatrice/card/card_localization.cpp
Normal file
38
libcockatrice_card/libcockatrice/card/card_localization.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include "card_localization.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QLocale>
|
||||
#include <QStringList>
|
||||
|
||||
namespace CardLocalization
|
||||
{
|
||||
const QStringList &supportedLanguages()
|
||||
{
|
||||
static const QStringList languages = {"cs", "de", "es", "fr", "it", "ja", "ko", "pt", "ru", "zhs", "zht", "he"};
|
||||
return languages;
|
||||
}
|
||||
|
||||
QString languageDisplayName(const QString &lang)
|
||||
{
|
||||
static const QHash<QString, QString> displayNames = {
|
||||
{"cs", "Česky (Czech)"},
|
||||
{"de", "Deutsch (German)"},
|
||||
{"es", "Español (Spanish)"},
|
||||
{"fr", "Français (French)"},
|
||||
{"it", "Italiano (Italian)"},
|
||||
{"ja", "日本語 (Japanese)"},
|
||||
{"ko", "한국어 (Korean)"},
|
||||
{"pt", "Português (Portuguese)"},
|
||||
{"ru", "Русский (Russian)"},
|
||||
{"he", "עברית (Hebrew)"},
|
||||
{"zhs", "简体中文 (Chinese Simplified)"},
|
||||
{"zht", "繁體中文 (Chinese Traditional)"},
|
||||
};
|
||||
const QString displayName = displayNames.value(lang);
|
||||
if (!displayName.isEmpty()) {
|
||||
return displayName;
|
||||
}
|
||||
const QString nativeName = QLocale(lang).nativeLanguageName();
|
||||
return nativeName.isEmpty() ? lang : nativeName;
|
||||
}
|
||||
} // namespace CardLocalization
|
||||
43
libcockatrice_card/libcockatrice/card/card_localization.h
Normal file
43
libcockatrice_card/libcockatrice/card/card_localization.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef CARD_LOCALIZATION_H
|
||||
#define CARD_LOCALIZATION_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
/**
|
||||
* @namespace CardLocalization
|
||||
* @ingroup Cards
|
||||
*
|
||||
* @brief Shared language metadata for localized card text and images.
|
||||
*
|
||||
* Lists the language codes Cockatrice can display localized card data for and
|
||||
* provides human-readable names. The list is shared between Oracle (which
|
||||
* imports the selected language's card data) and the client settings UI (which
|
||||
* offers the language choice).
|
||||
*/
|
||||
namespace CardLocalization
|
||||
{
|
||||
/**
|
||||
* @brief Language codes for which localized card data can be imported/displayed.
|
||||
*
|
||||
* Matches the languages Scryfall can serve localized card images for. "en" is
|
||||
* always available as the default/fallback and is not listed here.
|
||||
*
|
||||
* @return The list of supported language codes.
|
||||
*/
|
||||
[[nodiscard]] const QStringList &supportedLanguages();
|
||||
|
||||
/**
|
||||
* @brief Human-readable name for a language code.
|
||||
*
|
||||
* Follows the same "native name (English name)" format the UI language list
|
||||
* uses (e.g. "日本語 (Japanese)"), so the English fallback is always visible.
|
||||
*
|
||||
* @param lang Language code (e.g. "de", "ja", "zhs").
|
||||
* @return The language's native name with its English name in parentheses, or
|
||||
* the code itself if it cannot be resolved.
|
||||
*/
|
||||
[[nodiscard]] QString languageDisplayName(const QString &lang);
|
||||
} // namespace CardLocalization
|
||||
|
||||
#endif // CARD_LOCALIZATION_H
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
namespace
|
||||
{
|
||||
constexpr quint32 CACHE_MAGIC = 0x43445243; // "CDRC"
|
||||
constexpr quint32 CACHE_VERSION = 2;
|
||||
constexpr quint32 CACHE_VERSION = 3;
|
||||
|
||||
// ---- Primitives -----------------------------------------------------------
|
||||
|
||||
|
|
@ -71,6 +71,35 @@ QDate readDate(QDataStream &in)
|
|||
return d;
|
||||
}
|
||||
|
||||
void writeStringMap(QDataStream &out, const QMap<QString, QString> &map)
|
||||
{
|
||||
out << static_cast<quint32>(map.size());
|
||||
for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
|
||||
writeString(out, it.key());
|
||||
writeString(out, it.value());
|
||||
}
|
||||
}
|
||||
|
||||
QMap<QString, QString> readStringMap(QDataStream &in)
|
||||
{
|
||||
QMap<QString, QString> map;
|
||||
quint32 count = 0;
|
||||
in >> count;
|
||||
if (in.status() != QDataStream::Ok) {
|
||||
return map;
|
||||
}
|
||||
for (quint32 i = 0; i < count; ++i) {
|
||||
QString key = readString(in);
|
||||
QString value = readString(in);
|
||||
if (in.status() != QDataStream::Ok) {
|
||||
map.clear();
|
||||
return map;
|
||||
}
|
||||
map.insert(key, value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// ---- CardRelation ----------------------------------------------------------
|
||||
|
||||
void writeRelation(QDataStream &out, const CardRelation *rel)
|
||||
|
|
@ -195,6 +224,10 @@ void writeCard(QDataStream &out, const CardInfoPtr &card)
|
|||
for (const CardRelation *rel : reverse) {
|
||||
writeRelation(out, rel);
|
||||
}
|
||||
|
||||
// localized card data
|
||||
writeStringMap(out, card->getLocalizedNames());
|
||||
writeStringMap(out, card->getLocalizedTexts());
|
||||
}
|
||||
|
||||
CardInfoPtr readCard(QDataStream &in, const SetNameMap &sets)
|
||||
|
|
@ -268,8 +301,19 @@ CardInfoPtr readCard(QDataStream &in, const SetNameMap &sets)
|
|||
reverse.append(readRelation(in));
|
||||
}
|
||||
|
||||
return CardInfo::newInstance(name, text, isToken, propertiesBlob, related, reverse, cardSets, ui, simpleName,
|
||||
altNames, false);
|
||||
const QMap<QString, QString> localizedNames = readStringMap(in);
|
||||
if (in.status() != QDataStream::Ok) {
|
||||
return nullptr;
|
||||
}
|
||||
const QMap<QString, QString> localizedTexts = readStringMap(in);
|
||||
if (in.status() != QDataStream::Ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CardInfoPtr card = CardInfo::newInstance(name, text, isToken, propertiesBlob, related, reverse, cardSets, ui,
|
||||
simpleName, altNames, false, localizedNames, localizedTexts);
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
// ---- FormatRules -----------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -273,6 +273,8 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
QString name = QString("");
|
||||
QString text = QString("");
|
||||
QHash<QString, QString> properties;
|
||||
QMap<QString, QString> localizedNames;
|
||||
QMap<QString, QString> localizedTexts;
|
||||
QList<CardRelation *> relatedCards, reverseRelatedCards;
|
||||
auto _sets = SetToPrintingsMap();
|
||||
int tableRow = 0;
|
||||
|
|
@ -298,6 +300,44 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
// generic properties
|
||||
} else if (xmlName == "prop") {
|
||||
properties = loadCardPropertiesFromXml(xml);
|
||||
// localized card data
|
||||
} else if (xmlName == "localizations") {
|
||||
while (!xml.atEnd()) {
|
||||
if (xml.readNextStartElement()) {
|
||||
const QString elementName = xml.name().toString();
|
||||
if (elementName == "localization") {
|
||||
const QString lang = xml.attributes().value("lang").toString();
|
||||
QString localizedName;
|
||||
QString localizedText;
|
||||
while (!xml.atEnd()) {
|
||||
if (xml.readNext() == QXmlStreamReader::EndElement) {
|
||||
break;
|
||||
}
|
||||
if (xml.isStartElement()) {
|
||||
const QString childName = xml.name().toString();
|
||||
QString value = xml.readElementText(QXmlStreamReader::IncludeChildElements);
|
||||
if (childName == "name") {
|
||||
localizedName = value;
|
||||
} else if (childName == "text") {
|
||||
localizedText = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!lang.isEmpty()) {
|
||||
if (!localizedName.isEmpty()) {
|
||||
localizedNames.insert(lang, localizedName);
|
||||
}
|
||||
if (!localizedText.isEmpty()) {
|
||||
localizedTexts.insert(lang, localizedText);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
xml.skipCurrentElement();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// positioning info
|
||||
} else if (xmlName == "tablerow") {
|
||||
tableRow = xml.readElementText(QXmlStreamReader::IncludeChildElements).toInt();
|
||||
|
|
@ -399,8 +439,9 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
.landscapeOrientation = landscapeOrientation,
|
||||
.tableRow = tableRow,
|
||||
.upsideDownArt = upsideDown};
|
||||
CardInfoPtr newCard = CardInfo::newInstance(name, text, isToken, properties, relatedCards,
|
||||
reverseRelatedCards, _sets, attributes);
|
||||
CardInfoPtr newCard =
|
||||
CardInfo::newInstance(name, text, isToken, properties, relatedCards, reverseRelatedCards, _sets,
|
||||
attributes, std::move(localizedNames), std::move(localizedTexts));
|
||||
if (targetData) {
|
||||
// Mirror CardDatabase::addCard: if a card with this name already
|
||||
// exists, merge the new printings into it instead of replacing.
|
||||
|
|
@ -517,6 +558,26 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
|
|||
}
|
||||
xml.writeEndElement();
|
||||
|
||||
// localized card data
|
||||
const QStringList localizedLanguages = info->localizationLanguages();
|
||||
if (!localizedLanguages.isEmpty()) {
|
||||
xml.writeStartElement("localizations");
|
||||
const QMap<QString, QString> &localizedNames = info->getLocalizedNames();
|
||||
const QMap<QString, QString> &localizedTexts = info->getLocalizedTexts();
|
||||
for (const QString &lang : localizedLanguages) {
|
||||
xml.writeStartElement("localization");
|
||||
xml.writeAttribute("lang", lang);
|
||||
if (localizedNames.contains(lang)) {
|
||||
xml.writeTextElement("name", localizedNames.value(lang));
|
||||
}
|
||||
if (localizedTexts.contains(lang)) {
|
||||
xml.writeTextElement("text", localizedTexts.value(lang));
|
||||
}
|
||||
xml.writeEndElement();
|
||||
}
|
||||
xml.writeEndElement();
|
||||
}
|
||||
|
||||
// sets
|
||||
for (const auto &printings : info->getSets()) {
|
||||
for (const PrintingInfo &set : printings) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue