Only add Traditional Characters to Anki Flashcards if they differ from the Simplified Characters

Sim1080

Member
Hello everyone,

in the dictionaries available in Pleco you can usually see simplified and traditional characters next to each other if they differ from each other:
- For example: 过〔過〕

But if they do not differ there is only one character depicted
- For example: 吃

Now I want to achieve the same when exporting them to Anki Flashcards. But I run into the problem that, when checkmarking both simplified and traditional headwords in one field, but the character is the same in simplified and traditional, the character still gets printed twice:
- For example: 吃[吃] (here I just want 吃)
- For example: 过[過] (good)

Is there a way to do this?
I was trying to send simplified and traditional characters to different fields in my anki flashcards to then write code that hides the second field, if the 1st and 2nd field are equal. Unfortunately I have no idea about html and was wondering if someone knows how to code this or knows of a more direct/better solution.

Thanks in advance!
 

Sim1080

Member
I have now managed to write a ugly solution for the anki template for anyone interested that works for me. Of course I am still interested in other ideas :)

HTML:
<div id="hanzi", style="font-family: FZKai-Z03;font-size: 70px; ">{{Hanzi}}</div>
<div id="hanzit", style="font-family: FZKai-Z03;font-size: 70px; ">{{Hanzi (traditional)}}</div>

<script>
   var fst_field = document.getElementById("hanzi").innerHTML;
   var snd_field = document.getElementById("hanzit").innerHTML;

   if (fst_field === snd_field) {
       document.getElementById("hanzit").style.display = 'none';  // Hides the traditional field if both fields are equal
   } else {
       document.getElementById("hanzit").style.display = 'block';  // Shows traditional field if both fields are equal
     
       var hanzitContent = document.getElementById("hanzit").innerHTML;
       document.getElementById("hanzit").innerHTML = '〔' + hanzitContent + '〕'; // Add extra brackets around traditional characters
   }
</script>
 

Shun

状元
Hi Sim1080,

I think that yours is a rather elegant solution as it acts right inside Anki, at the end of the processing chain. I would have modified the HTML document that was exported from Pleco using Python. But with your current solution, the result will look right no matter what data you will pass to Anki in the future, without any further work necessary for you to do, which clearly makes it a superior solution.

Cheers, Shun
 

mikelove

皇帝
Staff member
We've generally adopted the philosophy with Anki that we're going to dump data into whatever system you're already using and only apply minimal styling to it on our end. This is partly because when we first added Anki support we assumed that it would mostly be used by people who were already using Pleco with Anki and hence already had some system for getting our text-based card export files into a flashcard format they liked, but also it's because there are so many different interesting templates / plugins / etc that we don't really feel like we could integrate well with all of them, and we didn't want to impose some specific system that you'd be stuck using for all of your newly added Pleco cards.

But anyway it seems like you're pretty much already doing what we'd recommend here.
 

Sim1080

Member
Thank you guys,
btw. I am a huge fan of both of your passions for this project and it's a joy to play with all the features; it is the best structured and well designed dictionary (and language learning app) I have every used.
Love your work!
 

Shun

状元
Happy to hear it! :) You're very welcome. The main contribution is from Mike, of course, but I and others have added a lot to Pleco over the years, too, making it more fun and effective to use.
 
Top