-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for (biblatex)
langid
to be an optional field in entr…
…y editor (#12071) * Configured project and started integrating langid into classes * Successfully integrated a langid dropdown menu with all langid values into gui and program logic * Fixed style in tests * Introduced display name to Langid enum and wrote more tests * Updated CHANGELOG.md to reflect that the langid optional field has been integrated. * Updated files in accordance to feedback from maintainers, including: - removed redundant description in CHANGELOG.md - removed unnecessary gradle properties - removed unnecessary tests - fixed formatting/commented out code * Discard changes to gradle.properties * Update langid field entry in CHANGELOG.md Co-authored-by: Oliver Kopp <[email protected]> * Updated some files in accordance to feedback from maintainers, including: - refactored and renamed LangidEditorViewModel.java to LanguageEditorViewModel (and tests) - re-added gradle property - reverted edits to BibtexEntryTypeDefinitions.java - removed FieldProperty.LANGUAGEID so both language and langid standard fields have FieldProperty.LANGUAGE NB: Still yet to fix tests * re-added gradle parallel property * cleanup * use set * checkstyle * disable test rule * apply rules * revert junit recipe --------- Co-authored-by: Oliver Kopp <[email protected]> Co-authored-by: Christoph <[email protected]>
- Loading branch information
1 parent
17c3e2c
commit d9b38ce
Showing
11 changed files
with
341 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/org/jabref/gui/fieldeditors/optioneditors/LanguageEditorViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.jabref.gui.fieldeditors.optioneditors; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import javax.swing.undo.UndoManager; | ||
|
||
import javafx.util.StringConverter; | ||
|
||
import org.jabref.gui.autocompleter.SuggestionProvider; | ||
import org.jabref.logic.integrity.FieldCheckers; | ||
import org.jabref.model.database.BibDatabaseMode; | ||
import org.jabref.model.entry.Langid; | ||
import org.jabref.model.entry.field.Field; | ||
import org.jabref.model.strings.StringUtil; | ||
|
||
public class LanguageEditorViewModel extends OptionEditorViewModel<Langid> { | ||
private BibDatabaseMode databaseMode; | ||
|
||
public LanguageEditorViewModel(Field field, SuggestionProvider<?> suggestionProvider, BibDatabaseMode databaseMode, FieldCheckers fieldCheckers, UndoManager undoManager) { | ||
super(field, suggestionProvider, fieldCheckers, undoManager); | ||
this.databaseMode = databaseMode; | ||
} | ||
|
||
@Override | ||
public StringConverter<Langid> getStringConverter() { | ||
return new StringConverter<>() { | ||
@Override | ||
public String toString(Langid object) { | ||
if (object == null) { | ||
return null; | ||
} else { | ||
return object.getLangid(); // Langid used as both display and value | ||
} | ||
} | ||
|
||
@Override | ||
public Langid fromString(String string) { | ||
if (StringUtil.isNotBlank(string)) { | ||
return Langid.parse(string).orElse(null); | ||
} else { | ||
return null; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Collection<Langid> getItems() { | ||
return Arrays.asList(Langid.values()); | ||
} | ||
|
||
@Override | ||
public String convertToDisplayText(Langid object) { | ||
return object.getName(); // Langid and display text are the same | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.jabref.model.entry; | ||
|
||
import java.util.Optional; | ||
|
||
import org.jabref.logic.bibtex.FieldWriter; | ||
/** | ||
* Language identifiers based on BibLaTeX manual specifications. | ||
* See the BibLaTeX documentation for full details: | ||
* <a href="http://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdfhangelo">BibLaTeX manual</a> | ||
*/ | ||
|
||
public enum Langid { | ||
BASQUE("Basque", "basque"), | ||
BULGARIAN("Bulgarian", "bulgarian"), | ||
CATALAN("Catalan", "catalan"), | ||
CROATIAN("Croatian", "croatian"), | ||
CZECH("Czech", "czech"), | ||
DANISH("Danish", "danish"), | ||
AMERICAN("American", "american"), | ||
USENGLISH("US English", "USenglish"), | ||
ENGLISH("English", "english"), | ||
BRITISH("British", "british"), | ||
UKENGLISH("UK English", "UKenglish"), | ||
CANADIAN("Canadian", "canadian"), | ||
AUSTRALIAN("Australian", "australian"), | ||
NEWZEALAND("New Zealand", "newzealand"), | ||
ESTONIAN("Estonian", "estonian"), | ||
FINNISH("Finnish", "finnish"), | ||
FRENCH("French", "french"), | ||
GERMAN("German", "german"), | ||
AUSTRIAN("Austrian", "austrian"), | ||
SWISSGERMAN("Swiss German", "swissgerman"), | ||
NGERMAN("German (New)", "ngerman"), | ||
NAUSTRIAN("Austrian (New)", "naustrian"), | ||
NSWISSGERMAN("Swiss German (New)", "nswissgerman"), | ||
GREEK("Greek", "greek"), | ||
MAGYAR("Hungarian", "hungarian"), | ||
HUNGARIAN("Hungarian", "hungarian"), | ||
ICELANDIC("Icelandic", "icelandic"), | ||
ITALIAN("Italian", "italian"), | ||
LATVIAN("Latvian", "latvian"), | ||
LITHUANIAN("Lithuanian", "lithuanian"), | ||
MARATHI("Marathi", "marathi"), | ||
NORSK("Norwegian (Bokmål)", "norsk"), | ||
NYNORSK("Norwegian (Nynorsk)", "nynorsk"), | ||
POLISH("Polish", "polish"), | ||
BRAZIL("Portuguese (Brazilian)", "brazil"), | ||
PORTUGUESE("Portuguese", "portuguese"), | ||
PORTUGES("Portuguese (alt)", "portuges"), | ||
ROMANIAN("Romanian", "romanian"), | ||
RUSSIAN("Russian", "russian"), | ||
SERBIAN("Serbian (Latin)", "serbian"), | ||
SERBIANC("Serbian (Cyrillic)", "serbianc"), | ||
SLOVAK("Slovak", "slovak"), | ||
SLOVENE("Slovene", "slovene"), | ||
SLOVENIAN("Slovenian", "slovenian"), | ||
SPANISH("Spanish", "spanish"), | ||
SWEDISH("Swedish", "swedish"), | ||
TURKISH("Turkish", "turkish"), | ||
UKRAINIAN("Ukrainian", "ukrainian"); | ||
|
||
|
||
private final String name; | ||
private final String langid; | ||
|
||
Langid(String name, String langid) { | ||
this.name = name; | ||
this.langid = langid; | ||
} | ||
|
||
public String getLangid() { | ||
return langid; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public static Optional<Langid> getByLangid(String id) { | ||
for (Langid lang : Langid.values()) { | ||
if (lang.langid.equalsIgnoreCase(id)) { | ||
return Optional.of(lang); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
public static Optional<Langid> parse(String value) { | ||
return Langid.getByLangid(value.trim().toLowerCase()); | ||
} | ||
|
||
public String getJabRefFormat() { | ||
return (FieldWriter.BIBTEX_STRING_START_END_SYMBOL + "%s" + FieldWriter.BIBTEX_STRING_START_END_SYMBOL).formatted(langid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/test/java/org/jabref/gui/fieldeditors/optioneditors/LanguageEditorViewModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.jabref.gui.fieldeditors.optioneditors; | ||
|
||
import java.util.Collection; | ||
import java.util.EnumSet; | ||
import java.util.HashSet; | ||
|
||
import javax.swing.undo.UndoManager; | ||
|
||
import org.jabref.gui.autocompleter.SuggestionProvider; | ||
import org.jabref.logic.FilePreferences; | ||
import org.jabref.logic.integrity.FieldCheckers; | ||
import org.jabref.logic.journals.JournalAbbreviationRepository; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.database.BibDatabaseMode; | ||
import org.jabref.model.entry.Langid; | ||
import org.jabref.model.entry.field.StandardField; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class LanguageEditorViewModelTest { | ||
|
||
private LanguageEditorViewModel languageEditorViewModel; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
BibDatabaseContext databaseContext = mock(BibDatabaseContext.class); | ||
FilePreferences filePreferences = mock(FilePreferences.class); | ||
JournalAbbreviationRepository abbreviationRepository = mock(JournalAbbreviationRepository.class); | ||
FieldCheckers fieldCheckers = new FieldCheckers(databaseContext, filePreferences, abbreviationRepository, false); | ||
SuggestionProvider<?> suggestionProvider = mock(SuggestionProvider.class); | ||
|
||
languageEditorViewModel = new LanguageEditorViewModel( | ||
StandardField.LANGUAGEID, | ||
suggestionProvider, | ||
BibDatabaseMode.BIBLATEX, | ||
fieldCheckers, | ||
new UndoManager() | ||
); | ||
} | ||
|
||
@Test | ||
void getItemsShouldReturnAllLangidValues() { | ||
Collection<Langid> items = new HashSet<>(languageEditorViewModel.getItems()); | ||
assertEquals(EnumSet.allOf(Langid.class), items); | ||
} | ||
|
||
@Test | ||
void stringConversion() { | ||
String langidString = "bulgarian"; | ||
Langid langid = languageEditorViewModel.getStringConverter().fromString(langidString); | ||
assertEquals(Langid.BULGARIAN, langid, "String should convert to the corresponding Langid"); | ||
|
||
String convertedString = languageEditorViewModel.getStringConverter().toString(Langid.BULGARIAN); | ||
assertEquals(langidString, convertedString, "Langid should convert back to its string representation"); | ||
} | ||
|
||
@Test | ||
void stringConversionWithHumanReadableName() { | ||
// Test conversion from human-readable name to Langid | ||
String langidString = "Basque"; | ||
Langid langid = languageEditorViewModel.getStringConverter().fromString(langidString); | ||
assertEquals(Langid.BASQUE, langid, "Human-readable name should convert to the corresponding Langid"); | ||
|
||
// Test conversion from Langid to human-readable name | ||
String convertedString = languageEditorViewModel.getStringConverter().toString(Langid.BASQUE); | ||
assertEquals("basque", convertedString, "Langid should convert back to its lowercase string representation"); | ||
} | ||
|
||
@Test | ||
void handlingNullValue() { | ||
// Test the handling of a null value | ||
Langid result = languageEditorViewModel.getStringConverter().fromString(null); | ||
assertNull(result, "Null input should return null Langid"); | ||
} | ||
|
||
@Test | ||
void handlingBlankValue() { | ||
// Test the handling of a blank string | ||
Langid result = languageEditorViewModel.getStringConverter().fromString(" "); | ||
assertNull(result, "Blank input should return null Langid"); | ||
} | ||
} | ||
|
Oops, something went wrong.