def transcribe(text, transcription=None, only_one=True):
    u'''
    Converts to specified transcription.
    Eg : 你 becomes nǐ (transcription="Pinyin", only_one=True)

    Pinyin, Taiwan Pinyin and Bopomofo: lookup in local words dictionaries
    first, and use characters dictionary as a backup.

    If no transcription is specified, use the transcription set in the menu.
    '''
    text = cleanup(text)
    if text == "":
        return ""
    if None == transcription:
        transcription = chinese_support_config.options["transcription"]
    if "Pinyin" == transcription:
        r = db.get_pinyin(text, taiwan=False)
    elif "Pinyin (Taiwan)" == transcription:
        r = db.get_pinyin(text, taiwan=True)
    elif "Cantonese" == transcription:
        r = db.get_cantonese(text, only_one)
    elif "Bopomofo" == transcription:
        r = db.get_pinyin(text, taiwan=True)
        r = bopomofo_module.bopomofo(no_accents(r))
    else:
        r = ""
    return r
示例#2
0
def transcribe(text, transcription=None, only_one=True):
    u'''
    Converts to specified transcription.
    Eg : 你 becomes nǐ (transcription="Pinyin", only_one=True)

    Pinyin, Taiwan Pinyin and Bopomofo: lookup in local words dictionaries
    first, and use characters dictionary as a backup.

    If no transcription is specified, use the transcription set in the menu.
    '''
    text = cleanup(text)
    if text == "":
        return ""
    if None == transcription:
        transcription = chinese_support_config.options["transcription"]
    if "Pinyin" == transcription:
        r = db.get_pinyin(text, taiwan=False)
    elif "Pinyin (Taiwan)" == transcription:
        r = db.get_pinyin(text, taiwan=True)
    elif "Cantonese" == transcription:
        r = db.get_cantonese(text, only_one)
    elif "Bopomofo" == transcription:
        r = db.get_pinyin(text, taiwan=True)
        r = bopomofo_module.bopomofo(no_accents(r))
    else:
        r = ""
    return r
def get_character_transcription(hanzi, transcription=None, only_one=False):
    if transcription == None:
        transcription = chinese_support_config.options['transcription']
    if "Bopomofo" == transcription:
        transcription = "Pinyin"
        bopomofo = True
    else:
        bopomofo = False

    def concat(a, b):
        return a + ' ' + b

    if "Pinyin" == transcription:
        transcriptions = transcribe_module.get_pinyin(hanzi)
    else:
        transcriptions = characterLookup.getReadingForCharacter(
            hanzi, transcription)
    if 0 == len(transcriptions):
        text = ""
    elif only_one:
        try:
            text = transcriptions[0]
        except:
            text = ""
    else:
        text = reduce(concat, transcriptions)
    if bopomofo:
        text = bopomofo_module.bopomofo(no_accents(text))
    return text
def get_character_transcription(hanzi, transcription=None, only_one=False):
    if transcription == None:
        transcription = chinese_support_config.options['transcription']
    if "Bopomofo" == transcription:
        transcription="Pinyin"
        bopomofo=True
    else:
        bopomofo=False

    def concat(a, b):
        return a+' '+b
    if "Pinyin" == transcription:
        transcriptions = transcribe_module.get_pinyin(hanzi)
    else:
        transcriptions = characterLookup.getReadingForCharacter(hanzi, transcription)
    if 0 == len(transcriptions):
        text = ""
    elif only_one:
        try:
            text = transcriptions[0]
        except:
            text = ""
    else:
        text = reduce(concat, transcriptions)
    if bopomofo:
        text = bopomofo_module.bopomofo(no_accents(text))
    return text
 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 get_character_transcription(hanzi, transcription=None):
    if transcription == None:
        transcription = chinese_support_config.options['transcription']

    if "Pinyin" == transcription:
        text = db.get_pinyin(hanzi)
    elif "Pinyin (Taiwan)" == transcription:
        text = db.get_pinyin(hanzi, taiwan=True)
    elif "Cantonese" == transcription:
        text = db.get_cantonese(hanzi)
    elif "Bopomofo" == transcription:
        text = db.get_pinyin(hanzi, taiwan=True)
        text = bopomofo_module.bopomofo(no_accents(text))
    else:
        text = ""
    return text
 def insert_multiple_pinyin_sub(p):
     hanzi=p.group(1)
     transc = db.get_pinyin(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)
示例#9
0
def get_character_transcription(hanzi, transcription=None):
    if transcription == None:
        transcription = chinese_support_config.options['transcription']

    if "Pinyin" == transcription:
        text = db.get_pinyin(hanzi)
    elif "Pinyin (Taiwan)" == transcription:
        text = db.get_pinyin(hanzi, taiwan=True)
    elif "Cantonese" == transcription:
        text = db.get_cantonese(hanzi)
    elif "Bopomofo" == transcription:
        text = db.get_pinyin(hanzi, taiwan=True)
        text = bopomofo_module.bopomofo(no_accents(text))
    else:
        text = ""
    return text
示例#10
0
 def insert_multiple_pinyin_sub(p):
     hanzi=p.group(1)
     transc = db.get_pinyin(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 pinyin_to_bopomofo(pinyin):
    u'''
    Converts Pinyin to Bopomofo.
    '''
    return bopomofo_module.bopomofo(no_accents(cleanup(pinyin)))
示例#12
0
def pinyin_to_bopomofo(pinyin):
    u'''
    Converts Pinyin to Bopomofo.
    '''
    return bopomofo_module.bopomofo(no_accents(cleanup(pinyin)))