Skip to content

Commit

Permalink
Sort languages alphabetically in the preferences JabRef#10660 (JabRef…
Browse files Browse the repository at this point in the history
…#10675)

* classic sort, only for latin alphabet

* sort all languages alphabetically

* sort all languages alphabetically without normalized

* Check style modification

* Update CHANGELOG.md

* classic sort, only for latin alphabet

* sort all languages alphabetically

* sort all languages alphabetically without normalized

* Check style modification

* Update CHANGELOG.md

* Update CHANGELOG.md

* use list

* delete comment

* use pattern

* fix

* pattern var

* remove duplicated sorted

---------

Co-authored-by: Théo Granier <[email protected]>
Co-authored-by: j23sanch <[email protected]>
Co-authored-by: Siedlerchr <[email protected]>
  • Loading branch information
4 people authored Dec 10, 2023
1 parent 43a4393 commit 43817fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

- We fixed an issue where the added protected term has unwanted leading and trailing whitespaces, where the formatted text has unwanted empty brackets and where the word at the cursor in the textbox can be added to the list. [#10415](https://github.com/JabRef/jabref/issues/10415)
- We fixed an issue where in the merge dialog the file field of entries was not correctly merged when the first and second entry both contained values inside the file field. [#10572](https://github.com/JabRef/jabref/issues/10572)
- We fixed some small inconsistencies in the user interface. [#10507](https://github.com/JabRef/jabref/issues/10507) [#10458](https://github.com/JabRef/jabref/issues/10458)
- We fixed some small inconsistencies in the user interface. [#10507](https://github.com/JabRef/jabref/issues/10507) [#10458](https://github.com/JabRef/jabref/issues/10458) [#10660](https://github.com/JabRef/jabref/issues/10660)
- We fixed the issue where the Hayagriva YAML exporter would not include a parent field for the publisher/series. [#10596](https://github.com/JabRef/jabref/issues/10596)

### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class GeneralTabViewModel implements PreferenceTabViewModel {
new SpinnerValueFactory.IntegerSpinnerValueFactory(9, Integer.MAX_VALUE);

private final ReadOnlyListProperty<Language> languagesListProperty =
new ReadOnlyListWrapper<>(FXCollections.observableArrayList(Language.values()));
new ReadOnlyListWrapper<>(FXCollections.observableArrayList(Language.getSorted()));
private final ObjectProperty<Language> selectedLanguageProperty = new SimpleObjectProperty<>();

private final ReadOnlyListProperty<ThemeTypes> themesListProperty =
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/jabref/logic/l10n/Language.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.jabref.logic.l10n;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;

/**
* Contains all supported languages.
Expand Down Expand Up @@ -35,9 +39,9 @@ public enum Language {
UKRAINIAN("украї́нська (Ukrainian)", "uk"),
VIETNAMESE("Vietnamese", "vi");

private static final Pattern IS_NOT_LATIN = Pattern.compile("[^\\p{IsLatin}]");
private final String displayName;
private final String id;

/**
* @param id Typically as 639-1 code
*/
Expand Down Expand Up @@ -70,4 +74,14 @@ public String getDisplayName() {
public String getId() {
return id;
}

public static List<Language> getSorted() {
return Arrays.stream(values())
.sorted(Comparator.comparing(language -> removeNonLatinCharacters(language.getDisplayName())))
.toList();
}

private static String removeNonLatinCharacters(String input) {
return IS_NOT_LATIN.matcher(input).replaceAll("");
}
}

0 comments on commit 43817fd

Please sign in to comment.