mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Preload translations in FModel.
Add cardname translations in CardDetailUtil. Removed translated flavors in CardTranslations. Only remove diacritics in mobile port.
This commit is contained in:
@@ -113,10 +113,10 @@ public class Localizer {
|
||||
observer.localizationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Language {
|
||||
public String languageName;
|
||||
public String langaugeID;
|
||||
}
|
||||
|
||||
public String languageID;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,7 @@ public class CardDetailUtil {
|
||||
if (area.length() != 0) {
|
||||
area.append("\n");
|
||||
}
|
||||
String text = card.getText(state);
|
||||
String text = CardTranslation.getTranslatedOracle(card.getName(), card.getText(state));
|
||||
// LEVEL [0-9]+-[0-9]+
|
||||
// LEVEL [0-9]+\+
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package forge.card;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import com.google.common.base.Charsets;
|
||||
import forge.GuiBase;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.util.LineReader;
|
||||
@@ -13,40 +15,34 @@ import java.util.Map;
|
||||
|
||||
public class CardTranslation {
|
||||
|
||||
public static Map <String, String> translatednames;
|
||||
public static Map <String, String> translatedtypes;
|
||||
public static Map <String, String> translatedoracles;
|
||||
public static Map <String, String> translatedflavors;
|
||||
private static Map <String, String> translatednames;
|
||||
private static Map <String, String> translatedtypes;
|
||||
private static Map <String, String> translatedoracles;
|
||||
|
||||
private static String removeDiacritics(String text) {
|
||||
text = text.replace("ñ", "ny");
|
||||
text = Normalizer.normalize(text, Normalizer.Form.NFD);
|
||||
text = text.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
|
||||
text = text.replace("ñ", "ny");
|
||||
return text;
|
||||
}
|
||||
|
||||
private static void readTranslationFile(String language) {
|
||||
String filename = "cardnames-" + language + ".txt";
|
||||
|
||||
try (LineReader translationFile = new LineReader(new FileInputStream(ForgeConstants.LANG_DIR + filename))) {
|
||||
|
||||
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], removeDiacritics(matches[1]));
|
||||
translatednames.put(matches[0], matches[1]);
|
||||
}
|
||||
|
||||
if(matches.length >= 3) {
|
||||
translatedtypes.put(matches[0], removeDiacritics(matches[2]));
|
||||
translatedtypes.put(matches[0], matches[2]);
|
||||
}
|
||||
|
||||
if(matches.length >= 4) {
|
||||
translatedoracles.put(matches[0], removeDiacritics(matches[3]).replace("\\n", "\n\n"));
|
||||
}
|
||||
|
||||
if(matches.length >= 5) {
|
||||
translatedflavors.put(matches[0], removeDiacritics(matches[4]));
|
||||
translatedoracles.put(matches[0], matches[3].replace("\\n", "\n\n"));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -54,8 +50,45 @@ public class CardTranslation {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean needsTranslation() {
|
||||
return !ForgePreferences.FPref.UI_LANGUAGE.toString().equals("en-US");
|
||||
static String getTranslatedName(String name) {
|
||||
String tname = translatednames.get(name);
|
||||
|
||||
if (tname != null) {
|
||||
if (GuiBase.getInterface().isLibgdxPort()) tname = removeDiacritics(tname);
|
||||
} else {
|
||||
tname = name;
|
||||
}
|
||||
|
||||
return tname;
|
||||
}
|
||||
|
||||
static String getTranslatedType(String name, String originaltype) {
|
||||
String ttype = translatedtypes.get(name);
|
||||
|
||||
if (ttype != null) {
|
||||
if (GuiBase.getInterface().isLibgdxPort()) ttype = removeDiacritics(ttype);
|
||||
} else {
|
||||
ttype = originaltype;
|
||||
}
|
||||
|
||||
return ttype;
|
||||
}
|
||||
|
||||
static String getTranslatedOracle(String name, String originaloracle) {
|
||||
String toracle = translatedoracles.get(name);
|
||||
|
||||
if (toracle != null) {
|
||||
if (GuiBase.getInterface().isLibgdxPort()) toracle = removeDiacritics(toracle);
|
||||
} else {
|
||||
toracle = originaloracle;
|
||||
}
|
||||
|
||||
return toracle;
|
||||
}
|
||||
|
||||
private static boolean needsTranslation() {
|
||||
ForgePreferences preferences = new ForgePreferences();
|
||||
return !preferences.getPref(ForgePreferences.FPref.UI_LANGUAGE).equals("en-US");
|
||||
}
|
||||
|
||||
public static void preloadTranslation(String language) {
|
||||
@@ -63,8 +96,7 @@ public class CardTranslation {
|
||||
translatednames = new HashMap<>();
|
||||
translatedtypes = new HashMap<>();
|
||||
translatedoracles = new HashMap<>();
|
||||
translatedflavors = new HashMap<>();
|
||||
readTranslationFile(ForgePreferences.FPref.UI_LANGUAGE.toString());
|
||||
readTranslationFile(language);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user