mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 10:05:10 -07:00
[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.
This commit is contained in:
parent
fd82b140a8
commit
8bb2337117
35 changed files with 1138 additions and 25 deletions
|
|
@ -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,25 @@ 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);
|
||||
CardInfoPtr card = 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;
|
||||
}
|
||||
for (auto it = localizedNames.constBegin(); it != localizedNames.constEnd(); ++it) {
|
||||
card->setLocalizedName(it.key(), it.value());
|
||||
}
|
||||
for (auto it = localizedTexts.constBegin(); it != localizedTexts.constEnd(); ++it) {
|
||||
card->setLocalizedText(it.key(), it.value());
|
||||
}
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
// ---- FormatRules -----------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue