mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-21 04:49:51 +08:00
Fix loading dev i18n files
This forces the repo file to FULLY OVERRIDE the default locale. Nothing will be loaded from the default locale in either the config folder, or the i18n dependency.
This commit is contained in:
parent
56182ad079
commit
83e744bae2
buildSrc/src/main/kotlin
worldedit-core
@ -125,6 +125,8 @@
|
||||
exclude(".cache")
|
||||
exclude("LICENSE*")
|
||||
exclude("META-INF/maven/**")
|
||||
// it's in the i18n zip, we only use it in dev
|
||||
exclude("**/lang/strings.json")
|
||||
minimize()
|
||||
}
|
||||
}
|
||||
|
@ -109,8 +109,6 @@
|
||||
}
|
||||
|
||||
tasks.named<Copy>("processResources") {
|
||||
// it's in the zip too
|
||||
exclude("**/lang/strings.json")
|
||||
from(configurations.named("languageFiles")) {
|
||||
rename {
|
||||
"i18n.zip"
|
||||
|
@ -39,6 +39,7 @@
|
||||
import java.io.Reader;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -183,35 +184,7 @@ private void loadLocale(Locale locale) {
|
||||
}
|
||||
|
||||
try {
|
||||
String localePath = getLocalePath(locale);
|
||||
Map<String, String> entries = new HashMap<>();
|
||||
|
||||
// From lowest priority to highest
|
||||
putTranslationData(entries, this.internalZipRoot.resolve(localePath));
|
||||
if (this.userProvidedZipRoot != null) {
|
||||
putTranslationData(entries, this.userProvidedZipRoot.resolve(localePath));
|
||||
}
|
||||
putTranslationData(entries, this.userProvidedFlatRoot.resolve(localePath));
|
||||
|
||||
// Load message formats
|
||||
for (Map.Entry<String, String> entry : entries.entrySet()) {
|
||||
MessageFormat format;
|
||||
try {
|
||||
format = new MessageFormat(entry.getValue().replace("'", "''"), locale);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.warn(
|
||||
"Failed to load translation"
|
||||
+ ", locale=" + locale
|
||||
+ ", key=" + entry.getKey()
|
||||
+ ", value=" + entry.getValue(),
|
||||
e
|
||||
);
|
||||
continue;
|
||||
}
|
||||
translationTable.put(
|
||||
locale, entry.getKey(), format
|
||||
);
|
||||
}
|
||||
loadTranslations(locale);
|
||||
} catch (Exception t) {
|
||||
LOGGER.warn(
|
||||
"Failed to load translations"
|
||||
@ -224,6 +197,49 @@ private void loadLocale(Locale locale) {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadTranslations(Locale locale) throws IOException {
|
||||
Map<String, String> entries = new HashMap<>();
|
||||
|
||||
// If needed, load the dev strings as an OVERRIDE!
|
||||
// In dev, reading lang/strings.json from either i18n.zip or the config folder
|
||||
// WILL NOT OCCUR!
|
||||
URL devStrings;
|
||||
if (locale == defaultLocale
|
||||
&& (devStrings = resourceLoader.getRootResource("lang/strings.json")) != null) {
|
||||
try (InputStream in = devStrings.openStream()) {
|
||||
putTranslationData(entries, in);
|
||||
}
|
||||
} else {
|
||||
String localePath = getLocalePath(locale);
|
||||
// From lowest priority to highest
|
||||
putTranslationData(entries, this.internalZipRoot.resolve(localePath));
|
||||
if (this.userProvidedZipRoot != null) {
|
||||
putTranslationData(entries, this.userProvidedZipRoot.resolve(localePath));
|
||||
}
|
||||
putTranslationData(entries, this.userProvidedFlatRoot.resolve(localePath));
|
||||
}
|
||||
|
||||
// Load message formats
|
||||
for (Map.Entry<String, String> entry : entries.entrySet()) {
|
||||
MessageFormat format;
|
||||
try {
|
||||
format = new MessageFormat(entry.getValue().replace("'", "''"), locale);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.warn(
|
||||
"Failed to load translation"
|
||||
+ ", locale=" + locale
|
||||
+ ", key=" + entry.getKey()
|
||||
+ ", value=" + entry.getValue(),
|
||||
e
|
||||
);
|
||||
continue;
|
||||
}
|
||||
translationTable.put(
|
||||
locale, entry.getKey(), format
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private String getLocalePath(Locale locale) {
|
||||
if (defaultLocale.equals(locale)) {
|
||||
return "strings.json";
|
||||
|
Loading…
Reference in New Issue
Block a user