-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split TranslationLoader from ICATranslations, better translation mixins
- Loading branch information
Showing
9 changed files
with
200 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
src/main/java/me/ivan/ivancarpetaddition/mixins/translations/LoggerMixin.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/me/ivan/ivancarpetaddition/translations/TranslationLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package me.ivan.ivancarpetaddition.translations; | ||
|
||
import com.google.gson.Gson; | ||
import me.ivan.ivancarpetaddition.IvanCarpetAdditionServer; | ||
import me.ivan.ivancarpetaddition.utils.FileUtil; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
import java.util.*; | ||
|
||
public class TranslationLoader { | ||
private static final String LANG_DIR = String.format("assets/%s/lang", TranslationConstants.TRANSLATION_NAMESPACE); | ||
|
||
public static void loadTranslations(Map<String, Map<String, String>> translationStorage) { | ||
List<String> languageList; | ||
|
||
try { | ||
String fileContent = FileUtil.readFile(LANG_DIR + "/meta/languages.json"); | ||
languageList = new Gson().fromJson(fileContent, LanguageList.class); | ||
} | ||
catch (Exception e) { | ||
IvanCarpetAdditionServer.LOGGER.error("Failed to read language list", e); | ||
return; | ||
} | ||
|
||
languageList.forEach(lang -> translationStorage.computeIfAbsent(lang, TranslationLoader::loadTranslation)); | ||
} | ||
|
||
private static Map<String, String> loadTranslation(String lang) { | ||
try { | ||
String fileContent = FileUtil.readFile(String.format("%s/%s.json", LANG_DIR, lang)); | ||
return new Gson().fromJson(fileContent, TranslationMapping.class); | ||
} | ||
catch (Exception e) { | ||
String message = "Failed to load translation of language " + lang; | ||
IvanCarpetAdditionServer.LOGGER.error(message, e); | ||
if (FabricLoader.getInstance().isDevelopmentEnvironment()) { | ||
throw new RuntimeException(message, e); | ||
} | ||
return Collections.emptyMap(); | ||
} | ||
} | ||
|
||
private static class LanguageList extends ArrayList<String> {} | ||
private static class TranslationMapping extends LinkedHashMap<String, String> {} | ||
} |
Oops, something went wrong.