Sort language map using stream API instead of guava

This commit is contained in:
RaphiMC 2024-06-15 21:44:07 +02:00
parent 62b70303c4
commit 9e85832a9f
No known key found for this signature in database
GPG key ID: 0F6BB0657A03AC94

View file

@ -17,9 +17,6 @@
*/
package net.raphimc.viaproxy.ui;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Ordering;
import net.raphimc.viabedrock.api.util.FileSystemUtil;
import net.raphimc.viaproxy.ViaProxy;
@ -28,6 +25,7 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;
public class I18n {
@ -49,7 +47,9 @@ public class I18n {
} catch (Throwable e) {
throw new RuntimeException("Failed to load translations", e);
}
LOCALES = ImmutableSortedMap.copyOf(LOCALES, Ordering.from(Comparator.comparing((Properties p) -> p.getProperty("language.name"))).onResultOf(Functions.forMap(LOCALES)));
LOCALES = LOCALES.entrySet().stream()
.sorted(Comparator.comparing(e -> e.getValue().getProperty("language.name")))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> newValue, LinkedHashMap::new));
currentLocale = ViaProxy.getSaveManager().uiSave.get("locale");
if (currentLocale == null || !LOCALES.containsKey(currentLocale)) {