def trans_word_sub(p): r = translate_module.transcribe_cjklib(p.group(1)) if r: if "Pinyin" == transcription: return " " + r + " " elif "Bopomofo" == transcription: bopo = "" for c in no_accents(r).split(" "): bopo += bopomofo_module.bopomofo(c) return bopo else: return p.group()
def trans_word_sub(p): r = add_diaeresis(translate_module.transcribe_cjklib(p.group(1))) if r: if "Pinyin" == transcription: return " " + r + " " elif "Bopomofo" == transcription: bopo = "" for c in no_accents(r).split(" "): bopo += bopomofo_module.bopomofo(c) return bopo else: return p.group()
def insert_multiple_pinyin_sub(p): hanzi=p.group(1) transc = translate_module.transcribe_cjklib(hanzi) if not transc: return p.group() transc = transc.split(" ") ret = "" hanzi = p.group(1) while len(hanzi): if "Pinyin" == transcription: ret += hanzi[0] + "["+transc.pop(0)+"]" elif "Bopomofo" == transcription: ret += hanzi[0] + "[" ret += bopomofo_module.bopomofo(no_accents(transc.pop(0)))+"]" hanzi = hanzi[1:] return ret+p.group(2)
def insert_multiple_pinyin_sub(p): hanzi = p.group(1) transc = translate_module.transcribe_cjklib(hanzi) if not transc: return p.group() transc = transc.split(" ") ret = "" hanzi = p.group(1) while len(hanzi): if "Pinyin" == transcription: ret += hanzi[0] + "[" + transc.pop(0) + "]" elif "Bopomofo" == transcription: ret += hanzi[0] + "[" ret += bopomofo_module.bopomofo(no_accents( transc.pop(0))) + "]" hanzi = hanzi[1:] return ret + p.group(2)