From 2ac5fe45e349dd35feba0b72b59f2f25fdd64957 Mon Sep 17 00:00:00 2001 From: SirYwell Date: Tue, 8 Jun 2021 15:35:29 +0200 Subject: [PATCH] Make CaptionLoader namespace-aware --- .../java/com/plotsquared/core/PlotSquared.java | 6 ++++-- .../caption/load/CaptionLoader.java | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 644783935..3a44ca23b 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -186,7 +186,8 @@ public class PlotSquared { DefaultCaptionProvider.forClassLoaderFormatString( this.getClass().getClassLoader(), "lang/messages_%s.json" - ) + ), + TranslatableCaption.DEFAULT_NAMESPACE ); // the path in our jar file // Load caption map try { @@ -1534,7 +1535,8 @@ public class PlotSquared { } /** - * Register a caption map + * Register a caption map. The namespace needs be equal to the namespace used for + * the {@link TranslatableCaption}s inside the map. * * @param namespace Namespace * @param captionMap Map instance diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/load/CaptionLoader.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/load/CaptionLoader.java index b4e0b2d2e..ac191dc8f 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/load/CaptionLoader.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/load/CaptionLoader.java @@ -32,9 +32,9 @@ import com.plotsquared.core.configuration.caption.CaptionMap; import com.plotsquared.core.configuration.caption.LocalizedCaptionMap; import com.plotsquared.core.configuration.caption.PerUserLocaleCaptionMap; import com.plotsquared.core.configuration.caption.TranslatableCaption; -import org.checkerframework.checker.nullness.qual.NonNull; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.checkerframework.checker.nullness.qual.NonNull; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -76,15 +76,18 @@ public final class CaptionLoader { private final Locale defaultLocale; private final Function localeExtractor; private final DefaultCaptionProvider captionProvider; + private final String namespace; private CaptionLoader( final @NonNull Locale internalLocale, final @NonNull Function<@NonNull Path, @NonNull Locale> localeExtractor, - final @NonNull DefaultCaptionProvider captionProvider + final @NonNull DefaultCaptionProvider captionProvider, + final @NonNull String namespace ) { this.defaultLocale = internalLocale; this.localeExtractor = localeExtractor; this.captionProvider = captionProvider; + this.namespace = namespace; Map temp; try { temp = this.captionProvider.loadDefaults(internalLocale); @@ -107,9 +110,10 @@ public final class CaptionLoader { public static @NonNull CaptionLoader of( final @NonNull Locale internalLocale, final @NonNull Function<@NonNull Path, @NonNull Locale> localeExtractor, - final @NonNull DefaultCaptionProvider captionProvider + final @NonNull DefaultCaptionProvider captionProvider, + final @NonNull String namespace ) { - return new CaptionLoader(internalLocale, localeExtractor, captionProvider); + return new CaptionLoader(internalLocale, localeExtractor, captionProvider, namespace); } /** @@ -209,7 +213,10 @@ public final class CaptionLoader { save(file, map); // update the file using the modified map } return new LocalizedCaptionMap(locale, map.entrySet().stream() - .collect(Collectors.toMap(entry -> TranslatableCaption.of(entry.getKey()), Map.Entry::getValue))); + .collect(Collectors.toMap( + entry -> TranslatableCaption.of(this.namespace, entry.getKey()), + Map.Entry::getValue) + )); } }