Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mumtazrifai
Copy link
Contributor

Fixes #3818

Right click on a flag in the browser sidebar > Rename > Delete all of the text > Hit Enter to confirm.
After doing this, Anki will go back to using the default name of the flag, including using the correct translation if the user switches languages.

anki-flags

@YukiNagat0
Copy link
Contributor

Python Style Guide suggestion:

if new_name == "" and item.item_type == SidebarItemType.FLAG:

Change the if new_name == "" to if not new_name

@dae
Copy link
Member

dae commented Feb 18, 2025

Thank you for contributing!

This could be done in a simpler way. Instead of storing a translation, simply delete the entry for that key from the dictionary, so that the default translation is used instead. This would change less code, and ensure the text remains correct when the user switches interface language.

@mumtazrifai
Copy link
Contributor Author

I already do delete the dictionary entry from the "flagLabels" config entry here:

anki/qt/aqt/flags.py

Lines 67 to 74 in 8380131

def restore_default_flag_name(self, flag_index: int) -> None:
labels = self.mw.col.get_config("flagLabels", {})
if str(flag_index) not in labels:
return
del labels[str(flag_index)]
self.get_flag(flag_index).label = self.default_flag_names[flag_index]
self.mw.col.set_config("flagLabels", labels)
gui_hooks.flag_label_did_change()

When I tested it, the flag label did switch to the correct translation after I changed the language, which indicates to me that it is using the default value and not a stored value in the config.

The reason why I also store the translations in default_flag_names is to make sure that the displayed name of the flag is updated after the function is called. Though after taking another look it seems like that's unnecessary and I can just call require_refresh() to accomplish the same thing.

I hope I correctly understood what you meant! If not please clarify further.

@dae
Copy link
Member

dae commented Feb 21, 2025

Sorry, I saw the other changes and assumed you were updating the key instead of deleting it. Looks nice and clean now - thanks again!

@dae dae merged commit e373b0e into ankitects:main Feb 21, 2025
1 check passed
mattfengsh added a commit to mattfengsh/anki that referenced this pull request Feb 21, 2025
commit 76c4ec7
Author: Damien Elmes <[email protected]>
Date:   Fri Feb 21 18:29:41 2025 +0700

    Add actions-processing based on qt-misc-processing

commit a7c5376
Author: Damien Elmes <[email protected]>
Date:   Fri Feb 21 18:21:28 2025 +0700

    Update translations

commit 00cc1b4
Author: GithubAnon0000 <[email protected]>
Date:   Fri Feb 21 10:14:15 2025 +0000

    Increase font size for accessibility (ankitects#3832)

    Apparently no font size should be lower than 12px, see https://www.boia.org/blog/accessibility-tips-let-users-control-font-size.

    With the current 55%, I get a computed font size of 8.25px though. Considering the text shows the helpful message "Press ⁨Enter⁩ to accept, ⁨Shift+Enter⁩ for new line.", I think we should add a minimum font size.

commit 8ec139f
Author: llama <[email protected]>
Date:   Fri Feb 21 17:39:11 2025 +0800

    Debounce mathjax rendering to avoid stalling (ankitects#3827)

    * move change-timer to editable

    * debounce mathjax rendering

commit e373b0e
Author: mumtazrifai <[email protected]>
Date:   Fri Feb 21 04:38:04 2025 -0500

    Use default flag name when flag is renamed to empty string (ankitects#3826)

    * Add function to restore the default name of a flag

    * Call function to restore default flag name if flag renamed to empty string

    * Update _load_flags to use the default_flag_names dict

    * Add name to contributors file

    * Add trailing comma to pass tests

    * Update to follow python style guide

    * Update about.py

    * Revert "Update _load_flags to use the default_flag_names dict"

    This reverts commit caa8fea.

    * Use require_refresh() instead of storing default flag names

commit 2727cf3
Author: Damien Elmes <[email protected]>
Date:   Fri Feb 21 10:33:57 2025 +0700

    Update to Rust 1.85

    Edition update to follow later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Browser: can't restore default flag names

3 participants