Skip to content

Commit 6eadca3

Browse files
committed
move code
1 parent 1541ef0 commit 6eadca3

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

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

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,10 @@ public void load() {
113113
return;
114114
}
115115
Util.debugLog("Loading translation for locale: " + crowdinCode + " (" + minecraftCode + ")");
116-
JsonConfiguration configuration = new JsonConfiguration();
117-
try {
118-
// Load the locale file from local cache if available
119-
// Or load the locale file from remote server if it had updates or not exists.
120-
configuration.loadFromString(distribution.getFile(crowdinFile, crowdinCode));
121-
} catch (InvalidConfigurationException exception) {
122-
// Force loading the locale file form remote server because file not valid.
123-
configuration.loadFromString(distribution.getFile(crowdinFile, crowdinCode, true));
124-
}
116+
JsonConfiguration configuration = getDistributionConfiguration(crowdinFile, crowdinCode);
125117
// Loading override text (allow user modification the translation)
126-
JsonConfiguration override = new JsonConfiguration();
127-
File localOverrideFile = new File(getOverrideFilesFolder(crowdinFile), minecraftCode + ".json");
128-
if (!localOverrideFile.exists()) {
129-
localOverrideFile.getParentFile().mkdirs();
130-
localOverrideFile.createNewFile();
131-
}
132-
override.loadFromString(Util.readToString(localOverrideFile));
133-
// Prevent user override important keys
134-
for (String key : override.getKeys(true)) {
135-
if ("language-version".equals(key) || "config-version".equals(key) || "version".equals(key)) {
136-
continue;
137-
}
138-
configuration.set(key, override.get(key));
139-
}
118+
JsonConfiguration override = getOverrideConfiguration(crowdinFile, minecraftCode);
119+
applyOverrideConfiguration(configuration,override);
140120
locale2ContentMapping.get(crowdinFile).computeIfAbsent(minecraftCode, e -> configuration);
141121
Util.debugLog("Locale " + crowdinFile.replace("%locale%", crowdinCode) + " has been successfully loaded");
142122
} catch (CrowdinOTA.OTAException e) {
@@ -157,6 +137,39 @@ public void load() {
157137
postProcessors.add(new ColorProcessor());
158138
}
159139

140+
private void applyOverrideConfiguration(JsonConfiguration distributionConfiguration, JsonConfiguration overrideConfiguration){
141+
for (String key : overrideConfiguration.getKeys(true)) {
142+
if ("language-version".equals(key) || "config-version".equals(key) || "version".equals(key)) {
143+
continue;
144+
}
145+
distributionConfiguration.set(key, distributionConfiguration.get(key));
146+
}
147+
}
148+
149+
private JsonConfiguration getDistributionConfiguration(String distributionFile, String distributionCode) throws Exception {
150+
JsonConfiguration configuration = new JsonConfiguration();
151+
try {
152+
// Load the locale file from local cache if available
153+
// Or load the locale file from remote server if it had updates or not exists.
154+
configuration.loadFromString(distribution.getFile(distributionFile, distributionCode));
155+
} catch (InvalidConfigurationException exception) {
156+
// Force loading the locale file form remote server because file not valid.
157+
configuration.loadFromString(distribution.getFile(distributionFile, distributionCode, true));
158+
}
159+
return configuration;
160+
}
161+
162+
private JsonConfiguration getOverrideConfiguration(String overrideFile, String locale) throws IOException, InvalidConfigurationException {
163+
File localOverrideFile = new File(getOverrideFilesFolder(overrideFile), locale + ".json");
164+
if (!localOverrideFile.exists()) {
165+
localOverrideFile.getParentFile().mkdirs();
166+
localOverrideFile.createNewFile();
167+
}
168+
JsonConfiguration configuration = new JsonConfiguration();
169+
configuration.loadFromString(Util.readToString(localOverrideFile));
170+
return configuration;
171+
}
172+
160173
/**
161174
* Getting the translation with path with default locale
162175
*

0 commit comments

Comments
 (0)