Skip to content

Instantly share code, notes, and snippets.

@shoui520
Last active May 3, 2024 19:56
Show Gist options
  • Star 35 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoui520/25460fd2e9fb194d3e5152fa2ce42ca2 to your computer and use it in GitHub Desktop.
Save shoui520/25460fd2e9fb194d3e5152fa2ce42ca2 to your computer and use it in GitHub Desktop.
Chinese Yomichan Setup

Yomichan setup for Chinese

https://learnjapanese.moe

Yomichan is a browser extension created for Japanese which enables its users to quickly and efficiently look up words on a webpage.
While it is made for Japanese, it is possible to use it for other languages, including Chinese.

Getting Yomichan

Yomichan is available for both Chromium and Firefox based browsers. You can find the respective versions below.
Chrome Web Store
Firefox Add-Ons
Once installed, it will open a new tab page, just close it for now so we don't confuse each other.

Dictionaries

Before you can use Yomichan, you must load dictionaries into it. The dictionaries listed on Yomichan's webpage are for Japanese, however there are some custom made ones for Chinese.

You can download them below. Thanks to Chrono07 at Refold for making the monolingual ones.
These come in .zip extension and are not to be extracted by the user.

Yomichan Dictionaries for Chinese - Google Drive

Installing dictionaries and basic usage

  1. Click on the yomichan-icon icon in the browser toolbar.
  2. Click on the cog icon to access the settings page.
  3. On the left sidebar, click on "Dictionaries" and then click on "Configure installed and enabled dictionaries…"
  4. Click the "Import" button on the bottom.
  5. Here's where you select the dictionaries to import. Have a read of what each dictionary is and decide which ones you want.

[ZH-EN] CEDICT.zip - This is a popular Chinese to English bilingual dictionary, it is the dictionary used in many ZH-EN dictionary projects such as Pleco and Zhongwen. Matches both simplified and traditional.

[ZH-JA] 中日大辞典 第二版.zip - Chinese to Japanese bilingual dictionary. Do not import if not a speaker of Japanese. Matches only simplified.

[ZH-ZH] 兩岸詞典.zip - Monolingual dictionary that has "mainland definitions". It is rather small, though. Matches both simplified and traditional.

[ZH-ZH] 漢語大詞典.zip - Monolingual dictionary. Hanyu Da Cidian, the largest Chinese dictionary, with over 600k word entries, first published 1986-1994. Matches both simplified and traditional.

[ZH-ZH] 萌典国语辞典 (简体字) - (Moedict) Monolingual dictionary. From an online dictionary website that takes definitions from the Ministry of Education (MoE) of Taiwan. Overall the best choice as it has the most compound words. Matches both simplified and traditional.

  1. Please wait for the dictionaries to import. This could take a while if you are using a mechanical hard drive.
  2. Once complete, you can test Yomichan by holding down the Shift key and hovering over Japanese text. Here is a sample: 中文. It will display a pop up box displaying the definitions separated by dictionary.
    Click anywhere outside of the box or press the Esc key to dismiss.

The audio button is meant to play the word pronounced by a native speaker, but by default, Yomichan does not support audio for Chinese. But we can just add it.

Audio

You can use the Yomichan Forvo Server anki add-on to enable Yomichan to play audio from Forvo.

It is an add-on originally made for Japanese but it has the functionality to change the language.

First you need to add the add-on: https://ankiweb.net/shared/info/580654285

Restart Anki, then go back to your addons and double click Yomichan Forvo Server to open the settings menu.

Change the language from ja to zh

For Cantonese, change it to yue. Please note that this will only affect audio so readings will remain in Pinyin.

Now restart Anki again to apply changes.

In Yomichan settings, go in Audio and click configure audio sources. Remove everything and add a Custom URL JSON http://localhost:8770/?expression={expression}&term={term}

It should just work. You should also enable the automatic playback of audio in Yomichan too.

Forcing Chinese font

In the case that your fonts are not displaying in Chinese (e.g. the 绞丝 looks like the Japanese variant), you will need to force it with CSS.

In the Yomichan settings page, go on Apperance > then Custom CSS

.kanji-link {
   font-family: "Microsoft YaHei";
}

.source-text {
   font-family: "Microsoft YaHei";
}

.gloss-content {
   font-family: "Microsoft YaHei";
   font-size: 21px
}

.tag-label-content {
   font-family: FangSong Regular;
   font-size: 15px
}

Above is an example, it should be human-readable and self explanatory. If you want a different font, then just change what is appending font-family:

On Windows you have the following possible fonts by default:

Simplified

DengXian
FangSong Regular
KaiTi Regular
Microsoft YaHei
Microsoft YaHei UI
NSimSun Regular
SimHei Regular
SimSun Regular
SimSun-ExtB Regular

Traditional

Microsoft JhengHei
Microsoft JhengHei UI
MingLiU_HKSCS-ExtB Regular
MingLiU-ExtB Regular
PMingLiU-ExtB Regular

@alexkiani
Copy link

Hey thanks for this! For some reason, the audio doesn't work for me -- just gives me a clicking sound when I click the audio button. Could there be a problem with the init file?

@takti92
Copy link

takti92 commented Aug 15, 2022

Thank you! Works like a charm - same problem with the audio though!

@shoui520
Copy link
Author

shoui520 commented Sep 2, 2022

Hey thanks for this! For some reason, the audio doesn't work for me -- just gives me a clicking sound when I click the audio button. Could there be a problem with the init file?

Thank you! Works like a charm - same problem with the audio though!

I updated the fork. Hopefully it works now.

@Sabin-Pla
Copy link

Sabin-Pla commented Sep 15, 2022

@shoui520 The audio does not work for me. If I pull up the network traffic viewer when I click the audio button the init.py file does return a response which validates yomichan's required schema and the url provided in the response plays back just fine when I manually open it in the browser. The setup and your script seems fine but it still doesn't work :c

Edit: I think yomichan might be getting error 403/forbidden when trying to open the URLS. I've found a work around by downloading the mp3s using the same Session object we created in order to open the search page on fervo. We can then return the url (local path) of the mp3 to yomichan :)

@dansclearov
Copy link

@Sabin-Pla can you please share the changes you have done to the script to make it work?

@mautinobruno
Copy link

That's useful! Thanks!

@teksongeap
Copy link

absolutely amazing, this little tip has increased my quality of life exponentially, thanks dude

@shoui520
Copy link
Author

@shoui520 The audio does not work for me. If I pull up the network traffic viewer when I click the audio button the init.py file does return a response which validates yomichan's required schema and the url provided in the response plays back just fine when I manually open it in the browser. The setup and your script seems fine but it still doesn't work :c

Edit: I think yomichan might be getting error 403/forbidden when trying to open the URLS. I've found a work around by downloading the mp3s using the same Session object we created in order to open the search page on fervo. We can then return the url (local path) of the mp3 to yomichan :)

nice, i cant program but i hope someone can get the script working this way

@shoui520
Copy link
Author

I know I'm probably really late to this, but the Yomichan Forvo add-on got an update that just lets you change the language. Ive updated this guide.

@Wyzmic
Copy link

Wyzmic commented Oct 3, 2023

Could you make a traditional chinese to japanese dictionary? Doesn't seem to exist unfortunately

@roger-yu-ds
Copy link

roger-yu-ds commented Nov 7, 2023

The extraction from Forvo is not reliable, I have the settings for Mandarin, but sometimes the Japanese pronunciation is saved into Anki.

My Yomichan Forvo Server config is

{
    "language": "zh",
    "port": 8770,
    "preferred_usernames": [],
    "show_gender": true
}

and the Yomichan browser add-on setting for Audio Sources is

http://localhost:8770/?term={term}&reading={reading}&language=zh

On the Yomichan pop up, the Audio that play is in the correct language. But somehow the Japanese one is saved into Anki.

Any ideas on how to fix this?

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