Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for (biblatex) langid to be an optional field in entry editor #12071

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

mag-sun
Copy link

@mag-sun mag-sun commented Oct 24, 2024

Overview:

Integrated 'langid' into all biblatex/bibtex supported entry types as an optional field. This is so formatting of entries can be adapted to the language of the entries. Closes #10868.

Changes implemented:

  • Added a 'Langid' enum class defining all valid language ids provided by the biblatex documentation ([https://au.mirrors.cicku.me/ctan/macros/latex/contrib/biblatex/doc/biblatex.pdf]).
  • Added a 'LanguageEditorViewModel' class to handle the gui and dropdown menu.
  • Introduced 'langid' as an important field in all relevant biblatex entry type definitions.
langid.video.mp4

image

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial comments.

Please re-iterate on the biblatex smanual and check whether language and origLanguage also have the same values. If yes, your editor can be used if the field proprty FieldProperty.LANGUAGE langauge is present. If not, then this property can just be remoed.

In other words FieldPropety groups fields together and indicates the editor for it. Do not introduce a property if it used for one field only.

CHANGELOG.md Outdated Show resolved Hide resolved
gradle.properties Outdated Show resolved Hide resolved
src/main/java/org/jabref/logic/msbib/MSBibEntry.java Outdated Show resolved Hide resolved
@@ -18,7 +18,7 @@ public enum FieldProperty {
IDENTIFIER,

LANGUAGE,

LANGUAGEID,
// Field content is text, but should be interpreted as markdown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep empty lines as separator

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, this and LANGUAGE can just be removed. These properties are not used.

Alternataively, use it. And then use the langId field editor as you introduced for all fields having this property.

src/test/java/org/jabref/model/entry/LangidTest.java Outdated Show resolved Hide resolved
src/test/java/org/jabref/model/entry/LangidTest.java Outdated Show resolved Hide resolved
- removed redundant description in CHANGELOG.md
- removed unnecessary gradle properties
- removed unnecessary tests
- fixed formatting/commented out code
gradle.properties Outdated Show resolved Hide resolved
@@ -78,30 +77,4 @@ private static Stream<Arguments> getLangidByStringTest() {
arguments(Optional.empty(), "unknown")
);
}

@Test
public void testLangidNameAndValue() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you remove these test?

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are a bit too verbose and not confirming to the one-assertion-per-test rule. Please streamline.

Other comments inside.

}

@Override
public Langid fromString(String string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return Optional<Langid> instead of null.

Copy link
Author

@mag-sun mag-sun Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that it had to return Langid because the superclass OptionEditorViewModel requires StringConverter<T> to return <T> not Optional<T>?

Comment on lines 65 to 67
// Test conversion from Langid to string
String convertedString = langidEditorViewModel.getStringConverter().toString(Langid.BULGARIAN);
assertEquals(langidString, convertedString, "Langid should convert back to its string representation");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do a seperate test.

Remove the assert text, because this should be the test method name.

(Also do for the other tests)

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

…ing:

- 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
…into 10868-support-for-langid-field

# Conflicts:
#	gradle.properties
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments.

Tests have to be rewritten to fit JabRef style.

No text for failing assertions.

@@ -11,3 +11,4 @@ org.gradle.jvmargs=-Xmx6096M

# hint by https://docs.gradle.org/current/userguide/performance.html#enable_the_build_cache
org.gradle.caching=true
org.gradle.parallel=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change.

* See the BibLaTeX documentation for full details:
* <a href="http://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdfhangelo">BibLaTeX manual</a>
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaDoc needs to be attached to class --> remove empty line here (and add empty line above)


@BeforeEach
void setUp() {
// Mock dependencies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment. The next lines state that by code.

FilePreferences filePreferences = Mockito.mock(FilePreferences.class);
JournalAbbreviationRepository abbreviationRepository = Mockito.mock(JournalAbbreviationRepository.class);

// Initialize FieldCheckers with mocked instances
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment. The next lines state that by code.

// Initialize FieldCheckers with mocked instances
FieldCheckers fieldCheckers = new FieldCheckers(databaseContext, filePreferences, abbreviationRepository, false);

// Mock the SuggestionProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment. The next lines state that by code.

languageEditorViewModel = new LanguageEditorViewModel(
StandardField.LANGUAGEID, // Use the correct field
suggestionProvider, // Mocked SuggestionProvider
BibDatabaseMode.BIBLATEX, // Use the correct BibDatabaseMode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment.

StandardField.LANGUAGEID, // Use the correct field
suggestionProvider, // Mocked SuggestionProvider
BibDatabaseMode.BIBLATEX, // Use the correct BibDatabaseMode
fieldCheckers, // FieldCheckers instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment.

suggestionProvider, // Mocked SuggestionProvider
BibDatabaseMode.BIBLATEX, // Use the correct BibDatabaseMode
fieldCheckers, // FieldCheckers instance
new UndoManager() // UndoManager instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment.

void getItemsShouldReturnAllLangidValues() {
Collection<Langid> items = languageEditorViewModel.getItems();
assertEquals(Langid.values().length, items.size());
assertTrue(items.contains(Langid.BASQUE)); // Check if it contains a specific Langid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment.

Collection<Langid> items = languageEditorViewModel.getItems();
assertEquals(Langid.values().length, items.size());
assertTrue(items.contains(Langid.BASQUE)); // Check if it contains a specific Langid
assertTrue(items.contains(Langid.AMERICAN)); // Additional check for another Langid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to rewrite multiple assert statements to one

assertEquals(List.of(...), items)

@koppor koppor added the status: changes required Pull requests that are not yet complete label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes required Pull requests that are not yet complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for (biblatex) langid field in entry editor
3 participants