diff --git a/buildSrc/src/main/kotlin/PlatformConfig.kt b/buildSrc/src/main/kotlin/PlatformConfig.kt index 5eaac8dc0..0203f277d 100644 --- a/buildSrc/src/main/kotlin/PlatformConfig.kt +++ b/buildSrc/src/main/kotlin/PlatformConfig.kt @@ -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() } } diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index 0d88d4d40..85a8becd7 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -109,8 +109,6 @@ } tasks.named("processResources") { - // it's in the zip too - exclude("**/lang/strings.json") from(configurations.named("languageFiles")) { rename { "i18n.zip" diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java index 8dfbdd2a0..f4b99d991 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java @@ -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 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 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 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 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";