Skip to content

Commit

Permalink
Fix GT lang not accepting en_US string updates (GTNewHorizons#2552)
Browse files Browse the repository at this point in the history
  • Loading branch information
miozune authored Mar 30, 2024
1 parent 5c64e9b commit 2267936
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/main/java/gregtech/api/util/GT_LanguageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class GT_LanguageManager {
* it's not necessarily English, but on system it's always treated as English (as in, "default" language.)
*/
public static Configuration sEnglishFile;
/**
* If the game is running with en_US language. This does not get updated when user changes language in game;
* GT lang system cannot handle that anyway.
*/
public static boolean isEN_US;
/**
* If placeholder like %material should be used for writing lang entries to file.
*/
Expand Down Expand Up @@ -125,14 +130,25 @@ private static synchronized String writeToLangFile(String trimmedKey, String aEn
sEnglishFile.save();
hasUnsavedEntry = false;
}
if (!tProperty.wasRead()) {
if (GregTech_API.sPostloadFinished) {
sEnglishFile.save();
} else {
hasUnsavedEntry = true;
String translation = tProperty.getString();
if (tProperty.wasRead()) {
if (isEN_US && !aEnglish.equals(translation)) {
tProperty.set(aEnglish);
markFileDirty();
return aEnglish;
}
} else {
markFileDirty();
}
return translation;
}

private static synchronized void markFileDirty() {
if (GregTech_API.sPostloadFinished) {
sEnglishFile.save();
} else {
hasUnsavedEntry = true;
}
return tProperty.getString();
}

public static String getTranslation(String aKey) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/gregtech/loaders/preload/GT_PreLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public static void initLocalization(File languageDir) {
GT_FML_LOGGER.info("User lang is " + userLang);
if (userLang.equals("en_US")) {
GT_FML_LOGGER.info("Loading GregTech.lang");
GT_LanguageManager.isEN_US = true;
GT_LanguageManager.sEnglishFile = new Configuration(new File(languageDir, "GregTech.lang"));
} else {
String l10nFileName = "GregTech_" + userLang + ".lang";
Expand All @@ -113,10 +114,12 @@ public static void initLocalization(File languageDir) {
GT_LanguageManager.sEnglishFile = new Configuration(l10nFile);
} else {
GT_FML_LOGGER.info("Cannot find l10n file " + l10nFileName + ", fallback to GregTech.lang");
GT_LanguageManager.isEN_US = true;
GT_LanguageManager.sEnglishFile = new Configuration(new File(languageDir, "GregTech.lang"));
}
}
} else {
GT_LanguageManager.isEN_US = true;
GT_LanguageManager.sEnglishFile = new Configuration(new File(languageDir, "GregTech.lang"));
}
GT_LanguageManager.sEnglishFile.load();
Expand Down

0 comments on commit 2267936

Please sign in to comment.