mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Make CaptionLoader namespace-aware
This commit is contained in:
parent
7f3d3ecb00
commit
2ac5fe45e3
@ -186,7 +186,8 @@ public class PlotSquared {
|
|||||||
DefaultCaptionProvider.forClassLoaderFormatString(
|
DefaultCaptionProvider.forClassLoaderFormatString(
|
||||||
this.getClass().getClassLoader(),
|
this.getClass().getClassLoader(),
|
||||||
"lang/messages_%s.json"
|
"lang/messages_%s.json"
|
||||||
)
|
),
|
||||||
|
TranslatableCaption.DEFAULT_NAMESPACE
|
||||||
); // the path in our jar file
|
); // the path in our jar file
|
||||||
// Load caption map
|
// Load caption map
|
||||||
try {
|
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 namespace Namespace
|
||||||
* @param captionMap Map instance
|
* @param captionMap Map instance
|
||||||
|
@ -32,9 +32,9 @@ import com.plotsquared.core.configuration.caption.CaptionMap;
|
|||||||
import com.plotsquared.core.configuration.caption.LocalizedCaptionMap;
|
import com.plotsquared.core.configuration.caption.LocalizedCaptionMap;
|
||||||
import com.plotsquared.core.configuration.caption.PerUserLocaleCaptionMap;
|
import com.plotsquared.core.configuration.caption.PerUserLocaleCaptionMap;
|
||||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
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.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
@ -76,15 +76,18 @@ public final class CaptionLoader {
|
|||||||
private final Locale defaultLocale;
|
private final Locale defaultLocale;
|
||||||
private final Function<Path, Locale> localeExtractor;
|
private final Function<Path, Locale> localeExtractor;
|
||||||
private final DefaultCaptionProvider captionProvider;
|
private final DefaultCaptionProvider captionProvider;
|
||||||
|
private final String namespace;
|
||||||
|
|
||||||
private CaptionLoader(
|
private CaptionLoader(
|
||||||
final @NonNull Locale internalLocale,
|
final @NonNull Locale internalLocale,
|
||||||
final @NonNull Function<@NonNull Path, @NonNull Locale> localeExtractor,
|
final @NonNull Function<@NonNull Path, @NonNull Locale> localeExtractor,
|
||||||
final @NonNull DefaultCaptionProvider captionProvider
|
final @NonNull DefaultCaptionProvider captionProvider,
|
||||||
|
final @NonNull String namespace
|
||||||
) {
|
) {
|
||||||
this.defaultLocale = internalLocale;
|
this.defaultLocale = internalLocale;
|
||||||
this.localeExtractor = localeExtractor;
|
this.localeExtractor = localeExtractor;
|
||||||
this.captionProvider = captionProvider;
|
this.captionProvider = captionProvider;
|
||||||
|
this.namespace = namespace;
|
||||||
Map<String, String> temp;
|
Map<String, String> temp;
|
||||||
try {
|
try {
|
||||||
temp = this.captionProvider.loadDefaults(internalLocale);
|
temp = this.captionProvider.loadDefaults(internalLocale);
|
||||||
@ -107,9 +110,10 @@ public final class CaptionLoader {
|
|||||||
public static @NonNull CaptionLoader of(
|
public static @NonNull CaptionLoader of(
|
||||||
final @NonNull Locale internalLocale,
|
final @NonNull Locale internalLocale,
|
||||||
final @NonNull Function<@NonNull Path, @NonNull Locale> localeExtractor,
|
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
|
save(file, map); // update the file using the modified map
|
||||||
}
|
}
|
||||||
return new LocalizedCaptionMap(locale, map.entrySet().stream()
|
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)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user