Skip to content

EnderQIU/cp2translate

Repository files navigation

cp2trans

Translate text from clipboard.

Installation

This script is written for Windows. Believe it's a hard way to setup but an easy one to use :).

  1. Python 37 on Windows 10.
  2. Upgrade pip by pip install -U pip.
  3. Install aws-cli from https://aws.amazon.com/cli/ and initiate aws by aws configure.
  4. Install MeCab from https://github.com/ikegami-yukino/mecab/releases/tag/v0.996. Add the /bin directory $PATH.
  5. Make additional dictionary by mecab-ipadic-neologd. Since it's hard to build on Windows 10, I suggest build it on Ubuntu WSL and copy all the files under /usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd into C:\neologd\ if you want the newest dictionary. Here's a pre-built dictionary on 2019-05-11.
  6. NOTICE: We use pydub's ffmpeg binding to play TTS mp3 audio. If you want to enable TTS, download ffmpeg from https://ffmpeg.zeranoe.com/builds/ or just ignore the warning. We won't cache audio so you should mind of its costs.
  7. Install requirements by pip install -r requirements.txt. If your system default encoding is not UTF-8, you might fail on installing the romkan package. Usually neither chcp nor locale.setdefaultencoding() won't solve this problem. I suggest manually download romkan source code and replace line 12 README = open(os.path.join(here, 'README.rst')).read() to README = open(os.path.join(here, 'README.rst'), encoding="utf-8").read(). Then run python .\setup.py install.
  8. Copy a file of config.ini.example and rename it to config.ini. Fill in the appid and the secretkey, make sure Natural Language Translation of this app is enabled.
  9. Run the script by python .\cp2trans\cp2trans.py or install cp2trans by python setup.py install (in this way you can pass step 8).
  • The easier way if your computer has been configured:
pip install cp2trans

Upgrade

Be sure to backup your config.ini before upgrading. It will be overwritten.

Usage

PS C:\cp2translate> python .\cp2trans.py -h
usage: cp2trans [-h] [--passwd log_file] [-p section] [-l log_file]
                [-e password] [-v {0,1}] [-m pattern] [-n number]
                [-s lang_code] [-t lang_code1,lang_code2,lang_code3] [-d]
                [-i seconds] [-a agth_path] [-o agth_opts]

Clipboard to Translate.

optional arguments:
  -h, --help            show this help message and exit
  --passwd log_file     Change password of an encrypted log_file or
                        encrypt/decrypt log_file and exit.
  -p section, --profile section
                        Load profiled options from the specified section of
                        "config.ini" file. Any other options from command line
                        will be ignored. See details in "config.example.ini".
  -l log_file, --log log_file
                        Save and read translation history from "log_file" to
                        save API calls.
  -e password, --encrypt password
                        Encrypt logfile if you don't want it too exposed ;P.
                        Have to be specified while loading an encrypted log
                        file.
  -v {0,1}, --voice {0,1}
                        Voice of TTS. "0" for male and "1" for female. Unset
                        for disable TTS.
  -m pattern, --match pattern
                        Only TTS when match <pattern>.
  -n number, --number number
                        Translate only if number of characters less than
                        <number>.
  -s lang_code, --source lang_code
                        Source language code. Romkan will only be shown with
                        "ja".
  -t lang_code1,lang_code2,lang_code3, --target lang_code1,lang_code2,lang_code3
                        Three target language codes used by youdao, aws and
                        google. Separated by comma.
  -d, --disable         Disable specified translate engine. Corresponding
                        results will be saved as null
  -i seconds, --interval seconds
                        Time interval in seconds to check the clipboard.
  -a agth_path, --agth agth_path
                        Start AGTH text hook. "agth_path" must be specified.
                        You might also have to specify -o option.
  -o agth_opts, --opt agth_opts
                        Extra options passed to "agth.exe". See details by the
                        help button of "agth.exe" window.

About

Translate text from clipboard.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages