diff --git a/.gitignore b/.gitignore index 14c36be..2771edf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ +/jyut6ping3.dict.yaml /jyut6ping3.simple.dict.yaml /background_scripts/dictionary.json.txt -/process.py +/preprocess.py /icons/icon.xcf diff --git a/README.md b/README.md new file mode 100644 index 0000000..164f468 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Inject Jyutping + +A browser extension to add Cantonese pronunciation (Jyutping) on Chinese characters, inspired by [EYHN/Furigana](https://github.com/EYHN/Furigana). + +## Build + +``` +python build/main.py +``` diff --git a/build/main.py b/build/main.py new file mode 100644 index 0000000..b6fb59a --- /dev/null +++ b/build/main.py @@ -0,0 +1,28 @@ +import json +from opencc import OpenCC +import os + +# Preprocess +os.system('wget -nc https://github.com/CanCLID/ToJyutping/raw/master/preprocess.py') +os.system("sed -i 's/src\/ToJyutping\/jyut6ping3.simple.dict.yaml/jyut6ping3.simple.dict.yaml/' preprocess.py") +os.system('python preprocess.py') + +# Build dictionary +converter = OpenCC('t2s') + +d_t = {} +d_cn = {} + +with open('jyut6ping3.simple.dict.yaml') as f: + for line in f: + k_t, v = line.rstrip('\n').split('\t') + k_cn = converter.convert(k_t) + d_t[k_t] = v + d_cn[k_cn] = v + +d = {**d_cn, **d_t} # prefer t over cn +l = list(d.items()) + +with open('background_scripts/dictionary.json.txt', 'w') as f: + f.write(json.dumps(l, ensure_ascii=False).replace('], [', '],\n[')) + f.write('\n') # Add line break at the end of file