Applied Locale to Pages

This commit is contained in:
Rsl1122 2020-03-02 15:09:26 +02:00 committed by Risto Lahtela
parent 420e098d41
commit f869de01b8
13 changed files with 50 additions and 55 deletions

View File

@ -17,14 +17,11 @@
package com.djrapitops.plan.data.store.containers; package com.djrapitops.plan.data.store.containers;
import com.djrapitops.plan.delivery.domain.container.DynamicDataContainer; import com.djrapitops.plan.delivery.domain.container.DynamicDataContainer;
import com.djrapitops.plan.delivery.domain.keys.PlaceholderKey;
/** /**
* Container used for analysis. * Container used for analysis.
* *
* @author Rsl1122 * @author Rsl1122
* @see com.djrapitops.plan.delivery.domain.keys.AnalysisKeys for Key objects
* @see PlaceholderKey for placeholder information
* @deprecated AnalysisContainer is no longer used. * @deprecated AnalysisContainer is no longer used.
*/ */
@Deprecated @Deprecated

View File

@ -24,7 +24,6 @@ import com.djrapitops.plan.delivery.webserver.resolver.json.RootJSONResolver;
import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.exceptions.connection.NotFoundException;
import com.djrapitops.plan.exceptions.connection.WebException; import com.djrapitops.plan.exceptions.connection.WebException;
import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.Database;
@ -51,7 +50,6 @@ public class NetworkPageExporter extends FileExporter {
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final PageFactory pageFactory; private final PageFactory pageFactory;
private final RootJSONResolver jsonHandler; private final RootJSONResolver jsonHandler;
private final Locale locale;
private final Theme theme; private final Theme theme;
private final ExportPaths exportPaths; private final ExportPaths exportPaths;
@ -62,14 +60,12 @@ public class NetworkPageExporter extends FileExporter {
DBSystem dbSystem, DBSystem dbSystem,
PageFactory pageFactory, PageFactory pageFactory,
RootJSONResolver jsonHandler, RootJSONResolver jsonHandler,
Locale locale,
Theme theme Theme theme
) { ) {
this.files = files; this.files = files;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.pageFactory = pageFactory; this.pageFactory = pageFactory;
this.jsonHandler = jsonHandler; this.jsonHandler = jsonHandler;
this.locale = locale;
this.theme = theme; this.theme = theme;
exportPaths = new ExportPaths(); exportPaths = new ExportPaths();
@ -92,7 +88,7 @@ public class NetworkPageExporter extends FileExporter {
.resolve("index.html"); .resolve("index.html");
Page page = pageFactory.networkPage(); Page page = pageFactory.networkPage();
export(to, exportPaths.resolveExportPaths(locale.replaceLanguageInHtml(page.toHtml()))); export(to, exportPaths.resolveExportPaths(page.toHtml()));
} }
public void exportJSON(Path toDirectory, Server server) throws IOException, NotFoundException { public void exportJSON(Path toDirectory, Server server) throws IOException, NotFoundException {

View File

@ -23,7 +23,6 @@ import com.djrapitops.plan.delivery.web.resolver.request.Request;
import com.djrapitops.plan.delivery.webserver.resolver.json.RootJSONResolver; import com.djrapitops.plan.delivery.webserver.resolver.json.RootJSONResolver;
import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.exceptions.connection.NotFoundException;
import com.djrapitops.plan.exceptions.connection.WebException; import com.djrapitops.plan.exceptions.connection.WebException;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.Database;
@ -52,7 +51,6 @@ public class PlayerPageExporter extends FileExporter {
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final PageFactory pageFactory; private final PageFactory pageFactory;
private final RootJSONResolver jsonHandler; private final RootJSONResolver jsonHandler;
private final Locale locale;
private final Theme theme; private final Theme theme;
@Inject @Inject
@ -61,14 +59,12 @@ public class PlayerPageExporter extends FileExporter {
DBSystem dbSystem, DBSystem dbSystem,
PageFactory pageFactory, PageFactory pageFactory,
RootJSONResolver jsonHandler, RootJSONResolver jsonHandler,
Locale locale,
Theme theme Theme theme
) { ) {
this.files = files; this.files = files;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.pageFactory = pageFactory; this.pageFactory = pageFactory;
this.jsonHandler = jsonHandler; this.jsonHandler = jsonHandler;
this.locale = locale;
this.theme = theme; this.theme = theme;
} }
@ -93,7 +89,7 @@ public class PlayerPageExporter extends FileExporter {
try { try {
Page page = pageFactory.playerPage(playerUUID); Page page = pageFactory.playerPage(playerUUID);
export(to, exportPaths.resolveExportPaths(locale.replaceLanguageInHtml(page.toHtml()))); export(to, exportPaths.resolveExportPaths(page.toHtml()));
} catch (IllegalStateException notFound) { } catch (IllegalStateException notFound) {
throw new NotFoundException(notFound.getMessage()); throw new NotFoundException(notFound.getMessage());
} }

View File

@ -24,7 +24,6 @@ import com.djrapitops.plan.delivery.webserver.resolver.json.RootJSONResolver;
import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.exceptions.connection.NotFoundException;
import com.djrapitops.plan.exceptions.connection.WebException; import com.djrapitops.plan.exceptions.connection.WebException;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.Database;
@ -51,7 +50,6 @@ public class PlayersPageExporter extends FileExporter {
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final PageFactory pageFactory; private final PageFactory pageFactory;
private final RootJSONResolver jsonHandler; private final RootJSONResolver jsonHandler;
private final Locale locale;
private final Theme theme; private final Theme theme;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
@ -63,7 +61,6 @@ public class PlayersPageExporter extends FileExporter {
DBSystem dbSystem, DBSystem dbSystem,
PageFactory pageFactory, PageFactory pageFactory,
RootJSONResolver jsonHandler, RootJSONResolver jsonHandler,
Locale locale,
Theme theme, Theme theme,
ServerInfo serverInfo ServerInfo serverInfo
) { ) {
@ -71,7 +68,6 @@ public class PlayersPageExporter extends FileExporter {
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.pageFactory = pageFactory; this.pageFactory = pageFactory;
this.jsonHandler = jsonHandler; this.jsonHandler = jsonHandler;
this.locale = locale;
this.theme = theme; this.theme = theme;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
@ -95,7 +91,7 @@ public class PlayersPageExporter extends FileExporter {
.resolve("index.html"); .resolve("index.html");
Page page = pageFactory.playersPage(); Page page = pageFactory.playersPage();
export(to, exportPaths.resolveExportPaths(locale.replaceLanguageInHtml(page.toHtml()))); export(to, exportPaths.resolveExportPaths(page.toHtml()));
} }
private void exportJSON(Path toDirectory) throws NotFoundException, IOException { private void exportJSON(Path toDirectory) throws NotFoundException, IOException {

View File

@ -25,7 +25,6 @@ import com.djrapitops.plan.exceptions.connection.NotFoundException;
import com.djrapitops.plan.exceptions.connection.WebException; import com.djrapitops.plan.exceptions.connection.WebException;
import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.Database;
@ -53,7 +52,6 @@ public class ServerPageExporter extends FileExporter {
private final PageFactory pageFactory; private final PageFactory pageFactory;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final RootJSONResolver jsonHandler; private final RootJSONResolver jsonHandler;
private final Locale locale;
private final Theme theme; private final Theme theme;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
@ -65,7 +63,6 @@ public class ServerPageExporter extends FileExporter {
PageFactory pageFactory, PageFactory pageFactory,
DBSystem dbSystem, DBSystem dbSystem,
RootJSONResolver jsonHandler, RootJSONResolver jsonHandler,
Locale locale,
Theme theme, Theme theme,
ServerInfo serverInfo // To know if current server is a Proxy ServerInfo serverInfo // To know if current server is a Proxy
) { ) {
@ -73,7 +70,6 @@ public class ServerPageExporter extends FileExporter {
this.pageFactory = pageFactory; this.pageFactory = pageFactory;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.jsonHandler = jsonHandler; this.jsonHandler = jsonHandler;
this.locale = locale;
this.theme = theme; this.theme = theme;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
@ -98,7 +94,7 @@ public class ServerPageExporter extends FileExporter {
.resolve("index.html"); .resolve("index.html");
Page page = pageFactory.serverPage(serverUUID); Page page = pageFactory.serverPage(serverUUID);
export(to, exportPaths.resolveExportPaths(locale.replaceLanguageInHtml(page.toHtml()))); export(to, exportPaths.resolveExportPaths(page.toHtml()));
} }
public void exportJSON(Path toDirectory, Server server) throws IOException, NotFoundException { public void exportJSON(Path toDirectory, Server server) throws IOException, NotFoundException {

View File

@ -16,13 +16,10 @@
*/ */
package com.djrapitops.plan.delivery.formatting; package com.djrapitops.plan.delivery.formatting;
import com.djrapitops.plan.delivery.domain.container.DataContainer;
import com.djrapitops.plan.delivery.domain.keys.PlaceholderKey;
import org.apache.commons.text.StringSubstitutor; import org.apache.commons.text.StringSubstitutor;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects;
/** /**
* Formatter for replacing ${placeholder} values inside strings. * Formatter for replacing ${placeholder} values inside strings.
@ -31,16 +28,6 @@ import java.util.Objects;
*/ */
public class PlaceholderReplacer extends HashMap<String, Serializable> implements Formatter<String> { public class PlaceholderReplacer extends HashMap<String, Serializable> implements Formatter<String> {
public <T> void addPlaceholderFrom(DataContainer container, PlaceholderKey<T> key) {
put(key.getPlaceholder(), container.getValue(key).map(Objects::toString).orElse("Missing value " + key.getPlaceholder()));
}
public void addAllPlaceholdersFrom(DataContainer container, PlaceholderKey... keys) {
for (PlaceholderKey key : keys) {
addPlaceholderFrom(container, key);
}
}
@Override @Override
public String apply(String string) { public String apply(String string) {
StringSubstitutor sub = new StringSubstitutor(this); StringSubstitutor sub = new StringSubstitutor(this);

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.delivery.rendering.pages;
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer; import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
import com.djrapitops.plan.delivery.rendering.html.Contributors; import com.djrapitops.plan.delivery.rendering.html.Contributors;
import com.djrapitops.plan.delivery.rendering.html.icon.Icon; import com.djrapitops.plan.delivery.rendering.html.icon.Icon;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.version.VersionChecker; import com.djrapitops.plan.version.VersionChecker;
/** /**
@ -33,24 +34,26 @@ public class ErrorMessagePage implements Page {
private final String errorTitle; private final String errorTitle;
private final String errorMsg; private final String errorMsg;
private final Locale locale;
private final VersionChecker versionChecker; private final VersionChecker versionChecker;
public ErrorMessagePage( public ErrorMessagePage(
String template, Icon icon, String errorTitle, String errorMsg, String template, Icon icon, String errorTitle, String errorMsg,
VersionChecker versionChecker Locale locale, VersionChecker versionChecker
) { ) {
this.template = template; this.template = template;
this.icon = icon; this.icon = icon;
this.errorTitle = errorTitle; this.errorTitle = errorTitle;
this.errorMsg = errorMsg; this.errorMsg = errorMsg;
this.locale = locale;
this.versionChecker = versionChecker; this.versionChecker = versionChecker;
} }
public ErrorMessagePage( public ErrorMessagePage(
String template, String errorTitle, String errorMsg, String template, String errorTitle, String errorMsg,
VersionChecker versionChecker VersionChecker versionChecker,
) { Locale locale) {
this(template, Icon.called("exclamation-circle").build(), errorTitle, errorMsg, versionChecker); this(template, Icon.called("exclamation-circle").build(), errorTitle, errorMsg, locale, versionChecker);
} }
@Override @Override
@ -63,6 +66,6 @@ public class ErrorMessagePage implements Page {
placeholders.put("version", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton())); placeholders.put("version", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton()));
placeholders.put("updateModal", versionChecker.getUpdateModal()); placeholders.put("updateModal", versionChecker.getUpdateModal());
placeholders.put("contributors", Contributors.generateContributorHtml()); placeholders.put("contributors", Contributors.generateContributorHtml());
return placeholders.apply(template); return locale.replaceLanguageInHtml(placeholders.apply(template));
} }
} }

View File

@ -27,6 +27,7 @@ import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionSer
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.ProxySettings; import com.djrapitops.plan.settings.config.paths.ProxySettings;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.settings.theme.ThemeVal; import com.djrapitops.plan.settings.theme.ThemeVal;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
@ -49,6 +50,7 @@ public class NetworkPage implements Page {
private final VersionChecker versionChecker; private final VersionChecker versionChecker;
private final PlanConfig config; private final PlanConfig config;
private final Theme theme; private final Theme theme;
private final Locale locale;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final Formatters formatters; private final Formatters formatters;
@ -59,6 +61,7 @@ public class NetworkPage implements Page {
VersionChecker versionChecker, VersionChecker versionChecker,
PlanConfig config, PlanConfig config,
Theme theme, Theme theme,
Locale locale,
ServerInfo serverInfo, ServerInfo serverInfo,
Formatters formatters Formatters formatters
) { ) {
@ -67,6 +70,7 @@ public class NetworkPage implements Page {
this.versionChecker = versionChecker; this.versionChecker = versionChecker;
this.config = config; this.config = config;
this.theme = theme; this.theme = theme;
this.locale = locale;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.formatters = formatters; this.formatters = formatters;
} }
@ -98,12 +102,15 @@ public class NetworkPage implements Page {
return new ServerPluginTabs(extensionData, formatters); return new ServerPluginTabs(extensionData, formatters);
}); });
String html = locale.replaceLanguageInHtml(placeholders.apply(templateHtml));
String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav()); String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav());
String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs()); String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs());
placeholders = new PlaceholderReplacer();
placeholders.put("navPluginsTabs", nav); placeholders.put("navPluginsTabs", nav);
placeholders.put("tabsPlugins", StringUtils.remove(tabs, "${backButton}")); placeholders.put("tabsPlugins", StringUtils.remove(tabs, "${backButton}"));
return placeholders.apply(templateHtml); return placeholders.apply(html);
} }
} }

View File

@ -101,7 +101,7 @@ public class PageFactory {
} }
public PlayersPage playersPage() throws IOException { public PlayersPage playersPage() throws IOException {
return new PlayersPage(getResource("web/players.html"), versionChecker.get(), config.get(), serverInfo.get()); return new PlayersPage(getResource("web/players.html"), versionChecker.get(), config.get(), locale.get(), serverInfo.get());
} }
public ServerPage serverPage(UUID serverUUID) throws NotFoundException, IOException { public ServerPage serverPage(UUID serverUUID) throws NotFoundException, IOException {
@ -112,6 +112,7 @@ public class PageFactory {
server, server,
config.get(), config.get(),
theme.get(), theme.get(),
locale.get(),
versionChecker.get(), versionChecker.get(),
dbSystem.get(), dbSystem.get(),
serverInfo.get(), serverInfo.get(),
@ -125,7 +126,7 @@ public class PageFactory {
return new PlayerPage( return new PlayerPage(
getResource("web/player.html"), player, getResource("web/player.html"), player,
versionChecker.get(), versionChecker.get(),
config.get(), this, theme.get(), config.get(), this, theme.get(), locale.get(),
formatters.get(), serverInfo.get() formatters.get(), serverInfo.get()
); );
} }
@ -166,7 +167,9 @@ public class PageFactory {
public NetworkPage networkPage() throws IOException { public NetworkPage networkPage() throws IOException {
return new NetworkPage(getResource("web/network.html"), return new NetworkPage(getResource("web/network.html"),
dbSystem.get(), dbSystem.get(),
versionChecker.get(), config.get(), theme.get(), serverInfo.get(), formatters.get()); versionChecker.get(),
config.get(), theme.get(), locale.get(),
serverInfo.get(), formatters.get());
} }
public Page internalErrorPage(String message, Throwable error) { public Page internalErrorPage(String message, Throwable error) {
@ -184,13 +187,13 @@ public class PageFactory {
public Page errorPage(String title, String error) throws IOException { public Page errorPage(String title, String error) throws IOException {
return new ErrorMessagePage( return new ErrorMessagePage(
getResource("web/error.html"), title, error, getResource("web/error.html"), title, error,
versionChecker.get()); versionChecker.get(), locale.get());
} }
public Page errorPage(Icon icon, String title, String error) throws IOException { public Page errorPage(Icon icon, String title, String error) throws IOException {
return new ErrorMessagePage( return new ErrorMessagePage(
getResource("web/error.html"), icon, title, error, getResource("web/error.html"), icon, title, error,
versionChecker.get()); locale.get(), versionChecker.get());
} }
public String getResource(String name) throws IOException { public String getResource(String name) throws IOException {

View File

@ -25,6 +25,7 @@ import com.djrapitops.plan.delivery.rendering.html.Contributors;
import com.djrapitops.plan.delivery.rendering.html.Html; import com.djrapitops.plan.delivery.rendering.html.Html;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.settings.theme.ThemeVal; import com.djrapitops.plan.settings.theme.ThemeVal;
import com.djrapitops.plan.version.VersionChecker; import com.djrapitops.plan.version.VersionChecker;
@ -46,6 +47,7 @@ public class PlayerPage implements Page {
private final PlanConfig config; private final PlanConfig config;
private final PageFactory pageFactory; private final PageFactory pageFactory;
private final Theme theme; private final Theme theme;
private final Locale locale;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final Formatter<Long> clockLongFormatter; private final Formatter<Long> clockLongFormatter;
@ -58,6 +60,7 @@ public class PlayerPage implements Page {
PlanConfig config, PlanConfig config,
PageFactory pageFactory, PageFactory pageFactory,
Theme theme, Theme theme,
Locale locale,
Formatters formatters, Formatters formatters,
ServerInfo serverInfo ServerInfo serverInfo
) { ) {
@ -67,6 +70,7 @@ public class PlayerPage implements Page {
this.config = config; this.config = config;
this.pageFactory = pageFactory; this.pageFactory = pageFactory;
this.theme = theme; this.theme = theme;
this.locale = locale;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
clockLongFormatter = formatters.clockLong(); clockLongFormatter = formatters.clockLong();
@ -91,24 +95,24 @@ public class PlayerPage implements Page {
placeholders.put("refreshFull", secondLongFormatter.apply(now)); placeholders.put("refreshFull", secondLongFormatter.apply(now));
placeholders.put("version", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton())); placeholders.put("version", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton()));
placeholders.put("updateModal", versionChecker.getUpdateModal()); placeholders.put("updateModal", versionChecker.getUpdateModal());
placeholders.put("timeZone", config.getTimeZoneOffsetHours());
String playerName = player.getValue(PlayerKeys.NAME).orElse(playerUUID.toString()); String playerName = player.getValue(PlayerKeys.NAME).orElse(playerUUID.toString());
placeholders.put("playerName", playerName); placeholders.put("playerName", playerName);
placeholders.put("worldPieColors", theme.getValue(ThemeVal.GRAPH_WORLD_PIE)); placeholders.put("timeZone", config.getTimeZoneOffsetHours());
placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE)); placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE));
placeholders.put("serverPieColors", theme.getValue(ThemeVal.GRAPH_SERVER_PREF_PIE));
placeholders.put("firstDay", 1);
placeholders.put("backButton", (serverInfo.getServer().isProxy() ? Html.BACK_BUTTON_NETWORK : Html.BACK_BUTTON_SERVER).create()); placeholders.put("backButton", (serverInfo.getServer().isProxy() ? Html.BACK_BUTTON_NETWORK : Html.BACK_BUTTON_SERVER).create());
placeholders.put("contributors", Contributors.generateContributorHtml()); placeholders.put("contributors", Contributors.generateContributorHtml());
String html = locale.replaceLanguageInHtml(placeholders.apply(templateHtml));
placeholders = new PlaceholderReplacer();
PlayerPluginTab pluginTabs = pageFactory.inspectPluginTabs(playerUUID); PlayerPluginTab pluginTabs = pageFactory.inspectPluginTabs(playerUUID);
placeholders.put("navPluginsTabs", pluginTabs.getNav()); placeholders.put("navPluginsTabs", pluginTabs.getNav());
placeholders.put("pluginsTabs", pluginTabs.getTab()); placeholders.put("pluginsTabs", pluginTabs.getTab());
return placeholders.apply(templateHtml); return placeholders.apply(html);
} }
} }

View File

@ -22,6 +22,7 @@ import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.PluginSettings; import com.djrapitops.plan.settings.config.paths.PluginSettings;
import com.djrapitops.plan.settings.config.paths.ProxySettings; import com.djrapitops.plan.settings.config.paths.ProxySettings;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.version.VersionChecker; import com.djrapitops.plan.version.VersionChecker;
/** /**
@ -34,17 +35,20 @@ public class PlayersPage implements Page {
private final String templateHtml; private final String templateHtml;
private final VersionChecker versionChecker; private final VersionChecker versionChecker;
private final PlanConfig config; private final PlanConfig config;
private final Locale locale;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
PlayersPage( PlayersPage(
String templateHtml, String templateHtml,
VersionChecker versionChecker, VersionChecker versionChecker,
PlanConfig config, PlanConfig config,
Locale locale,
ServerInfo serverInfo ServerInfo serverInfo
) { ) {
this.templateHtml = templateHtml; this.templateHtml = templateHtml;
this.versionChecker = versionChecker; this.versionChecker = versionChecker;
this.config = config; this.config = config;
this.locale = locale;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
} }
@ -61,6 +65,6 @@ public class PlayersPage implements Page {
placeholders.put("networkName", config.get(PluginSettings.SERVER_NAME)); placeholders.put("networkName", config.get(PluginSettings.SERVER_NAME));
} }
return placeholders.apply(templateHtml); return locale.replaceLanguageInHtml(placeholders.apply(templateHtml));
} }
} }

View File

@ -28,6 +28,7 @@ import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionSer
import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.settings.theme.ThemeVal; import com.djrapitops.plan.settings.theme.ThemeVal;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
@ -47,6 +48,7 @@ public class ServerPage implements Page {
private final Server server; private final Server server;
private final PlanConfig config; private final PlanConfig config;
private final Theme theme; private final Theme theme;
private final Locale locale;
private final VersionChecker versionChecker; private final VersionChecker versionChecker;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
@ -56,6 +58,7 @@ public class ServerPage implements Page {
String templateHtml, Server server, String templateHtml, Server server,
PlanConfig config, PlanConfig config,
Theme theme, Theme theme,
Locale locale,
VersionChecker versionChecker, VersionChecker versionChecker,
DBSystem dbSystem, DBSystem dbSystem,
ServerInfo serverInfo, ServerInfo serverInfo,
@ -65,6 +68,7 @@ public class ServerPage implements Page {
this.server = server; this.server = server;
this.config = config; this.config = config;
this.theme = theme; this.theme = theme;
this.locale = locale;
this.versionChecker = versionChecker; this.versionChecker = versionChecker;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
@ -93,12 +97,15 @@ public class ServerPage implements Page {
return new ServerPluginTabs(extensionData, formatters); return new ServerPluginTabs(extensionData, formatters);
}); });
String html = locale.replaceLanguageInHtml(placeholders.apply(templateHtml));
String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav()); String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav());
String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs()); String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs());
placeholders = new PlaceholderReplacer();
placeholders.put("navPluginsTabs", nav); placeholders.put("navPluginsTabs", nav);
placeholders.put("tabsPlugins", tabs); placeholders.put("tabsPlugins", tabs);
return placeholders.apply(templateHtml); return placeholders.apply(html);
} }
} }

View File

@ -102,7 +102,6 @@ public class Locale extends HashMap<Lang, Message> {
this.langCode = locale.langCode; this.langCode = locale.langCode;
} }
// TODO Use inside Page implementations
public String replaceLanguageInHtml(String from) { public String replaceLanguageInHtml(String from) {
if (isEmpty()) { if (isEmpty()) {
return from; return from;