From cc668e4e1b29b9b9a34e0545d065066c6031d20b 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 | 15 +++++++++++++++ chinese/config.json | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/chinese/behavior.py b/chinese/behavior.py index 5b5832e..68513ce 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,19 @@ def fill_transcript(hanzi, note): return n_filled +def fill_tone_numbers(hanzi, note): + filled = False + separated = split_hanzi(hanzi, grouped=False) + + if get_first(config['fields']['numpinyin'], note) == '': + trans = transcribe(separated, 'pinyin', 'simp') + tones = [get_tone_number_pinyin(t) for t in trans] + set_all(config['fields']['numpinyin'], note, to=' '.join(tones)) + filled = True + + return filled + + def reformat_transcript(note, group, target): if target == 'bopomofo': return @@ -311,6 +325,7 @@ def update_fields(note, focus_field, fields): fill_all_defs(hanzi, copy) fill_classifier(hanzi, copy) fill_transcript(hanzi, copy) + fill_tone_numbers(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..5d65e67 100644 --- a/chinese/config.json +++ b/chinese/config.json @@ -34,6 +34,11 @@ "法語", "法语" ], + "toneNumbers": [ + "Tone Numbers", + "Tones", + "NumPinyin" + ], "pinyin": [ "Pinyin", "Reading",