I’m currently working on an add-on that generates note types. One feature that I’d like to have in my add-on is to have the field labels be automatically translated when the user changes their language in the Anki settings. When the language changes, I’ll call note.col.models.rename_field
, passing in the translated field labels.
This is all going pretty smoothly thus far, but one snag that I’m having is that Anki doesn’t seem to provide any proper field identifiers. Up until now I’ve just been using the field label as the identifier, but this doesn’t work very well as the labels would no longer be constant as they’re auto-translated. Ideally I’d want something similar to anki.notes.Note#guid
but per field (like an extra key-value pair called guid
in anki.models.FieldDict
).
There are a couple of workarounds that I’ve found so far, but they are all a bit inelegant:
- Modify the field schema to add a note type (e.g.,
col.models.add_field(notetype, col.models.new_field(label) | {'custom_identifier': guid})
). This works but goes against the advice of the documentation [1]. - Continue using the label as an identifier, but cache the selected language, and on every startup, compare the current language with the cached language, and if they differ, then map from the old language to the new language.
I tried looking to see if there are any field identifiers but I couldn’t find any. Did I overlook them? If not, would adding identifiers be a PR that you’re willing to accept?
[1] addon-docs[dot]ankiweb[dot]net/the-anki-module.html?highlight=schema#the-database — I’m not allowed to include links in this post.