Skip to content

Commit 61b2324

Browse files
committed
Add support for tone number pinyin field
resolves jdlorimer#56
1 parent c45c286 commit 61b2324

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

chinese/behavior.py

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
sanitize_transcript,
2929
split_transcript,
3030
transcribe,
31+
get_tone_number_pinyin,
3132
)
3233
from .translate import translate
3334
from .util import (
@@ -155,6 +156,20 @@ def fill_transcript(hanzi, note):
155156
return n_filled
156157

157158

159+
def fill_numpinyin(hanzi, note):
160+
filled = False
161+
separated = split_hanzi(hanzi, grouped=False)
162+
163+
if get_first(config['fields']['numpinyin'], note) == '':
164+
trans = transcribe(separated, 'pinyin', 'simp')
165+
tones = [get_tone_number_pinyin(t) for t in trans]
166+
set_all(config['fields']['numpinyin'], note, to=' '.join(tones))
167+
filled = True
168+
169+
return filled
170+
171+
172+
158173
def reformat_transcript(note, group, target):
159174
if target == 'bopomofo':
160175
return
@@ -311,6 +326,7 @@ def update_fields(note, focus_field, fields):
311326
fill_all_defs(hanzi, copy)
312327
fill_classifier(hanzi, copy)
313328
fill_transcript(hanzi, copy)
329+
fill_numpinyin(hanzi, copy)
314330
fill_trad(hanzi, copy)
315331
fill_color(hanzi, copy)
316332
fill_sound(hanzi, copy)

chinese/config.json

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
"法語",
3535
"法语"
3636
],
37+
"numpinyin": [
38+
"NumPinyin",
39+
"Tone Number"
40+
],
3741
"pinyin": [
3842
"Pinyin",
3943
"Reading",

0 commit comments

Comments
 (0)