use of com.djrapitops.plan.settings.locale.lang.Lang in project Plan by plan-player-analytics.
the class LocaleFileReader method loadLegacy.
/**
* Used to migrate old files to new format.
*/
public Locale loadLegacy(LangCode code) throws IOException {
final List<String> lines = resource.asLines();
Locale locale = new Locale(code);
Map<String, Lang> identifiers = LocaleSystem.getIdentifiers();
lines.forEach(line -> {
String[] split = line.split(" \\|\\| ");
if (split.length == 2) {
String identifier = split[0].trim();
Lang msg = identifiers.get(identifier);
if (msg != null) {
locale.put(msg, new Message(split[1]));
}
}
});
return locale;
}
use of com.djrapitops.plan.settings.locale.lang.Lang in project Plan by plan-player-analytics.
the class Locale method replaceLanguageInHtml.
public String replaceLanguageInHtml(String from) {
if (isEmpty()) {
return from;
}
Matcher scriptMatcher = FIND_SCRIPT.matcher(from);
List<String> foundScripts = new ArrayList<>();
while (scriptMatcher.find()) {
foundScripts.add(scriptMatcher.toMatchResult().group(0));
}
TranslatedString translated = new TranslatedString(from);
Arrays.stream(HtmlLang.values()).sorted((one, two) -> Integer.compare(two.getIdentifier().length(), one.getIdentifier().length())).forEach(lang -> getNonDefault(lang).ifPresent(replacement -> translated.translate(lang.getDefault(), replacement.toString())));
StringBuilder complete = new StringBuilder(translated.length());
String[] parts = FIND_SCRIPT.split(translated.toString());
for (int i = 0; i < parts.length; i++) {
complete.append(parts[i]);
if (i < parts.length - 1) {
complete.append(replaceLanguageInJavascript(foundScripts.get(i)));
}
}
return complete.toString();
}
use of com.djrapitops.plan.settings.locale.lang.Lang in project Plan by plan-player-analytics.
the class Locale method replaceLanguageInJavascript.
public String replaceLanguageInJavascript(String from) {
if (isEmpty()) {
return from;
}
TranslatedString translated = new TranslatedString(from);
Arrays.stream(JSLang.values()).sorted((one, two) -> Integer.compare(two.getIdentifier().length(), one.getIdentifier().length())).forEach(lang -> getNonDefault(lang).ifPresent(replacement -> translated.translate(lang.getDefault(), replacement.toString())));
for (Lang extra : new Lang[] { HtmlLang.UNIT_NO_DATA, HtmlLang.TITLE_WORLD_PLAYTIME, // HtmlLang.LABEL_BANNED,
HtmlLang.SIDE_SESSIONS, HtmlLang.LABEL_PLAYTIME, HtmlLang.LABEL_AFK_TIME, HtmlLang.LABEL_LONGEST_SESSION, HtmlLang.LABEL_SESSION_MEDIAN, HtmlLang.LABEL_PLAYER_KILLS, HtmlLang.LABEL_MOB_KILLS, HtmlLang.LABEL_DEATHS, HtmlLang.LABEL_PLAYERS_ONLINE, HtmlLang.LABEL_REGISTERED, HtmlLang.TITLE_SERVER, HtmlLang.TITLE_LENGTH, HtmlLang.TITLE_AVG_PING, HtmlLang.TITLE_BEST_PING, HtmlLang.TITLE_WORST_PING, HtmlLang.LABEL_FREE_DISK_SPACE, HtmlLang.LABEL_NEW_PLAYERS, HtmlLang.LABEL_UNIQUE_PLAYERS, HtmlLang.LABEL_ACTIVE_PLAYTIME, HtmlLang.LABEL_AFK_TIME, HtmlLang.LABEL_AVG_SESSION_LENGTH, HtmlLang.LABEL_AVG_PLAYTIME, HtmlLang.LABEL_AVG_ACTIVE_PLAYTIME, HtmlLang.LABEL_AVG_AFK_TIME, HtmlLang.LABEL_AVG_PLAYTIME, HtmlLang.SIDE_GEOLOCATIONS, HtmlLang.LABEL_PER_PLAYER, HtmlLang.TITLE_JOIN_ADDRESSES }) {
getNonDefault(extra).ifPresent(replacement -> translated.translate(extra.getDefault(), replacement.toString()));
}
return translated.toString();
}
use of com.djrapitops.plan.settings.locale.lang.Lang in project Plan by plan-player-analytics.
the class LocaleFileReader method load.
public Locale load(LangCode code) throws IOException {
try (ConfigReader reader = new ConfigReader(resource.asInputStream())) {
Config config = reader.read();
Locale locale = new Locale(code);
Map<String, Lang> keys = LocaleSystem.getKeys();
config.getConfigPaths().forEach(key -> {
Lang msg = keys.get(key);
if (msg != null) {
locale.put(msg, new Message(config.getString(key)));
}
});
return locale;
}
}
use of com.djrapitops.plan.settings.locale.lang.Lang in project Plan by plan-player-analytics.
the class ComparatorTest method localeEntryComparator.
@Test
void localeEntryComparator() {
Map<Lang, Message> messageMap = new HashMap<>();
messageMap.put(HelpLang.SERVERS, new Message(RandomData.randomString(10)));
messageMap.put(HelpLang.SERVER, new Message(RandomData.randomString(10)));
messageMap.put(HelpLang.DB_RESTORE, new Message(RandomData.randomString(10)));
List<Lang> result = messageMap.entrySet().stream().sorted(new LocaleEntryComparator()).map(Map.Entry::getKey).collect(Collectors.toList());
List<Lang> expected = Arrays.asList(HelpLang.DB_RESTORE, HelpLang.SERVER, HelpLang.SERVERS);
assertEquals(expected, result);
}
Aggregations