From c773fbac38627735d89e2ee9a8123fcaf110c3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Wirnata?= Date: Sun, 22 May 2022 23:35:18 +0200 Subject: [PATCH] Add support for tone number pinyin field resolves luoliyan/chinese-support-redux#56 --- chinese/behavior.py | 19 +++++++++++++++++++ chinese/config.json | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/chinese/behavior.py b/chinese/behavior.py index 5b5832e..dc2f462 100644 --- a/chinese/behavior.py +++ b/chinese/behavior.py @@ -28,6 +28,7 @@ sanitize_transcript, split_transcript, transcribe, + get_tone_number_pinyin, ) from .translate import translate from .util import ( @@ -155,6 +156,23 @@ def fill_transcript(hanzi, note): return n_filled +def fill_numpinyin(hanzi, note): + filled = False + separated = split_hanzi(hanzi, grouped=False) + + if get_first(config['fields']['numpinyin'], note) == '': + trans = transcribe(separated, 'pinyin', 'simp') + tone = '' + for t in trans: + tone += get_tone_number_pinyin(t) + ' ' + + set_all(config['fields']['numpinyin'], note, to=tone.strip()) + filled = True + + return filled + + + def reformat_transcript(note, group, target): if target == 'bopomofo': return @@ -311,6 +329,7 @@ def update_fields(note, focus_field, fields): fill_all_defs(hanzi, copy) fill_classifier(hanzi, copy) fill_transcript(hanzi, copy) + fill_numpinyin(hanzi, copy) fill_trad(hanzi, copy) fill_color(hanzi, copy) fill_sound(hanzi, copy) diff --git a/chinese/config.json b/chinese/config.json index 5147a67..f782040 100644 --- a/chinese/config.json +++ b/chinese/config.json @@ -34,6 +34,10 @@ "法語", "法语" ], + "numpinyin": [ + "NumPinyin", + "Tone Number" + ], "pinyin": [ "Pinyin", "Reading",