DR.eye(译典通)也是vnr内置的一个离线翻译,支持日中,英中互译。参考vnr的调用方式: https://github.com/Dangetsu/vnr/blob/7d0d80f298dc913d29270607fb26318026573f97/Frameworks/Sakura/py/libs/dreye/transcom.py

以日中翻译为例

        const string DREYE_DLL = @"D:\DR.eye\DreyeMT\SDK\bin\TransCOM.dll";
        const int EC_DAT = 1;   //英中
        const int CE_DAT = 2;   //中英
        const int CJ_DAT = 3;   //中日
        const int JC_DAT = 10;  //日中

        [DllImport(DREYE_DLL, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int MTInitCJ(int dat_index);

        [DllImport(DREYE_DLL, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int MTEndCJ();

        [DllImport(DREYE_DLL, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int TranTextFlowCJ(
            byte[] src,
            byte[] dest,
            int dest_size,
            int dat_index
            );

英中则是调用TransCOMCE.dll,函数名分别为MTInitEC,MTEndEC,TranTextFlowCJ。

static void Main(string[] args)
        {
            Encoding shiftjis = Encoding.GetEncoding("shift-jis"); //英中utf-8
            Encoding gbk = Encoding.GetEncoding("gbk");
            string workingDirectory = Path.GetDirectoryName(DREYE_DLL);
            Directory.SetCurrentDirectory(workingDirectory);
            MTInitCJ(JC_DAT); //返回值为-255
            byte[] src = shiftjis.GetBytes("人を信じよ、しかしその百倍も自らを信じよ");
            byte[] buffer = new byte[3000];
            TranTextFlowCJ(src,buffer,3000, JC_DAT);
            Console.WriteLine(gbk.GetString(buffer));
            MTEndCJ();
        }

翻译结果为:

Directory.SetCurrentDirectory(workingDirectory);的作用是设定工作目录,如果不写,可以看到找不到资源文件,翻译结果为乱码


一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。