ツールの話をしよう~コマンドライン翻訳


このブログを見てらっしゃる方はtwitterのFFの方がメインであろうかと思います。
つまりは小説関連のご同胞ですよね?
皆さん、翻訳・辞書ツールを使っていらっしゃると思います。
今回は私が使っている Windows10 PC上でのコマンドラインで動作する翻訳・辞書ツールをご紹介しようと思います。

その名もtranslate-shellです。
soimort/translate-shell: Command-line translator … – GitHub

このツールはコマンドラインからgoogle翻訳等のWEBアプリを使って、翻訳したり辞書をひいたりしてくれる超便利なソフトです。
小説の執筆をしているときに、ちょっと「この英単語、どういう意味だっけ?」とか、「英語タイトルなんにしよう?」とか思うことありますよね。
それでいちいちChromeを立ち上げてgoogle翻訳を開くってめんどくさいですよね?
そんなとき、コマンドラインからバシャバシャっと入力して辞書を引いたり翻訳できたら便利だと思いません?
私はすごく思います。

例えば和英翻訳ならばこんな感じ。

kuyo@DESKTOP-8O0L9BP:~$ je '腹が減った'
腹が減った
(Haragahetta)

I am hungry

Translations of 腹が減った
[ 日本語 -> English ]

腹が減った
    I am hungry, hungry
kuyo@DESKTOP-8O0L9BP:~$

例えば英和翻訳ならばこんな感じ。

kuyo@DESKTOP-8O0L9BP:~$ ej 'Never let me go'
Never let me go

私を離さないで
(Watashi o hanasanaide)

Translations of Never let me go
[ English -> 日本語 ]

Never let me go
    私を離さないで, 私を手放すことはありません, 私は手放すことはありません
kuyo@DESKTOP-8O0L9BP:~$

例えば和英辞書ならばこんな感じ。

kuyo@DESKTOP-8O0L9BP:~$ je -d 'きょうだい'
きょうだい
(Kyō dai)

Siblings

Translations of きょうだい
[ 日本語 -> English ]
kuyo@DESKTOP-8O0L9BP:~$

例えば英和辞書ならこんな感じ。

kuyo@DESKTOP-8O0L9BP:~$ ej 'Sibling'
Sibling
/ˈsibliNG/

兄弟姉妹
(Keiteishimai)

Translations of Sibling
[ English -> 日本語 ]

Sibling
    兄弟姉妹, 兄弟
kuyo@DESKTOP-8O0L9BP:~$

英英辞書的にも使えます。

kuyo@DESKTOP-8O0L9BP:~$ ej -d 'love'
love
/ləv/

愛
(Ai)

Definitions of love
[ English -> 日本語 ]

verb
    feel a deep romantic or sexual attachment to (someone).
        - "Though you tried to deny it, you must trust your heart that deep inside you love him."
    Synonyms: care very much for, feel deep affection for, hold very dear, adore, think the world of, be devoted to, dote on, idolize, worship, be in love with, be infatuated with, be smitten with, be besotted with, be mad/crazy/nuts/wild about, have a crush on, carry a torch for

noun
    an intense feeling of deep affection.
        - "My brother, and his real, strong love for me that was able to pull me back into the world I know."
    Synonyms: deep affection, fondness, tenderness, warmth, intimacy, attachment, endearment, devotion, adoration, doting, idolization, worship, passion, ardor, desire, lust, yearning, infatuation, besottedness

    a person or thing that one loves.
        - "By the end of the trip I knew she had two loves ; her son and her carpets."
    Synonyms: beloved, loved one, love of one's life, dear, dearest, dear one, darling, sweetheart, sweet, angel, honey, lover, inamorato, inamorata, amour, paramour

    (in tennis, squash, and some other sports) a score of zero; nil.
        - "To come back from two sets to love and win it is an awesome feeling."

Synonyms
    verb
        - care very much for, feel deep affection for, hold very dear, adore, think the world of, be devoted to, dote on, idolize, worship, be in love with, be infatuated with, be smitten with, be besotted with, be mad/crazy/nuts/wild about, have a crush on, carry a torch for
        - like very much, delight in, enjoy greatly, have a passion for, take great pleasure in, derive great pleasure from, relish, savor, have a weakness for, be partial to, have a soft spot for, have a taste for, be taken with, get a kick out of, have a thing about, be mad/crazy/nuts/wild about, be hooked on, get off on
        - enjoy
        - have intercourse, eff, hump, get laid, make out, have sex, do it, fuck, bed, make love, jazz, sleep together, bang, screw, bonk, be intimate, know, lie with, have it off, sleep with

    noun
        - relationship, love affair, romance, liaison, affair of the heart, amour
        - beloved, loved one, love of one's life, dear, dearest, dear one, darling, sweetheart, sweet, angel, honey, lover, inamorato, inamorata, amour, paramour
        - best wishes, regards, good wishes, greetings, kind/kindest regards
        - liking of/for, enjoyment of, appreciation of/for, taste for, delight for/in, relish of, passion for, zeal for, appetite for, zest for, enthusiasm for, keenness for, fondness for, soft spot for, weakness for, bent for, proclivity for, inclination for, disposition for, partiality for, predilection for, penchant for
        - compassion, care, caring, regard, solicitude, concern, friendliness, friendship, kindness, charity, goodwill, sympathy, kindliness, altruism, unselfishness, philanthropy, benevolence, fellow feeling, humanity
        - deep affection, fondness, tenderness, warmth, intimacy, attachment, endearment, devotion, adoration, doting, idolization, worship, passion, ardor, desire, lust, yearning, infatuation, besottedness
        - love life, lovemaking, making love, sexual love
        - passion
        - dear, dearest, beloved, honey
        - sexual love

Examples
    - In short, how can there be love for the country without love for the people?

    - they were both in love with her

    - babies fill parents with intense feelings of love

    - Ian drinks his coffee and talks enthusiastically about his love of singing.

    - people who love democracy

    - I guess Michael and I were trying to find a way to express our brotherly love for one another.

    - So passionate is my love of opera, that I crave any activity that extends my time in the Arts Centre.

    - Years later he has combined his love for zoology with his appreciation of the female form.

    - She dwells on her charming manner, love of clothes, loyalty to her brother and, in later life, to her adoptive city.

    - you're such a love!

    - "Emily, my dear," said the spinster aunt, with a patronising air, "don't talk so loud, love."

    - You did that? I love it!

    - He lost his ambition and forgot everything but his love for this unworthy woman.

    - Brotherly love comes at a price, it seems.

    - He truly did love her, and deep down he knew his family would too, but he was still nervous.

    - All the very very best to you Tom, and lots of love from Charlie.

    - I had a great interest and love of music, and music was always a part of the family, but no one had ever pursued it.

    - Looking forward to seeing you soon, Lots of love, Grannie

    - We also send our best love to you and the children all wish that they were going on the same ship as their Father.

    - Each one is very powerful, but none of them is as strong as your love for your daughter.

    - do you love me?

    - We have always happy together and our love for each other has been strong and growing for sometime now.

    - we share a love of music

    - Try falling in love with someone who is from a different country and speaks a different language.

    - She did not overtly try to attract Edgar, but he was still falling in love with her.

    - My love for her was as strong as ever, as it is now, at this very moment.

    - I'd love a cup of tea

    - It's alright my love you are safe with me.

    - I had to try to put my intense passionate love for him to the side and be his friend.

    - their love for their country
kuyo@DESKTOP-8O0L9BP:~$

どうですか?
便利でしょう?
これはLinuxのShellとかで動作するコマンドなのですが、Windows10にインストールすることも可能です。
ただ、多少手順がめんどくさいので順を追って説明しますね。

Windows10上のコマンドラインと言ってもDOS窓でもなければ、PowerShellでもありません。
WSLです。

WSLはWindows Subsystem for Linuxの略で、マイクロソフトが提供する、Windows10上で動作するLinuxなんですね。
コマンドライン上でLinuxの様々なツールが使えてしまうというスグレモノです。

先ずはWSLのインストールから始めます。
WHLのインストールのために、まずWHLを許可します。
コントロールパネルを開きます。

[プログラム]をクリックします。

[プログラムと機能]をクリックします。

左ペインにある[Windowsの機能の有効化または無効化]をクリックします。

リストの下のほうにある[Windows Subsystem for Linux]のチェックを入れて[OK]をクリックします。

暫く待つと完了します。

PCの再起動を求められるので再起動します。

スタートメニューから[Microsoft Store]を起動します。

検索から[WSL]を探します。

LinuxのDistributionを選びます。
特に好みが無ければUbuntuが良いでしょう。

[入手]をクリック。
インストールされます。

[起動]をクリックするとWSLのコマンドラインが開きます。

暫く待つとuser nameを聞いてきます。

ここで自分の作成したいuser nameを入力します。
私はkuyoにしました。

次にuserのpasswordを聞いてきます。
ローカルの話なので適当に覚えやすいpasswordを設定します。

確認のためにもう一度passwordを入力します。

これでWSLのインストールはおしまいです。
Windows上に仮想的なLinuxが立ち上がったことになります。
しかもUbuntuですからaptで欲しいツールを簡単にインストールすることができます。

ちなみにこのLInux環境のrootディレクトリは以下になります。

C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\

kuyoのhomeは以下ですね。

C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\kuyo

ではWSLのコマンドターミナルから必要なツールをインストールします。
先ずはaptのupdate。

kuyo@DESKTOP-8O0L9BP:~$ sudo apt update
[sudo] password for kuyo:

passwordを聞いてくるので先ほど設定したものを入力します。

導入にはいくつかのツールが必要です。
具体的にはgit, gawk, makeが必要なのでインストールします。

kuyo@DESKTOP-8O0L9BP:~$ sudo apt install git
kuyo@DESKTOP-8O0L9BP:~$ sudo apt install gawk

gitとgawkが必要ですが既に最新のものが入っていました。
makeもインストールします。

kuyo@DESKTOP-8O0L9BP:~$ sudo apt install make
kuyo@DESKTOP-8O0L9BP:~$ sudo apt install make-guile

途中”Do you want to continue? [Y/n] Y”と聞いてきますのでyと[enter]キーを押します。
ネットへの接続が必要です。

次にtranslate-shellをダウンロードします。

kuyo@DESKTOP-8O0L9BP:~$ git clone https://github.com/soimort/translate-shell

ディレクトリを移動します。

kuyo@DESKTOP-8O0L9BP:~$ cd translate-shell

makeしてinstallします。

kuyo@DESKTOP-8O0L9BP:~/translate-shell$ make
[OK] Task build completed.
kuyo@DESKTOP-8O0L9BP:~/translate-shell$ sudo make install
[OK] Task build completed.
[OK] translate-shell installed.
kuyo@DESKTOP-8O0L9BP:~/translate-shell$

以上でインストールはおしまいです。
transというコマンドがインストールされました。
使い方は以下で分かります。

kuyo@DESKTOP-8O0L9BP:~$ trans --help
Usage:  trans [OPTIONS] [SOURCES]:[TARGETS] [TEXT]...

Information options:
    -V, -version
        Print version and exit.
    -H, -help
        Print help message and exit.
    -M, -man
        Show man page and exit.
    -T, -reference
        Print reference table of languages and exit.
    -R, -reference-english
        Print reference table of languages (in English names) and exit.
    -L CODES, -list CODES
        Print details of languages and exit.
    -S, -list-engines
        List available translation engines and exit.
    -U, -upgrade
        Check for upgrade of this program.

Translator options:
    -e ENGINE, -engine ENGINE
        Specify the translation engine to use.

Display options:
    -verbose
        Verbose mode. (default)
    -b, -brief
        Brief mode.
    -d, -dictionary
        Dictionary mode.
    -identify
        Language identification.
    -show-original Y/n
        Show original text or not.
    -show-original-phonetics Y/n
        Show phonetic notation of original text or not.
    -show-translation Y/n
        Show translation or not.
    -show-translation-phonetics Y/n
        Show phonetic notation of translation or not.
    -show-prompt-message Y/n
        Show prompt message or not.
    -show-languages Y/n
        Show source and target languages or not.
    -show-original-dictionary y/N
        Show dictionary entry of original text or not.
    -show-dictionary Y/n
        Show dictionary entry of translation or not.
    -show-alternatives Y/n
        Show alternative translations or not.
    -w NUM, -width NUM
        Specify the screen width for padding.
    -indent NUM
        Specify the size of indent (number of spaces).
    -theme FILENAME
        Specify the theme to use.
    -no-theme
        Do not use any other theme than default.
    -no-ansi
        Do not use ANSI escape codes.
    -no-autocorrect
        Do not autocorrect. (if defaulted by the translation engine)
    -no-bidi
        Do not convert bidirectional texts.
    -bidi
        Always convert bidirectional texts.
    -no-warn
        Do not write warning messages to stderr.
    -dump
        Print raw API response instead.

Audio options:
    -p, -play
        Listen to the translation.
    -speak
        Listen to the original text.
    -n VOICE, -narrator VOICE
        Specify the narrator, and listen to the translation.
    -player PROGRAM
        Specify the audio player to use, and listen to the translation.
    -no-play
        Do not listen to the translation.
    -no-translate
        Do not translate anything when using -speak.
    -download-audio
        Download the audio to the current directory.
    -download-audio-as FILENAME
        Download the audio to the specified file.

Terminal paging and browsing options:
    -v, -view
        View the translation in a terminal pager.
    -pager PROGRAM
        Specify the terminal pager to use, and view the translation.
    -no-view, -no-pager
        Do not view the translation in a terminal pager.
    -browser PROGRAM
        Specify the web browser to use.
    -no-browser
        Do not open the web browser.

Networking options:
    -x HOST:PORT, -proxy HOST:PORT
        Use HTTP proxy on given port.
    -u STRING, -user-agent STRING
        Specify the User-Agent to identify as.
    -4, -ipv4, -inet4-only
        Connect only to IPv4 addresses.
    -6, -ipv6, -inet6-only
        Connect only to IPv6 addresses.

Interactive shell options:
    -I, -interactive, -shell
        Start an interactive shell.
    -E, -emacs
        Start the GNU Emacs front-end for an interactive shell.
    -no-rlwrap
        Do not invoke rlwrap when starting an interactive shell.

I/O options:
    -i FILENAME, -input FILENAME
        Specify the input file.
    -o FILENAME, -output FILENAME
        Specify the output file.

Language preference options:
    -l CODE, -hl CODE, -lang CODE
        Specify your home language.
    -s CODES, -sl CODES, -source CODES, -from CODES
        Specify the source language(s), joined by '+'.
    -t CODES, -tl CODES, -target CODES, -to CODES
        Specify the target language(s), joined by '+'.

Text preprocessing options:
    -j, -join-sentence
        Treat all arguments as one single sentence.

Other options:
    -no-init
        Do not load any initialization script.

See the man page trans(1) for more information.
kuyo@DESKTOP-8O0L9BP:~$

ただしこのままでは使いにくいので ~/.bashrc に以下の二行を付け加えます。

alias ej="trans -sl=en -tl=ja"
alias je="trans -sl=ja -tl=en"

テキストエディッタはnanoというものが標準でインストールされているのでそれを使います。
もちろんvimをインストールするのでも良いし、以下のファイルをWindowsのテキストエディッタで直接編集するのでも構いません。

C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\kuyo\.bashrc

編集できましたら一度exitコマンドで抜けます。

kuyo@DESKTOP-8O0L9BP:~$ exit   

再度の起動はスタートメニューから行えます。
Ubuntuならば以下のようなアプリが増えています。

いかがでしょうか?
手順は多いのですが、意外と簡単にインストールすることができました。
これで快適な執筆ライフがおくれますね。

WSLは単にtranslate-shellのためだけではなく、様々なツールを使うことができます。
例えば電卓。
bcというコマンドがあります。
これはコマンドラインで計算ができるというスグレモノです。

小説を執筆しているときに距離だとか時間の確認に電卓が欲しい場合がありますが、これもコマンドラインで用が足りてしまうわけです。
変数も使えるし、上下カーソルで履歴も拾えるので普通の電卓よりも高機能だったりします。
終了は quit と入力して[enter]キーを押します。

ご同胞の諸兄姉の執筆ライフが少しでも充実されんことを心より祈りつつ。


コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です