mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Merge remote-tracking branch 'remotes/core/master'
This commit is contained in:
@@ -160,11 +160,13 @@ public class CardDetailUtil {
|
||||
|
||||
public static String formatCardName(final CardView card, final boolean canShow, final boolean forAltState) {
|
||||
final String name = forAltState ? card.getAlternateState().getName() : card.getName();
|
||||
return StringUtils.isEmpty(name) || !canShow ? "???" : name.trim();
|
||||
String translatedname = CardTranslation.getTranslatedName(name);
|
||||
return StringUtils.isEmpty(translatedname) || !canShow ? "???" : translatedname.trim();
|
||||
}
|
||||
|
||||
public static String formatCardType(final CardStateView card, final boolean canShow) {
|
||||
return canShow ? card.getType().toString() : (card.getState() == CardStateName.FaceDown ? "Creature" : "---");
|
||||
String translatedtype = CardTranslation.getTranslatedType(card.getName(), card.getType().toString());
|
||||
return canShow ? translatedtype : (card.getState() == CardStateName.FaceDown ? "Creature" : "---");
|
||||
}
|
||||
|
||||
public static String formatPowerToughness(final CardStateView card, final boolean canShow) {
|
||||
@@ -276,7 +278,9 @@ public class CardDetailUtil {
|
||||
if (area.length() != 0) {
|
||||
area.append("\n");
|
||||
}
|
||||
String text = card.getText(state);
|
||||
|
||||
String text = card.getText(state, CardTranslation.getTranslationTexts(state.getName(), ""));
|
||||
|
||||
// LEVEL [0-9]+-[0-9]+
|
||||
// LEVEL [0-9]+\+
|
||||
|
||||
|
||||
91
forge-gui/src/main/java/forge/card/CardTranslation.java
Normal file
91
forge-gui/src/main/java/forge/card/CardTranslation.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package forge.card;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import com.google.common.base.Charsets;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.util.LineReader;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CardTranslation {
|
||||
|
||||
private static Map <String, String> translatednames;
|
||||
private static Map <String, String> translatedtypes;
|
||||
private static Map <String, String> translatedoracles;
|
||||
private static String languageSelected;
|
||||
|
||||
private static void readTranslationFile(String language) {
|
||||
String filename = "cardnames-" + language + ".txt";
|
||||
|
||||
try (LineReader translationFile = new LineReader(new FileInputStream(ForgeConstants.LANG_DIR + filename), Charsets.UTF_8)) {
|
||||
for (String line : translationFile.readLines()) {
|
||||
String[] matches = line.split("\\|");
|
||||
if (matches.length >= 2) {
|
||||
translatednames.put(matches[0], matches[1]);
|
||||
}
|
||||
if (matches.length >= 3) {
|
||||
translatedtypes.put(matches[0], matches[2]);
|
||||
}
|
||||
if (matches.length >= 4) {
|
||||
translatedoracles.put(matches[0], matches[3].replace("\\n", "\n\n"));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Error reading translation file: cardnames-" + language + ".txt");
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTranslatedName(String name) {
|
||||
if (needsTranslation()) {
|
||||
String tname = translatednames.get(name);
|
||||
return tname == null ? name : tname;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public static String getTranslatedType(String name, String originaltype) {
|
||||
if (needsTranslation()) {
|
||||
String ttype = translatedtypes.get(name);
|
||||
return ttype == null ? originaltype : ttype;
|
||||
}
|
||||
|
||||
return originaltype;
|
||||
}
|
||||
|
||||
public static String getTranslatedOracle(String name) {
|
||||
if (needsTranslation()) {
|
||||
String toracle = translatedoracles.get(name);
|
||||
return toracle == null ? "" : toracle;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getTranslationTexts(String cardname, String altcardname) {
|
||||
HashMap<String, String> translations = new HashMap<String, String>();
|
||||
translations.put("name", getTranslatedName(cardname));
|
||||
translations.put("oracle", getTranslatedOracle(cardname));
|
||||
translations.put("altname", getTranslatedName(altcardname));
|
||||
translations.put("altoracle", getTranslatedOracle(altcardname));
|
||||
return translations;
|
||||
}
|
||||
|
||||
private static boolean needsTranslation() {
|
||||
return !languageSelected.equals("en-US");
|
||||
}
|
||||
|
||||
public static void preloadTranslation(String language) {
|
||||
languageSelected = language;
|
||||
|
||||
if (needsTranslation()) {
|
||||
translatednames = new HashMap<>();
|
||||
translatedtypes = new HashMap<>();
|
||||
translatedoracles = new HashMap<>();
|
||||
readTranslationFile(languageSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import forge.CardStorageReader.ProgressObserver;
|
||||
import forge.achievement.*;
|
||||
import forge.ai.AiProfileUtil;
|
||||
import forge.card.CardPreferences;
|
||||
import forge.card.CardTranslation;
|
||||
import forge.card.CardType;
|
||||
import forge.deck.CardArchetypeLDAGenerator;
|
||||
import forge.deck.CardRelationMatrixGenerator;
|
||||
@@ -146,6 +147,7 @@ public final class FModel {
|
||||
final CardStorageReader tokenReader = new CardStorageReader(ForgeConstants.TOKEN_DATA_DIR, progressBarBridge,
|
||||
FModel.getPreferences().getPrefBoolean(FPref.LOAD_CARD_SCRIPTS_LAZILY));
|
||||
magicDb = new StaticData(reader, tokenReader, ForgeConstants.EDITIONS_DIR, ForgeConstants.BLOCK_DATA_DIR);
|
||||
CardTranslation.preloadTranslation(preferences.getPref(FPref.UI_LANGUAGE));
|
||||
|
||||
//create profile dirs if they don't already exist
|
||||
for (final String dname : ForgeConstants.PROFILE_DIRS) {
|
||||
|
||||
@@ -2433,9 +2433,9 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
||||
TextUtil.concatWithSpace("Should", forgeCard.toString(), "be added to the top or to the bottom of the library?"), true, Arrays.asList("Top", "Bottom"));
|
||||
}
|
||||
if (lastTopOfTheLibrary) {
|
||||
game.getAction().moveToLibrary(forgeCard, null, null);
|
||||
game.getAction().moveToLibrary(forgeCard, null);
|
||||
} else {
|
||||
game.getAction().moveToBottomOfLibrary(forgeCard, null, null);
|
||||
game.getAction().moveToBottomOfLibrary(forgeCard, null);
|
||||
}
|
||||
} else {
|
||||
game.getAction().moveTo(targetZone, forgeCard, null);
|
||||
|
||||
Reference in New Issue
Block a user