2013年6月21日金曜日

秀丸マクロ:用語統一(一括置換&用語集生成)マクロ

SimplyTerms(ST)に同梱されているマクロの中で、次に紹介するのは用語統一用のマクロ、「AddTerm」です。

このマクロを使うと、秀丸標準の[置換]機能よりも簡単に「(一括)置換」ができ、それと同時に、置換した原語と訳語をセットにした用語集を(ほとんど自動的に)作っていくことができます。

基本的な使い方は、
(訳語を訳文に入力→)訳語をクリップボードにコピー→原語を範囲選択→マクロ実行→(用語集に原語と訳語のセットが自動的に登録される)→マクロ実行
ですが、これだけではわかりづらいと思うので、「SimplyTermsを使った翻訳(その1)~(その5)」で使った「1,2-Dichloroethane.docx」の翻訳(英日翻訳)で実際に試してみましょう。

下の点線と点線の間をコピーして、「1,2-Dichloroethane_jpn.txt」という名前のテキストファイルを秀丸で作ってください。(もとの原稿にサブ拡張子をつけて、テキスト抽出して、サブ拡張子を変更して、英日翻訳をするためのテキストファイルが準備できた状態です。)

サブ拡張子は常にターゲット言語にしておいてください。今回のマクロでは、このサブ拡張子も関係してきます。

------
[[BD-1]]
1,2-Dichloroethane
[[BD-2]]
The chemical compound 1,2-dichloroethane (or DCA) commonly known by its old name of ethylene dichloride (EDC), is a chlorinated hydrocarbon, mainly used to produce vinyl chloride monomer (VCM, chloroethene), the major precursor for PVC production. It is a colourless liquid with a chloroform-like odour. 1,2-Dichloroethane is also used generally as an intermediate for other organic chemical compounds and as a solvent. It forms azeotropes with many other solvents, including water (b.p. 70.5 C) and other chlorocarbons.[1]
[[BD-3]]
Safety
[[BD-4]]
1,2-Dichloroethane is toxic (especially by inhalation due to its high vapour pressure), highly flammable,[4] and carcinogenic. Its high solubility and 50-year half-life in anoxic aquifers make it a perennial pollutant and health risk that is very expensive to treat conventionally, requiring a method of bioremediation.[5] While the chemical is banned from use by U.S. manufacturers,[6] a case was reported in 2009 of molded plastic consumer products (toys and holiday decorations) from China that released 1,2-dichloroethane into homes at levels high enough to produce cancer risk.[7] Substitutes are recommended and will vary according to application. Dioxolane and toluene are possible substitutes as solvents. Dichloroethane is unstable in the presence of aluminium metal and, when moist, with zinc and iron.
------

では、始めましょう。

※どのように翻訳作業を進めるか、例えば原文の上側に訳文を書いていく、下側に書いていく、原文訳文と交互に書いていくなど、やり方はそれぞれだと思うので、これは一つの例です。

ざっと内容に目を通し、ひとまず、最初の段落(小見出し)を訳しました。

------
[[BD-1]]
1,2-ジクロロエタン
[[BD-2]]
The chemical compound 1,2-dichloroethane (or DCA) commonly known by its old name of ethylene dichloride (EDC), is a chlorinated hydrocarbon, mainly used to produce vinyl chloride monomer (VCM, chloroethene), the major precursor for PVC production. It is a colourless liquid with a chloroform-like odour. 1,2-Dichloroethane is also used generally as an intermediate for other organic chemical compounds and as a solvent. It forms azeotropes with many other solvents, including water (b.p. 70.5 C) and other chlorocarbons.[1]
[[BD-3]]
Safety
[[BD-4]]
1,2-Dichloroethane is toxic (especially by inhalation due to its high vapour pressure), highly flammable,[4] and carcinogenic. Its high solubility and 50-year half-life in anoxic aquifers make it a perennial pollutant and health risk that is very expensive to treat conventionally, requiring a method of bioremediation.[5] While the chemical is banned from use by U.S. manufacturers,[6] a case was reported in 2009 of molded plastic consumer products (toys and holiday decorations) from China that released 1,2-dichloroethane into homes at levels high enough to produce cancer risk.[7] Substitutes are recommended and will vary according to application. Dioxolane and toluene are possible substitutes as solvents. Dichloroethane is unstable in the presence of aluminium metal and, when moist, with zinc and iron.
------

次の段落の最初の方にまた「dichloroethane」を見つけました。この後も何度も出てくるようです。これを一括置換しましょう。
まず「ジクロロエタン」(訳語)を範囲選択し、コピーします(これでクリップボードに「ジクロロエタン」(訳語)がコピーされました)。
次に、「dichloroethane」(原語)を範囲選択します。
そして(範囲選択したままの状態で)、「AddTerm」マクロを実行します。

すると、自動で新しい秀丸ファイルが開き、一行目に
dichloroethane    ジクロロエタン
と入力されました。そのままの状態で、もう一度「AddTerm」マクロを実行します。

翻訳をしていた「1,2-Dichloroethane_jpn.txt」のファイルに自動的に戻り、[置換の確認]という小さいウィンドウが現れ、dichloroethaneとDichloroethaneがハイライトされています。(大文字と小文字は区別されません。)

今回はそのまま全部置換しても大丈夫なので、[一気]をクリックします。すると、下のように、すべて置換されました。

------
[[BD-1]]
1,2-ジクロロエタン
[[BD-2]]
The chemical compound 1,2-ジクロロエタン (or DCA) commonly known by its old name of ethylene dichloride (EDC), is a chlorinated hydrocarbon, mainly used to produce vinyl chloride monomer (VCM, chloroethene), the major precursor for PVC production. It is a colourless liquid with a chloroform-like odour. 1,2-ジクロロエタン is also used generally as an intermediate for other organic chemical compounds and as a solvent. It forms azeotropes with many other solvents, including water (b.p. 70.5 C) and other chlorocarbons.[1]
[[BD-3]]
Safety
[[BD-4]]
1,2-ジクロロエタン is toxic (especially by inhalation due to its high vapour pressure), highly flammable,[4] and carcinogenic. Its high solubility and 50-year half-life in anoxic aquifers make it a perennial pollutant and health risk that is very expensive to treat conventionally, requiring a method of bioremediation.[5] While the chemical is banned from use by U.S. manufacturers,[6] a case was reported in 2009 of molded plastic consumer products (toys and holiday decorations) from China that released 1,2-ジクロロエタン into homes at levels high enough to produce cancer risk.[7] Substitutes are recommended and will vary according to application. Dioxolane and toluene are possible substitutes as solvents. ジクロロエタン is unstable in the presence of aluminium metal and, when moist, with zinc and iron.
------

これが、このマクロの基本的な動きです。

先ほど自動でできた秀丸ファイルを見てみると、ファイル名は「1,2-Dichloroethane_trm.txt」(「元のファイル名_trm.txt」)となっています。サブ拡張子が「_trm」で「英語(tab)日本語」という形式、つまりSTの用語集形式になっていますので、次回似たような案件を依頼されたときに用語集として使えます。

次の単語をまた「AddTerm」で置換すると、今できた「1,2-Dichloroethane_trm.txt」の用語集に追加されます。実際に試してみましょう。

「compound」を「化合物」と置換してみます。
------
[[BD-1]]
1,2-ジクロロエタン
[[BD-2]]
化合物

The chemical compound 1,2-ジクロロエタン (or DCA) commonly known by its old name of ethylene dichloride (EDC), is a chlorinated hydrocarbon, mainly used to produce vinyl chloride monomer (VCM, chloroethene), the major precursor for PVC production. It is a colourless liquid with a chloroform-like odour. 1,2-ジクロロエタン is also used generally as an intermediate for other organic chemical compounds and as a solvent. It forms azeotropes with many other solvents, including water (b.p. 70.5 C) and other chlorocarbons.[1]
[[BD-3]]
Safety
[[BD-4]]
1,2-ジクロロエタン is toxic (especially by inhalation due to its high vapour pressure), highly flammable,[4] and carcinogenic. Its high solubility and 50-year half-life in anoxic aquifers make it a perennial pollutant and health risk that is very expensive to treat conventionally, requiring a method of bioremediation.[5] While the chemical is banned from use by U.S. manufacturers,[6] a case was reported in 2009 of molded plastic consumer products (toys and holiday decorations) from China that released 1,2-ジクロロエタン into homes at levels high enough to produce cancer risk.[7] Substitutes are recommended and will vary according to application. Dioxolane and toluene are possible substitutes as solvents. ジクロロエタン is unstable in the presence of aluminium metal and, when moist, with zinc and iron.
------

まず「化合物」と入力し、これをコピーし、「compound」を範囲選択し、「AddTerm」を実行します。
先ほどの「1,2-Dichloroethane_trm.txt」の1行目に、「compound」と「化合物」のセットが追加され、先ほどあった「dichloroethane」と「ジクロロエタン」のセットは2行目に移動しました。
compound    化合物
dichloroethane    ジクロロエタン
もう一度「AddTerm」マクロを実行すると、また、[置換の確認]という小さいウィンドウが現れ、どのように置換するか聞いてきますので、自分の望む置換方法を選びます。
[一気]で置換した結果は、下のようになります。

------
[[BD-1]]
1,2-ジクロロエタン
[[BD-2]]
化合物

The chemical 化合物 1,2-ジクロロエタン (or DCA) commonly known by its old name of ethylene dichloride (EDC), is a chlorinated hydrocarbon, mainly used to produce vinyl chloride monomer (VCM, chloroethene), the major precursor for PVC production. It is a colourless liquid with a chloroform-like odour. 1,2-ジクロロエタン is also used generally as an intermediate for other organic chemical 化合物@@pl and as a solvent. It forms azeotropes with many other solvents, including water (b.p. 70.5 C) and other chlorocarbons.[1]
[[BD-3]]
Safety
[[BD-4]]
1,2-ジクロロエタン is toxic (especially by inhalation due to its high vapour pressure), highly flammable,[4] and carcinogenic. Its high solubility and 50-year half-life in anoxic aquifers make it a perennial pollutant and health risk that is very expensive to treat conventionally, requiring a method of bioremediation.[5] While the chemical is banned from use by U.S. manufacturers,[6] a case was reported in 2009 of molded plastic consumer products (toys and holiday decorations) from China that released 1,2-ジクロロエタン into homes at levels high enough to produce cancer risk.[7] Substitutes are recommended and will vary according to application. Dioxolane and toluene are possible substitutes as solvents. ジクロロエタン is unstable in the presence of aluminium metal and, when moist, with zinc and iron.
------

※STで用語集を適用したときと同じように、英語が複数形であった箇所には、訳語(日本語)のあとに「@@pl」が自動的につけられます。

これがこのマクロの基本的な動きです。頻繁に使うものなので、入力しやすいショートカットキーを割り当てるといいと思います(マウスを右手で使うなら、左手で簡単に入力できるところがおすすめです)。

[置換の確認]ウィンドウの各項目は、以下のような動きをします。(各項目は、マウスでクリックするだけではなく、括弧に入ったアルファベットを入力することでも選べます。このアルファベットの入力の方が断然早いと思います。)
置換(R)・・・いま選択されている(反転している)箇所のみを置換します。
置換+次(C)・・・いま選択されている(反転している)箇所を置換したあと、次の対象箇所に移動します。
一気(A)・・・対象となる箇所(ハイライトされている箇所)すべてを置換します。
上候補(P)・・・いま選択されている(反転している)箇所を置換せずに、前(上)の対象箇所に移動します。
下候補(N)・・・いま選択されている(反転している)箇所を置換せずに、次(下)の対象箇所に移動します。
キャンセル・・・何も置換せずに終わります。

このマクロを使うときに注意する点は、
  • サブ拡張子を必ずターゲット言語にしておく(英日翻訳の場合は「_jpn」)。このマクロは、自動的に生成される用語集が「英語(tab)日本語」の順番になるように、サブ拡張子を参照して判断しているので、サブ拡張子を間違うと、1列目(英語)と2列目(日本語)が逆になった用語集ができてしまいます。
  • 「AddTerm」マクロを一度実行し用語集ファイルに移動したときに、(英語の複数形など)必要に応じて用語を修正する。英語が複数形だった場合、マクロ実行直後はその複数形(と思われる)部分が範囲選択されている状態なので、削除したり、書き換えたり、等、簡単に修正ができます。
何度か使って慣れてきたら、STの[ヘルプ]→[同梱秀丸マクロのヘルプ]→[個別マクロの操作方法]→[用語統一]をぜひ読んで下さい。


***************************************
実は私はこのマクロをそのまま使うのではなく、一部書き換えて使っています。こういうふうにも使えるよ、ということで、参考に書いておきます。

「AddTerm」マクロの場合、最初に訳語をクリップボードにコピーするために、訳語を訳文中にあらかじめ入力しなければなりません。つまり、次のような流れになります。
(訳語を訳文に入力→)訳語をクリップボードにコピー→原語を範囲選択→マクロ実行→(用語集に原語と訳語のセットが自動的に登録される→)マクロ実行
これを、私の翻訳の進め方に合うように、
原語を範囲選択→マクロ実行→訳語をウィンドウに入力→OKをクリック→(用語集に原語と訳語のセットが自動的に登録される→)マクロ実行
という流れになるようにマクロを変更しました。変更した箇所は次の通りです。

AddTerm.mac(抽出単語を追加するマクロ Ver 3.00)の232行目から253行目
-------------------------------------------------------------------------
    //置換元単語を$$originalwordにコピー
    $$originalword = gettext(seltopx, seltopy, selendx, selendy);
    call ReplaceStr $$originalword, " ", " ";
    $$originalword = $$return;

    //フレーズが登録されているファイルをオープンし、最初に移動。
    call Another_File $PhrsFile;
    escape;
    gofiletop;

    //以下の形式で登録
    //   英語    日本語(リターン)
    if ($TransDir == "EtoJ"){
        insert $$originalword + "\t" +"\n";
        left;
        poppaste;
    } else {
        insert "\t" + $$originalword + "\n";
        gofiletop;
        poppaste ;
    }
    save;
-------------------------------------------------------------------------

-------------------------------------------------------------------------
    //置換元単語を$$originalwordにコピー
    $$originalword = gettext(seltopx, seltopy, selendx, selendy);
    call ReplaceStr $$originalword, " ", " ";
    $$originalword = $$return;
//変更!訳語を入力する
    $jpnword = input("訳語を入力してください");


    //フレーズが登録されているファイルをオープンし、最初に移動。
    call Another_File $PhrsFile;
    escape;
    gofiletop;

    //以下の形式で登録
    //   英語    日本語(リターン)
    if ($TransDir == "EtoJ"){
        insert $$originalword + "\t" +"\n";
        left;
//変更!    poppaste;
        insert $jpnword;


    } else {
        insert "\t" + $$originalword + "\n";
        gofiletop;
//変更!    poppaste ;
        insert $jpnword;

    }
    save;
-------------------------------------------------------------------------

2 件のコメント:

  1. ゆかりさん、こんにちは。うっちー(ucchysnow)です。やっと重い腰を上げて導入してみました!最初から最後までゆかりさんのブログにお世話になった感じです。マクロもたくさんあって迷ったので、とりあえずオススメのものを入れてみました。ご紹介ありがとうございます。

    私も少しずつ使いこなせていけたらいいなと思っています。ブログにリンクを貼らせていただきましたが、もし問題があればご連絡くださいね。

    返信削除
    返信
    1. うっちーさん、こんにちは!

      ブログ参考にしていただいて、ありがとうございます。(リンクもありがとうございます!)少しでもうっちーさんのお役に立てたなら何よりです。

      他のマクロ(地味だけどとても便利なマクロもあるんです!)や秀丸の便利な機能も少しずつ紹介していくつもりですので、お待ちくださいね。

      削除