Skip to content

Commit 3bb9132

Browse files
committed
Add tone number pinyin field
resolves jdlorimer#56
1 parent c45c286 commit 3bb9132

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

chinese/behavior.py

+15
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,19 @@ def fill_transcript(hanzi, note):
155156
return n_filled
156157

157158

159+
def fill_numpinyin(hanzi, note):
160+
key = 'numpinyin'
161+
separated = split_hanzi(hanzi, grouped=False)
162+
163+
if get_first(config['fields'][key], note) == '':
164+
trans = transcribe(separated, 'pinyin', 'simp')
165+
tone = ""
166+
for t in trans:
167+
tone += get_tone_number_pinyin(t) + ' '
168+
169+
set_all(config['fields'][key], note, to=tone.strip())
170+
171+
158172
def reformat_transcript(note, group, target):
159173
if target == 'bopomofo':
160174
return
@@ -311,6 +325,7 @@ def update_fields(note, focus_field, fields):
311325
fill_all_defs(hanzi, copy)
312326
fill_classifier(hanzi, copy)
313327
fill_transcript(hanzi, copy)
328+
fill_numpinyin(hanzi, copy)
314329
fill_trad(hanzi, copy)
315330
fill_color(hanzi, copy)
316331
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)