Skip to content

Commit 2779ce3

Browse files
committed
add comments
1 parent 1541ca4 commit 2779ce3

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/main/java/org/maxgamer/quickshop/util/language/text/TextManager.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,46 @@ private File getOverrideFilesFolder(@NotNull String crowdinPath) {
4848
return folder;
4949
}
5050

51-
public void load() {
52-
plugin.getLogger().info("Checking for translation updates...");
51+
private void reset(){
5352
locale2ContentMapping.clear();
5453
postProcessors.clear();
55-
// Load mapping
56-
//for (String availableFile : distribution.getAvailableFiles()) {
54+
}
55+
56+
private void loadBundled(){
5757
try {
5858
bundledLang.loadFromString(new String(IOUtils.toByteArray(new InputStreamReader(plugin.getResource("lang-original/messages.json")), StandardCharsets.UTF_8)));
5959
} catch (IOException | InvalidConfigurationException ex) {
6060
bundledLang = new JsonConfiguration();
6161
plugin.getLogger().log(Level.SEVERE, "Cannot load bundled language file from Jar, some strings may missing!", ex);
6262
}
63-
// init file mapping
64-
locale2ContentMapping.computeIfAbsent(languageFileCrowdin, e -> new HashMap<>());
65-
// Multi File and Multi-Language loader
63+
}
6664

65+
public void load() {
66+
plugin.getLogger().info("Checking for translation updates...");
67+
this.reset();
68+
69+
// Read bundled language files
70+
this.loadBundled();
71+
// Initial file mapping
72+
locale2ContentMapping.computeIfAbsent(languageFileCrowdin, e -> new HashMap<>()); // Prevent nullportinter exception
73+
distribution.getAvailableFiles().forEach(file-> locale2ContentMapping.computeIfAbsent(file, e -> new HashMap<>()));
6774

75+
// Multi File and Multi-Language loader
6876
distribution.getAvailableLanguages().parallelStream().forEach(crowdinCode -> distribution.getAvailableFiles().parallelStream().forEach(crowdinFile -> {
6977
try {
70-
// load OTA text from Crowdin
71-
78+
// Minecraft client use lowercase wi
7279
String minecraftCode = crowdinCode.toLowerCase(Locale.ROOT).replace("-", "_");
73-
7480
Util.debugLog("Loading translation for locale: " + crowdinCode + " (" + minecraftCode + ")");
7581
JsonConfiguration configuration = new JsonConfiguration();
7682
try {
83+
// Load the locale file from local cache if available
84+
// Or load the locale file from remote server if it had updates or not exists.
7785
configuration.loadFromString(distribution.getFile(crowdinFile, crowdinCode));
7886
} catch (InvalidConfigurationException exception) {
87+
// Force loading the locale file form remote server because file not valid.
7988
configuration.loadFromString(distribution.getFile(crowdinFile, crowdinCode, true));
8089
}
81-
// load override text (allow user modification the translation)
82-
// TODO: full multi-file support
90+
// Loading override text (allow user modification the translation)
8391
JsonConfiguration override = new JsonConfiguration();
8492
File localOverrideFile = new File(getOverrideFilesFolder(crowdinFile), minecraftCode + ".json");
8593
if (!localOverrideFile.exists()) {
@@ -93,7 +101,7 @@ public void load() {
93101
configuration.set(key, override.get(key));
94102
}
95103
locale2ContentMapping.get(languageFileCrowdin).computeIfAbsent(minecraftCode, e -> configuration);
96-
Util.debugLog("Locale " + crowdinFile);
104+
Util.debugLog("Locale " + crowdinFile +" has been successfully loaded");
97105
} catch (CrowdinOTA.OTAException e) {
98106
plugin.getLogger().warning("Couldn't update the translation for locale " + crowdinCode + " because it not configured, please report to QuickShop");
99107
} catch (IOException e) {
@@ -103,10 +111,7 @@ public void load() {
103111
}
104112
}));
105113

106-
107-
// for (String availableLanguage : distribution.getAvailableLanguages()) {
108-
//
109-
// }
114+
// Register post processor
110115
postProcessors.add(new FillerProcessor());
111116
postProcessors.add(new ColorProcessor());
112117
postProcessors.add(new PlaceHolderApiProcessor());

0 commit comments

Comments
 (0)