コード例 #1
0
ファイル: deploy.py プロジェクト: mxsyx/bdtrans
def setup(appid, secretkey, source_lang, target_lang):
    config = {
        "APPID": appid,
        "SECRETKEY": secretkey,
        "SOURCE_LANG": source_lang,
        "TARGET_LANG": target_lang
    }
    with open(PROFILE, 'w') as f:
        json.dump(config, f)
        print(_('\nSetup successful!'))
        print(_('\nYour profile is located at %s') % PROFILE)
コード例 #2
0
ファイル: deploy.py プロジェクト: mxsyx/bdtrans
def change_lang(source_lang, target_lang):
    config = None
    with open(PROFILE, 'r') as f:
        config = json.load(f)
    config['SOURCE_LANG'] = source_lang
    config['TARGET_LANG'] = target_lang
    with open(PROFILE, 'w') as f:
        json.dump(config, f)
    print(_('Change source and target languages successful!'))
    print(_('The default source language is => %s') % source_lang)
    print(_('The default target language is => %s') % target_lang)
コード例 #3
0
ファイル: deploy.py プロジェクト: mxsyx/bdtrans
def change_appid(appid, secretkey):
    config = None
    with open(PROFILE, 'r') as f:
        config = json.load(f)
    config['APPID'] = appid
    config['SECRETKEY'] = secretkey
    with open(PROFILE, 'w') as f:
        json.dump(config, f)
    print(_('Change app info successful!'))
    print(_('Your appid is => %s') % appid)
    print(_('Your secretkey is => %s') % secretkey)
コード例 #4
0
ファイル: deploy.py プロジェクト: mxsyx/bdtrans
def read_info():
    appid = ''
    while (True):
        appid = input(_('please enter your appid: '))
        if appid is not '':
            break
    secretkey = ''
    while (True):
        secretkey = input(_('please enter your secretkey: '))
        if secretkey is not '':
            break
    return {'appid': appid, 'secretkey': secretkey}
コード例 #5
0
ファイル: deploy.py プロジェクト: mxsyx/bdtrans
def read_lang():
    while (True):
        source_lang = input(_('please enter the source language code: '))
        if source_lang is '':
            source_lang = language.DEFAULT_SOURCE_LANG
            break
        if lib.check_source_code(source_lang):
            break
    while (True):
        target_lang = input(_('please enter the target language code: '))
        if target_lang is '':
            target_lang = language.DEFAULT_TARGET_LANG
            break
        if lib.check_target_code(target_lang):
            break
    return {'source_lang': source_lang, 'target_lang': target_lang}
コード例 #6
0
def translate_loop():
    while True:
        try:
            user_input = prompt_toolkit.prompt(
                '> ',history=_file_history,
                auto_suggest=_auto_suggest_from_history,    
                completer=_word_completer)
            if user_input:
                _select_operate(user_input)
        except KeyboardInterrupt:
            print(_('To exit, type /quit'))
コード例 #7
0
ファイル: deploy.py プロジェクト: mxsyx/bdtrans
def initialize_app():
    print(
        _('At First, you need to configure the appid and secretkey.\n\n'
          'If you don\'t have an appid, plaese see:\n'
          'https://github.com/zsimline/bdtrans/blob/master/README.md\n'))

    info = read_info()

    print(
        _('\nAnd, it is recommended that you specify common '
          'source and target languages.   \n\nThe following '
          'language codes are legal:\n'))
    lib.list_langs()
    print(
        _('If you press Enter directly, the default source or '
          'target language will be specified.\n'))

    lang = read_lang()

    setup(info['appid'], info['secretkey'], lang['source_lang'],
          lang['target_lang'])
コード例 #8
0
def _set_lang(source_lang, target_lang):
    """
    Setting source language code and target language code.
    
    If only the target language is specified,
    the source language will be specified as auto.
    If only the source language is specified, 
    an error message is prompted.
    """
    if source_lang and target_lang:
        lib.set_lang(source_lang, target_lang)
    elif not source_lang and target_lang:
        lib.set_lang('auto', target_lang)
    elif source_lang and not target_lang:
        print(_("Can't just specify the source language !"))
        sys.exit(0)
    else:
        return
コード例 #9
0
 def _save_error(self):
     print(
         _('[error] please use the command in this way:'
           '\n\t/save filename\n\tsuch as save my_result'))
コード例 #10
0
 def _set_lang_error(self):
     print(
         _('[error] please use the command in this way:'
           '\n\t/setlang source_lang target_lang'
           '\n\tsuch as setlang en zh'))
コード例 #11
0
import urllib

from bdtrans._global import _

ERROR_MSG = {
    '52001':
    _('request timeout: please retry.'),
    '52002':
    _('system error: please retry.'),
    '52003':
    _('unauthorized user: check if your appid is correct or if the '
      'service is open.'),
    '54000':
    _('the required parameters are blank: check whether the parameters '
      'are missing.'),
    '54001':
    _('signature error: please check your signature generation method.'),
    '54003':
    _('restricted access frequency: please reduce your call frequency.'),
    '54004':
    _('inadequate account balance: please go to the management console '
      'to recharge the account.'),
    '54005':
    _('long query requests are frequent: please reduce the sending '
      'frequency of long query and try again after 3S.'),
    '58000':
    _('client IP illegality: check whether the IP address filled in '
      'the personal data is correct or not. You can go to the management '
      'control platform to modify the IP restriction. IP can be left blank.'),
    '58001':
    _('language Direction of the Translated Language is not Supported: '
コード例 #12
0
def _get_parser():
    """
    Create and return a command line parameter parser.
    """
    parser = argparse.ArgumentParser(prog='bdtrans', add_help=False)
    parser.add_argument('-h',
                        '--help',
                        action='store_true',
                        help=_("show this message and exit"))
    parser.add_argument('-v',
                        '--version',
                        action='store_true',
                        help=_("show program's version number and exit"))
    parser.add_argument('-l',
                        '--list',
                        action='store_true',
                        help=_('show reference table of languages and exit'))
    parser.add_argument('-S',
                        '--shell',
                        action='store_true',
                        help=_('start an interactive shell'))
    parser.add_argument(
        '-q',
        '--quiet',
        action='store_true',
        help=_('do not print translation results to the console'))
    parser.add_argument('-s',
                        '--source',
                        metavar='CODE',
                        help=_('specify the source language'))
    parser.add_argument('-t',
                        '--target',
                        metavar='CODE',
                        help=_('specify the target language'))
    parser.add_argument('-i',
                        '--input',
                        metavar='FILENAME',
                        help=_('specify the input file'))
    parser.add_argument('-o',
                        '--output',
                        metavar='FILENAME',
                        help=_('specify the output file'))
    parser.add_argument('--init',
                        action='store_true',
                        help=_('follow the wizard to initialize app'))
    parser.add_argument('--changeinfo',
                        action='store_true',
                        help=_('change AppID in configuration file'))
    parser.add_argument(
        '--changelang',
        action='store_true',
        help=_('change translation rules in configuration file'))
    return parser
コード例 #13
0
    Defines the source language code.
    """
    auto = 'auto'


class TargetCode(Code):
    """ 
    Defines the target language code.
    Notice that: Target language code cannot be auto.
    """
    pass


# Language List
LANGUAGES = {
    'zh': _('Chinese'),
    'en': _('English'),
    'jp': _('Japanese'),
    'kor': _('Korean'),
    'fra': _('French'),
    'spa': _('Spanish'),
    'th': _('Thai'),
    'ara': _('Arabic'),
    'ru': _('Russian'),
    'pt': _('Portuguese'),
    'de': _('German'),
    'it': _('Italian'),
    'el': _('Greek'),
    'nl': _('Dutch'),
    'pl': _('Polish'),
    'bul': _('Bulgarian'),
コード例 #14
0
def _exit_cmdline():
    print(_('Good Bye!'))
    sys.exit(0)
コード例 #15
0
def _print_help():
    print(_('\nThe following commands are supported:\n'))
    print(_('  /reve  \n\treverse source language and target language'))
    print(_('  /rule  \n\tshow current translation rules'))
    print(_('  /list  \n\tshow reference table of languages and exit'))
    print(_('  /help  \n\tprint help information'))
    print(_('  /quit  \n\tquit the program'))
    print(_('  /save filename \n\tsave translation results'))
    print(_('  /setlang source_lang target_lang'))
    print(_('  \tset the source and target languages'))
    print(_('\nTry to use =code to temporarily specify the target language,'
           '\nthen the source language is automatically specified as auto,'
           '\nfor example "=zh hello world"\n'))
    print(_('Want more help information? Please see:\n'
           'https://github.com/zsimline/immortal/blob/master/README.md\n'))