krmanik / Anki-xiehanzi

Learn, read, write and practice Mandarin by drawing strokes in Anki Desktop, AnkiDroid and AnkiMobile with audio of HSK 2.0 (HSK1-6) and HSK 3.0 (HSK 1-9) characters.
https://krmanik.github.io/Anki-xiehanzi
Other
157 stars 17 forks source link

fix: adding lv from 旅鼠, fixes #52 #53

Closed faceleg closed 2 months ago

faceleg commented 2 months ago

I don't know anything about zhuyin, tried my best to make it work.

Works for Pinyin.

Screenshot 2024-04-14 at 3 58 10 PM
krmanik commented 2 months ago

Thanks for PR. It is interesting that I never came across these issues because I have tested this with HSK 3.0.

The result should be lǚ shǔ. It breaks when there is no dictionary entry, and when pinyin conversion return v3 instead of u:3. So, the desired fix should be this.

diff --git a/src/pages/create.tsx b/src/pages/create.tsx
index 71233e7..ecbbcff 100644
--- a/src/pages/create.tsx
+++ b/src/pages/create.tsx
@@ -210,6 +210,10 @@ export default function CreateDeck(): JSX.Element {

     let pin = pinyin(word.trim(), { toneToNumber: true });
     pin = pin.replace(/0/g, "5");
+
+    // replace v3 with u:3
+    pin = pin.replace(/v/g, "u:");
+
     let pizh = await pinzhu.pinyinAndZhuyin(pin, "", "");

     let pinyin1 = [decodeHtmlEntities(pizh[1])];
krmanik commented 2 months ago

I have pushed the fix in https://github.com/krmanik/Anki-xiehanzi/commit/251023bfcef558cd9be3bf2e1c68e22f1a631e39