(for Internet Explorer)
Sub  TranslateEx( TranslatorPath as string, FromLanguage as string, ToLanguage as string,
                    in_out_Config as TranslateConfigClass )
翻訳ファイルの情報に従って、テキストファイルの一部を翻訳します。
【引数】
TranslatorPath
FromLanguage
翻訳ファイルのパス
翻訳前の言語。 通常 "JP"
ToLanguage
翻訳後の言語。 通常 "EN"
in_out_Config
(入出力) 各種設定、または Empty
テスト
→ T_Translate.vbs
ソース
→ ToolsLib.vbs
.IsTestOnly
.OutFolderPath
.BaseFolderPath
True = すべて翻訳されたかどうかチェックだけします。 (デフォルト)
False = 翻訳します。
翻訳後のファイルを格納するフォルダーのパス。
省略時は、翻訳後のファイルを出力しません。
翻訳ファイルの BaseFolder タグを置き換えた後のパス。
省略時は、翻訳ファイルの BaseFolder タグのテキストが使われます。
参考
翻訳ファイル(*.trans) の説明など
テスト
→ T_Translate.vbs
ソース
→ ToolsLib.vbs
Function  Translate_getOverwritePaths( TranslatorPath as string )
で置き換わるすべてのファイルのフルパスを配列で返します。
【引数】
TranslatorPath
返り値
翻訳ファイルのパス
置き換わるすべてのファイルのフルパスの配列
T_Translate_getOverwritePaths
テスト
→ T_Translate.vbs
ソース
→ ToolsLib.vbs
Function  Translate_getWritable( TranslatorPath as string )
で置き換わるすべてのファイルを含むフォルダーのフルパスを配列で返します。
【引数】
TranslatorPath
返り値
翻訳ファイルのパス
フォルダーのフルパスの配列
T_Translate_getWritable
Function  new_TranslateToEnglish( DictionaryCsvPath as string ) as TranslateToEnglish
辞書ファイルを使って、ソース・ファイルのコメントを英訳します。
【引数】
DictionaryCsvPath
CSV 形式の辞書ファイルのパス
ToolsLib.vbs
モジュール・ファイル:
(src)
サンプル:
Dim tr : Set tr  = new_TranslateToEnglish( "Text1.txt.trans.csv" )
'// tr.IsReverseTranslate = True
Dim w_:Set w_=AppKey.NewWritable( tr.Writable ).Enable()
tr.Translate
いわゆる英訳ソフトのような、文法解析を行って大きな辞書を引くような翻訳ではありません。
内部では、単純なテキストの置換と、置換後のファイルに含まれる文字が英文字だけかどうか
のチェックをします。 翻訳後に英文字以外の文字が残ったら、TranslateToEnglish::c.
E_NotEnglishChar エラーになります。
英訳処理のサンプル
Text1_trans.csv
Text1.c, %eng%\Text1.c
メイン関数, Main function
サブ関数, Sub function
テスト
#include  <stdio.h>

int  main() { }  // メイン関数
int  sub() { }   // サブ関数
Text1.c
%eng%\Text1.c
#include  <stdio.h>

int  main() { }  // Main function
int  sub() { }   // Sub function
1行目の左は、変換前のファイルパスです。
1行目の右は、変換後のファイルパスです。
1行目は、% % で囲んだ環境変数を指定できます。
1行目の右を省略すると、ファイルの置き換えをします。
2行目以降は、翻訳するキーワードを指定します。
→ TranslateToEnglish フォルダ
キーワード:
関連
→ sample / CheckEnglishOnly
関連
英文字以外が無いか、フォルダ全体をチェックする
Text1.txt.trans.csv
廃止
.IsReverseTranslate
Property  TranslateToEnglish::IsReverseTranslate as boolean
.Writable
Property  TranslateToEnglish::Writable as string
.Translate
Sub  TranslateToEnglish::Translate()
取得
True なら、翻訳する方向を逆に設定します。
EnglishTextPath から NotEnglishTextPath に翻訳します。
デフォルトは False です。
出力ファイルのパス。
AppKey.NewWritable に指定してください。
翻訳を実行します。
Property  TranslateToEnglish::c.E_NotEnglishChar as integer
翻訳後も英文字以外の文字が残っていたときのエラーコード。
.Reverse が呼び出されたときは、このエラーは発生しません。
.NotEnglishTextPath
.EnglishTextPath
Property  TranslateToEnglish::EnglishTextPath as string
英語のテキスト・ファイルのパス。
NotEnglishTextPath と同じパスを指定できます。
new_TranslateToEnglish を呼び出したら、翻訳 CSV ファイルに書かれたパスが格納されます。
このとき、翻訳 CSV ファイルに書かれた環境変数は展開されます。
.Translate を呼び出す前に変更することができます。
英語以外のテキスト・ファイルのパス。
new_TranslateToEnglish を呼び出したら、翻訳 CSV ファイルに書かれたパスが格納されます。
このとき、翻訳 CSV ファイルに書かれた環境変数は展開されます。
.Translate を呼び出す前に変更することができます。
Property  TranslateToEnglish::NotEnglishTextPath as string
.DictionaryCsvPath
Property  TranslateToEnglish::DictionaryCsvPath as string
CSV 形式の辞書ファイルのパス。
new_TranslateToEnglish に指定した引数の値と同じです。
廃止
  cd  g_fs.GetParentFolderName( WScript.ScriptFullName )
  Dim  trs, tr, folder, fnames(), fname, w_, step_path, b

  set_ "folder_jp", "C:\FolderA"
  set_ "folder_en", GetFullPath( "..\folder_en", WScript.ScriptFullName )

  echo_line
  echo  "コメントを英訳します"
  echo  "From: "+ GetVar( "folder_jp" )
  echo  "To:   "+ GetVar( "folder_en" )
  pause


  '//=== 翻訳 CSV ファイルを集める
  Set trs = new ArrayClass
  ExpandWildcard  GetVar( "folder_en" ) +"\*.trans.csv", F_File or F_SubFolder, folder, fnames
  For Each fname in fnames
    step_path = fname : CutLastOf  step_path, ".trans.csv", Empty
    set_ "step", step_path

    trs.Add  new_TranslateToEnglish( folder +"\"+ fname )
  Next


  '//=== 翻訳する。 ただし、翻訳済みファイルがあるとき(英文字以外が無く、新しいとき)は処理しない
  For Each tr  In trs.Items
    b = MakeRule_compare( tr.EnglishTextPath, tr.NotEnglishTextPath )
    If not b Then  b = ( GetLineNumsExistNotEnglighChar( tr.EnglishTextPath, Empty ) > 0 )
    If b Then
      Set w_=AppKey.NewWritable( tr.Writable ).Enable()
      tr.Translate
    End If
  Next
%folder_jp%\%step%, %folder_en%\%step%
日本語, Japanese
翻訳ファイル *.trans.csv を、変換対象のフォルダーと同じ構成で配置して、翻訳します。
翻訳ファイル *.trans.csv
廃止
Function  GetLineNumsExistNotEnglighChar( Path as string, out_LineNums as Array of integer ) as integer
テキスト・ファイルの中に、英文字以外の文字が含まれる行番号の配列を取得します。
【引数】
Path
out_LineNums
テキスト・ファイルのパス
(出力) 英文字以外の文字が含まれる行番号の配列、Empty 指定可
ToolsLib.vbs
モジュール・ファイル:
関連
(src)
返り値
英文字以外の文字が含まれる行数
Set tr = new_TranslateToEnglish( "Text1.txt.trans.csv" )
If GetLineNumsExistNotEnglighChar( tr.EnglishTextPath, Empty ) > 0 Then  ...
GetLineNumsExistNotEnglighChar  "Text1.txt", line_nums  '//[out] line_nums
For Each i  In line_nums
    echo  i
Next
日本語(文字コード256以上)を 2文字として文字数を返します。
サンプル
サンプル
Function  CheckEnglishOnly( CheckFolderPath as string, SettingPath as string )
    as ArrayClass of CheckEnglishOnlyFound
テキスト・ファイルの中に、英文字以外の文字が含まれるファイルを一覧します。
【引数】
CheckFolderPath
SettingPath
調べるフォルダのパス
設定ファイルのパス。または Empty
ToolsLib.vbs
モジュール・ファイル:
返り値
英文字以外の文字が含まれるファイルの情報
    Set founds = CheckEnglishOnly( "FolderA", "SettingForCheckEnglish.ini" )

    For Each file  In founds.Items
        For Each found  In file.NotEnglishItems.Items
            echo  file.Path +"("& found.LineNum  &"): "+ found.NotEnglishText
        Next
    Next

    If founds.Count >= 1 Then  Error
テスト
実行ファイル版、設定ファイルの例
関連
簡易版
scriptlib フォルダーをチェックする
→ 3.CheckNotEnglish フォルダー
→ T_CheckEnglishOnly.vbs # [T_CheckEnglishOnly]
ソース
コマンド・プロンプト版
→ ToolsLib.vbs # [CheckEnglishOnly]
設定ファイルに下記が記述されていないときは、上記の CheckEnglishOnly 関数呼び
出しでエラーになり、続きを実行しません。
[CheckEnglishOnlyVbs]
IsRaiseError = False
サンプル
サンプル
MakeSettingForCheckEnglish  "SettingForCheckEnglish.ini", Array( "Sample.trans" )
Sub  MakeSettingForCheckEnglish( CheckEnglishOnlyFilePath as string,
    TranslateFilePaths as array of string )
の対象外となるファイルの一覧を翻訳ファイル(*.trans)から作成します。
【引数】
CheckEnglishOnlyFilePath
TranslateFilePaths
ファイルの一覧が書かれる出力ファイルのパス
翻訳ファイルのパスの配列
関連
テスト
→ ToolLib.vbs # [MakeSettingForCheckEnglish]
サンプル
ソース
→ T_CheckEnglishOnly.vbs # [T_MakeSettingForCheckEnglish]
[CheckEnglishOnlyExe]

;// From "sample.trans" file
ExceptFile = Sample1.txt
ExceptFile = ..\Sample2.txt
<?xml version="1.0" encoding="UTF-16"?>
<Translate>
<File>Sample1.txt</File>
<File>..\Sample2.txt</File>
<T><JP>日本語</JP><EN>Japanese</EN></T>
<T><JP>英語</JP><EN>English</EN></T>
</Translate>
VBScript
  Dim  zip1, sub_fo1, step_paths, step_path, target_root, work_root

  '//=== convert binary file emulated
  zip1 = work_root +"\converted_files"
  unzip  "converted_files.zip", zip1, Empty

  sub_fo1 = "target"
  step_paths = Array( sub_fo1+"\file1.bin", sub_fo1+"\file2.bin" )
  For Each step_path  In step_paths
    ConvertBinaryEmulated  target_root +"\"+ step_path, Empty, False, _
                           zip1+"\src\"+step_path, zip1+"\dst\"+step_path
  Next
  del  zip1
書きかけ
(src)
その他
-
指定のタグで囲まれたテキストを置き換えます
複数のファイルの中の複数の単語(文字列)を一度に置き換えます。
旧仕様
vbslib のテンポラリ フォルダーの場所の例: (Windows Vista/7 のとき)
C:\Users\user1\AppData\Local\Temp\Report
vbslib を使うと、PC の内臓 HDD (OSが指定するテンポラリ・フォルダの中の Report フォルダ)
に、一時ファイルを作成することがあります。
PCを借りているときは情報漏えいに注意してください。
テンポラリ フォルダーの設定は、
関数を作成することで変更できます。
テンポラリ フォルダーを削除するときは、
ゴミ箱にも一時ファイルが格納されることがあります。
ごみ箱を空にしてください。
C:\Documents and Settings\user1\Local Settings\Temp\Report
上記フォルダーに、日付を表すフォルダーを作成し、2日前のフォルダーは
を呼び出したときに削除されます。
%USERPROFILE%\AppData\Local\Temp\Report
Function  GetTempPath( BasePath as string ) as string
の中のファイルやフォルダのパスを返します。
  Dim  f, path
  Dim  c : Set c = g_VBS_Lib

  path = GetTempPath( "DataA_*.xml" )
  Set f = OpenForWrite( path, c.Unicode )
  f.WriteLine  "<sample/>"
  f = Empty
  start  path
サンプル:
サンプル・ファイルパス: (Windows Vista のとき)
C:\Users\user1\AppData\Local\Temp\Report\090401\DataA_090401_1300_1.xml
BasePath 引数は、テンポラリ・フォルダからの相対パスになり、* はタイムスタンプと
識別番号になります。 ? は識別番号になります。 存在するファイルパスにならない
ように調整され、常に新しいファイルを作成します。 同時に保存期間を超えたファイル
やフォルダを削除します。(起動したプロセスで初めてテンポラリ・フォルダにファイル
を作成するとき、および g_TempPath= Empty のときのみ)
DataA_*.xml
c.Unicode
<sample/>
(src)
  start  CreateFile( "*.xml", obj.xml )
GetTempPath
サンプル:  obj の xml プロパティを、テンポラリファイルに出力して開きます。
obj
にワイルドカードを指定すれば、テンポラリ・フォルダにファイルを作る
ので、簡単にテキストファイルや XML ファイルを作成できます。
ファイルパスは、環境変数 TEMP の値を使っています。 上段は * 、下段は ? を使ったとき。
C:\Users\user1\AppData\Local\Temp\Report\090401\DataA_1.xml
【引数】
BasePath
返り値
ファイル名のテンプレート。 * または ? を含んでもよい
テンポラリ・フォルダの中のファイルパス
BasePath に、* または ? を含んでいる場合は、ファイルまたはフォルダが存在
しないパスに変換して返します。
本関数を呼び出すと、テンポラリ・フォルダに作成した2日以上前のファイルを削除
します。 このとき、ファイルがロックされていると再試行を繰り返して、最終的に
エラーになります。
関連
デスクトップのフル・パスを返す。
フル・パスを返す。
相対パスを返す。
親フォルダのフル・パスを返す。
フル・パスかどうかを返します。
ファイルパスの最後文字列を追加します。
参考
関連
パスの辞書(集合)
ファイルのパスか、ファイルの内容に相当する文字列の抽象。
Function  DesktopPath() as string
デスクトップのフル・パスを返します。
(src)
Function  GetFullPath( StepPath as string, BasePath as string ) as string
フル・パスを返します。
【引数】
StepPath
BasePath
返り値と同じファイルの相対パス
基準フォルダのフル・パス、Empty でカレントフォルダ
返り値
StepPath と同じファイルのフル・パス
g_fs.GetAbsolutePathName は、StepPath に * が入っていると、ピリオドに
置き換わってしまいますが、GetFullPath では発生しません。
  path2 = GetFullPath( Path, BaseFolderPath )
  path2 = GetFullPath( "..\"+ Path, BaseFilePath )
  path2 = GetFullPath( Path, GetParentFullPath( BaseFilePath ) )
BasePath をファイルパスにしたときは、StepPath を1つ親にしてください。
GetFullPath(    "file.txt", "C:\folder1" ) =
GetFullPath( "..\file.txt", "C:\folder1\file2.txt" )
テスト
関連
→ T_Path.vbs # [T_GetFullPath]
親フォルダー、または、その親フォルダー … と探すときは、"..." とピリオドを
3つ並べてください。 ただし、スクリプトを記述できるときは、
GetFullPath( "...\file.txt", "C:\folder1\sub" )
上記の返り値は、C:\folder1\sub\file.txt 、C:\folder1\file.txt 、C:\file.txt
のいずれかになります。 または、E_PathNotFound エラーになります。
を呼ぶほうが可読性が高まります。
サンプル
参考
→ vbslib.vbs
ソース
→ vbslib_mini.vbs
大文字小文字をファイル名に合わせます
テキストファイルの中をフルパスにします
Path の最後を区切り記号にします
Scripting.FileSystemObject によるフル・パス
  IsEmpty( GetFullPath( Empty, BaseFolderPath )
StepPath = Empty なら、Empty が返ります。
Function  GetStepPath( FullPath as string, BasePath as string ) as string
相対パスを返します。
【引数】
FullPath
BasePath
返り値が指すファイルと同じファイルのフル・パス
基準フォルダーのフル・パス
返り値
FullPath 引数が指すファイルと同じファイルの相対パス
テスト
→ T_Path.vbs
→ vbslib.vbs
ソース
T_GetStepPath
Assert  NormalizePath( "C:\folder\..\a" ) = "C:\a"
Assert  NormalizePath( "C:\..\a" ) = "C:\..\a"
Function  NormalizePath( Path as string ) as string
ファイル・パスの ".." や "." をなくします。
【引数】
Path
返り値
変換する前のファイル・パス
変換した後のファイル・パス
サンプル
ソース
→ vbslib.vbs
→ T_Path.vbs
テスト
T_NormalizePath
Assert  NormalizePath( "C:\folder\.\a" ) = "C:\folder\a"
Assert  NormalizePath( "C:\folder\a\" ) = "C:\folder\a"
Assert  NormalizePath( "C:\" ) = "C:\"
Assert  NormalizePath( "http://example.com/folder/" ) = "http://example.com/folder/"
末尾の \ はカットされますが、/ はカットされません。
Function  GetCaseSensitiveFullPath( StepPath as string ) as string
フル・パスを返します。 大文字小文字はファイル名に合わせます。
【引数】
StepPath
返り値と同じファイルの相対パス、または、フルパス
大文字小文字をファイル名に合わせたフル・パス
返り値
    path = GetCaseSensitiveFullPath( "file.txt" )
    Assert  path = "C:\Folder\File.txt"
サンプル
file.txt に該当するファイルのフルパスが、C:\Folder\File.txt のとき。
本関数は、ファイルシステムにアクセスして、ファイル名を調べます。
ファイルが存在しないときは、カレント フォルダーを基準とした相対パスとして、
フルパスを返します。
テスト
関連
→ T_Path.vbs # [T_GetFullPath]
ソース
→ vbslib.vbs
Function  IsFullPath( Path as string ) as boolen
Path  に指定したパスがフル・パスかどうかを返します。
(src)
テスト
→ T_Path.vbs # [T_IsFullPath]
Function  GetRootSeparatorPosition( Path as string ) as integer
Path  に入っているルート・フォルダーの位置を返します。
【引数】
Path
ファイルなどのパス
返り値
ルート・フォルダーの位置、0=相対パス
Assert  GetRootSeparatorPosition( "C:\File" ) = 3
Assert  GetRootSeparatorPosition( "\File" ) = 1
Assert  GetRootSeparatorPosition( "File" ) = 0
Assert  GetRootSeparatorPosition( "..\File" ) = 0
Assert  GetRootSeparatorPosition( "\\PC01\Folder\File" ) = 14
Assert  GetRootSeparatorPosition( "http://www.example.com/" ) = 23
サンプル
ソース
→ vbslib.vbs
→ T_Path.vbs
テスト
T_GetRootSeparatorPosition