mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-24 00:51:25 +01:00
Html Lang implementations, Fixed LocaleFileWriter
This commit is contained in:
parent
c44ddac69d
commit
d62d510bda
@ -39,6 +39,6 @@ public enum LangCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return "locale_" + name + ".txt";
|
return "locale_" + name() + ".txt";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,20 +30,30 @@ public class LocaleFileWriter {
|
|||||||
|
|
||||||
public void writeToFile(File file) throws IOException {
|
public void writeToFile(File file) throws IOException {
|
||||||
// Find longest identifier
|
// Find longest identifier
|
||||||
if (locale.isEmpty()) {
|
Optional<String> key = LocaleSystem.getIdentifiers().keySet().stream()
|
||||||
throw new IllegalStateException("Locale has no values");
|
|
||||||
}
|
|
||||||
Optional<String> key = locale.keySet().stream()
|
|
||||||
.map(Lang::getIdentifier)
|
|
||||||
.min(new StringLengthComparator());
|
.min(new StringLengthComparator());
|
||||||
if (!key.isPresent()) {
|
if (!key.isPresent()) {
|
||||||
throw new IllegalStateException("Locale has not been loaded.");
|
throw new IllegalStateException("LocaleSystem defines no Identifiers.");
|
||||||
}
|
}
|
||||||
final int length = key.get().length() + 2;
|
|
||||||
|
for (Lang lang : LocaleSystem.getIdentifiers().values()) {
|
||||||
|
if (!locale.containsKey(lang)) {
|
||||||
|
locale.put(lang, new Message(lang.getDefault()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int length = key.get().length() + 2;
|
||||||
List<String> lines = locale.entrySet().stream()
|
List<String> lines = locale.entrySet().stream()
|
||||||
.sorted(new LocaleEntryComparator())
|
.sorted(new LocaleEntryComparator())
|
||||||
.map(entry -> getSpacedIdentifier(entry.getKey().getIdentifier(), length) + "|| " + entry.getValue().toString())
|
.map(entry -> {
|
||||||
|
String value = entry.getValue() != null ? entry.getValue().toString() : entry.getKey().getDefault();
|
||||||
|
return getSpacedIdentifier(entry.getKey().getIdentifier(), length) + "|| " + value;
|
||||||
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
if (!file.exists()) {
|
||||||
|
Files.createFile(file.toPath());
|
||||||
|
}
|
||||||
|
|
||||||
Files.write(file.toPath(), lines, StandardCharsets.UTF_8);
|
Files.write(file.toPath(), lines, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
Config config = ConfigSystem.getConfig();
|
Config config = ConfigSystem.getConfig();
|
||||||
|
@ -34,7 +34,11 @@ public class LocaleSystem implements SubSystem {
|
|||||||
DeepHelpLang.values(),
|
DeepHelpLang.values(),
|
||||||
PluginLang.values(),
|
PluginLang.values(),
|
||||||
ManageLang.values(),
|
ManageLang.values(),
|
||||||
GenericLang.values()
|
GenericLang.values(),
|
||||||
|
CommonHtmlLang.values(),
|
||||||
|
PlayerPageLang.values(),
|
||||||
|
ServerPageLang.values(),
|
||||||
|
NetworkPageLang.values()
|
||||||
};
|
};
|
||||||
|
|
||||||
return Arrays.stream(lang)
|
return Arrays.stream(lang)
|
||||||
@ -59,8 +63,8 @@ public class LocaleSystem implements SubSystem {
|
|||||||
|
|
||||||
private void writeNewDefaultLocale(File localeFile) {
|
private void writeNewDefaultLocale(File localeFile) {
|
||||||
try {
|
try {
|
||||||
new LocaleFileWriter(Locale.forLangCode(LangCode.EN)).writeToFile(localeFile);
|
new LocaleFileWriter(new Locale()).writeToFile(localeFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException | IllegalStateException e) {
|
||||||
Log.error("Failed to write new Locale file at " + localeFile.getAbsolutePath());
|
Log.error("Failed to write new Locale file at " + localeFile.getAbsolutePath());
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass().getName(), e);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.djrapitops.plan.system.locale.lang;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Lang} implementation for commonly used .html replacement values.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public enum CommonHtmlLang implements Lang {
|
||||||
|
PLEASE_WAIT("Please wait..."),
|
||||||
|
|
||||||
|
NAV_INFORMATION("Information"),
|
||||||
|
NAV_SESSIONS("Sessions"),
|
||||||
|
NAV_OVERVIEW("Overview"),
|
||||||
|
NAV_PLUGINS("Plugins"),
|
||||||
|
NAV_ONLINE_ACTIVITY("Online Activity"),
|
||||||
|
NAV_SEVER_HEALTH("Server Health"),
|
||||||
|
NAV_PERFORMANCE("Performance"),
|
||||||
|
NAV_PLAYERS("Players"),
|
||||||
|
NAV_GEOLOCATIONS("Geolocations"),
|
||||||
|
NAV_COMMAND_USAGE("Command Usage"),
|
||||||
|
NAV_NETWORK_PLAYERS("Network Players"),
|
||||||
|
|
||||||
|
AVERAGE_PING("Average Ping"),
|
||||||
|
BEST_PING("Best Ping"),
|
||||||
|
WORST_PING("Worst Ping"),
|
||||||
|
PLAYERS_ONLINE_TEXT("Players Online");
|
||||||
|
|
||||||
|
private final String defaultValue;
|
||||||
|
|
||||||
|
CommonHtmlLang(String defaultValue) {
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return "HTML - " + name();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefault() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.djrapitops.plan.system.locale.lang;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Lang} implementation for player.html replacement values.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public enum NetworkPageLang implements Lang {
|
||||||
|
NETWORK("Network"),
|
||||||
|
NETWORK_INFORMATION("NETWORK INFORMATION"),
|
||||||
|
PLAYERS_TEXT("Players"),
|
||||||
|
PLAYERS("PLAYERS"),
|
||||||
|
NEW_TEXT("New"),
|
||||||
|
HEALTH_ESTIMATE("Health Estimate");
|
||||||
|
|
||||||
|
private final String defaultValue;
|
||||||
|
|
||||||
|
NetworkPageLang(String defaultValue) {
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return "HTML - " + name();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefault() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
package com.djrapitops.plan.system.locale.lang;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Lang} implementation for player.html replacement values.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public enum PlayerPageLang implements Lang {
|
||||||
|
PLAYER_KILLS("Player Kills"),
|
||||||
|
MOB_KILLS("Mob Kills"),
|
||||||
|
DEATHS("Deaths"),
|
||||||
|
SESSIONS("Sessions"),
|
||||||
|
TOTAL("Total"),
|
||||||
|
PLAYTIME("Playtime"),
|
||||||
|
ACTIVE("Active"),
|
||||||
|
MEDIAN("Median"),
|
||||||
|
LONGEST("Longest"),
|
||||||
|
SESSION("Session"),
|
||||||
|
ACTIVITY_INDEX("Activity Index"),
|
||||||
|
INDEX_ACTIVE("Active"),
|
||||||
|
INDEX_VERY_ACTIVE("Very Active"),
|
||||||
|
INDEX_REGULAR("Regular"),
|
||||||
|
INDEX_IRREGULAR("Irregular"),
|
||||||
|
INDEX_INACTIVE("Inactive"),
|
||||||
|
FAVORITE_SERVER("Favorite Server"),
|
||||||
|
|
||||||
|
REGISTERED("REGISTERED"),
|
||||||
|
LAST_SEEN("LAST SEEN"),
|
||||||
|
PUNCH_CARD("Punchcard"),
|
||||||
|
SEEN_NICKNAMES("Seen Nicknames"),
|
||||||
|
NICKNAME("Nickname"),
|
||||||
|
SERVER("Server"),
|
||||||
|
LAST_SEEN_TEXT("Last Seen"),
|
||||||
|
CONNECTION_INFORMATION("Connection Information"),
|
||||||
|
IP_ADDRESS("IP-address"),
|
||||||
|
GEOLOCATION("Geolocation"),
|
||||||
|
LAST_CONNECTED("Last Connected"),
|
||||||
|
LOCAL_MACHINE("Local Machine"),
|
||||||
|
CALENDAR_TEXT("Calendar"),
|
||||||
|
MOST_RECENT("Most Recent"),
|
||||||
|
WORLD(" World"),
|
||||||
|
PREFERENCE("Preference"),
|
||||||
|
LAST_30_DAYS("LAST 30 DAYS"),
|
||||||
|
LAST_7_DAYS("LAST 7 DAYS"),
|
||||||
|
LAST_24_HOURS("LAST 24 HOURS"),
|
||||||
|
SERVERS("Servers"),
|
||||||
|
OVERVIEW("OVERVIEW"),
|
||||||
|
PLAYER_CAUSED_DEATHS("Player caused Deaths"),
|
||||||
|
MOB_CAUSED_DEATHS("Mob caused Deaths"),
|
||||||
|
TIME("Time"),
|
||||||
|
KILLED("Killed"),
|
||||||
|
WITH("With"),
|
||||||
|
KILLED_BY("Killed by");
|
||||||
|
|
||||||
|
private final String defaultValue;
|
||||||
|
|
||||||
|
PlayerPageLang(String defaultValue) {
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return "HTML - " + name();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefault() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
@ -43,7 +43,7 @@ public enum PluginLang implements Lang {
|
|||||||
|
|
||||||
DB_APPLY_PATCH("Database - Apply Patch", "Applying Patch: ${0}.."),
|
DB_APPLY_PATCH("Database - Apply Patch", "Applying Patch: ${0}.."),
|
||||||
DB_APPLIED_PATCHES("Database - Patches Applied", "All database patches applied successfully."),
|
DB_APPLIED_PATCHES("Database - Patches Applied", "All database patches applied successfully."),
|
||||||
DB_APPLIED_PATCHES_ALREADY("Database - Patches Applied", "All database patches already applied."),
|
DB_APPLIED_PATCHES_ALREADY("Database - Patches Applied Already", "All database patches already applied."),
|
||||||
DB_NOTIFY_CLEAN("Database Notify - Clean", "Removed data of ${0} players."),
|
DB_NOTIFY_CLEAN("Database Notify - Clean", "Removed data of ${0} players."),
|
||||||
DB_NOTIFY_SQLITE_WAL("Database Notify - SQLite No WAL", "SQLite WAL mode not supported on this server version, using default. This may or may not affect performance."),
|
DB_NOTIFY_SQLITE_WAL("Database Notify - SQLite No WAL", "SQLite WAL mode not supported on this server version, using default. This may or may not affect performance."),
|
||||||
DB_MYSQL_LAUNCH_OPTIONS_FAIL("Database MySQL - Launch Options Error", "Launch Options were faulty, using default (${0})");
|
DB_MYSQL_LAUNCH_OPTIONS_FAIL("Database MySQL - Launch Options Error", "Launch Options were faulty, using default (${0})");
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.djrapitops.plan.system.locale.lang;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Lang} implementation for player.html replacement values.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public enum ServerPageLang implements Lang {
|
||||||
|
SERVER_ANALYSIS("Server Analysis"),
|
||||||
|
PLAYERS_ONLINE("PLAYERS ONLINE"),
|
||||||
|
UNIQUE("UNIQUE"),
|
||||||
|
NEW("NEW"),
|
||||||
|
REGULAR("REGULAR"),
|
||||||
|
TOTAL_PLAYERS("Total Players"),
|
||||||
|
UNIQUE_PLAYERS_TEXT("Unique Players"),
|
||||||
|
NEW_PLAYERS("New Players"),
|
||||||
|
LAST_PEAK("Last Peak"),
|
||||||
|
ALL_TIME_PEAK("All Time Peak"),
|
||||||
|
SERVER_INFORMATION("SERVER INFORMATION"),
|
||||||
|
USER_INFORMATION("USER INFORMATION"),
|
||||||
|
RECENT_LOGINS("RECENT LOGINS"),
|
||||||
|
UNIQUE_PLAYERS("UNIQUE PLAYERS"),
|
||||||
|
CALENDAR("CALENDAR"),
|
||||||
|
UNIQUE_CALENDAR("Unique:"),
|
||||||
|
NEW_CALENDAR("New:"),
|
||||||
|
NEW_RETENTION("New Player Retention"),
|
||||||
|
PREDICETED_RETENTION("Predicted Retention"),
|
||||||
|
SERVER_HEALTH_ESTIMATE("Server Health Estimate"),
|
||||||
|
LAST_30_DAYS_TEXT("Last 30 Days"),
|
||||||
|
PLAYERBASE_DEVELOPMENT("Playerbase Development"),
|
||||||
|
CURRENT_PLAYERBASE("Current Playerbase"),
|
||||||
|
WORLD_PLAYTIME("World Playtime"),
|
||||||
|
WORLD_LOAD("WORLD LOAD"),
|
||||||
|
LOW_TPS_SPIKES("Low TPS Spikes"),
|
||||||
|
LOADED_ENTITIES("Loaded Entities"),
|
||||||
|
LOADED_CHUNKS("Loaded Chunks"),
|
||||||
|
ENTITIES("Entities"),
|
||||||
|
CHUNKS("Chunks"),
|
||||||
|
AVG("AVG"),
|
||||||
|
PLAYER_LIST("Player List"),
|
||||||
|
NAME("Name"),
|
||||||
|
REGISTERED_TEXT("Registered"),
|
||||||
|
GEOLOCATION_TEXT("Geolocation"),
|
||||||
|
COUNTRY("Country"),
|
||||||
|
COMMNAND_USAGE("Command Usage"),
|
||||||
|
USED_COMMANDS("Used Commands"),
|
||||||
|
UNIQUE_TEXT("Unique");
|
||||||
|
|
||||||
|
private final String defaultValue;
|
||||||
|
|
||||||
|
ServerPageLang(String defaultValue) {
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return "HTML - " + name();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefault() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.djrapitops.plan.system.locale;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class LocaleSystemTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void noIdentifierCollisions() {
|
||||||
|
// No Exception wanted
|
||||||
|
LocaleSystem.getIdentifiers();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user