Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions chinese/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
sanitize_transcript,
split_transcript,
transcribe,
get_tone_number_pinyin,
)
from .translate import translate
from .util import (
Expand Down Expand Up @@ -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']['toneNumbers'], note) == '':
trans = transcribe(separated, 'pinyin', 'simp')
tones = [get_tone_number_pinyin(t) for t in trans]
set_all(config['fields']['toneNumbers'], note, to=' '.join(tones))
filled = True

return filled


def reformat_transcript(note, group, target):
if target == 'bopomofo':
return
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions chinese/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"法語",
"法语"
],
"toneNumbers": [
"Tone Numbers",
"Tones",
"NumPinyin"
],
"pinyin": [
"Pinyin",
"Reading",
Expand Down
3 changes: 3 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_get_fields_no_arg(self):
'Hanzi (Color)',
'Hanzi',
'Measure Word',
"NumPinyin",
'Pinyin (Taiwan)',
'Pinyin',
'Reading',
Expand All @@ -55,6 +56,8 @@ def test_get_fields_no_arg(self):
'Sound (Mandarin)',
'Sound',
'Spoken',
'Tone Numbers',
'Tones',
'Trad',
'Trad.',
'TradColor',
Expand Down