init collator once

This commit is contained in:
Tobias Hagemann 2023-05-05 11:45:02 +02:00
parent 7d62fc78de
commit 2a704d5eb4
No known key found for this signature in database
GPG Key ID: 898890C09D3199B3

View File

@ -31,11 +31,11 @@ public class SupportedLanguages {
public SupportedLanguages(Settings settings) {
var preferredLanguage = settings.languageProperty().get();
preferredLocale = preferredLanguage == null ? Locale.getDefault() : Locale.forLanguageTag(preferredLanguage);
var sorted = LANGUAGE_TAGS.stream().sorted((a, b) -> {
var collator = Collator.getInstance(preferredLocale);
collator.setStrength(Collator.PRIMARY);
return collator.compare(Locale.forLanguageTag(a).getDisplayName(), Locale.forLanguageTag(b).getDisplayName());
}).collect(Collectors.toList());
var collator = Collator.getInstance(preferredLocale);
collator.setStrength(Collator.PRIMARY);
var sorted = LANGUAGE_TAGS.stream() //
.sorted((a, b) -> collator.compare(Locale.forLanguageTag(a).getDisplayName(), Locale.forLanguageTag(b).getDisplayName())) //
.collect(Collectors.toList());
sorted.add(0, Settings.DEFAULT_LANGUAGE);
sorted.add(1, ENGLISH);
sortedLanguageTags = Collections.unmodifiableList(sorted);