55import * as assert from 'assert' ;
66import * as _ from 'lodash' ;
77import { PontFileManager } from './PontFileManager' ;
8- import { TRANSLATE_DICT_NAME } from '../constants' ;
98import { IBaiduTranslateConfig } from '../types/pontConfig' ;
109import { youdao , baidu , google } from 'translation.js' ;
1110import pinyin from './pinyin' ;
@@ -48,8 +47,8 @@ const engines = [
4847export const dict : { [ rootDir : string ] : { [ cn : string ] : string } } = { } ;
4948const dicPath : { [ rootDir : string ] : string } = { } ;
5049
51- function init ( rootDir : string ) {
52- dicPath [ rootDir ] = PontFileManager . getLocalFilePath ( rootDir , TRANSLATE_DICT_NAME ) ;
50+ function init ( rootDir : string , translatePath : string ) {
51+ dicPath [ rootDir ] = PontFileManager . getLocalFilePath ( rootDir , null , translatePath ) ;
5352 const localDict = PontFileManager . loadFile ( dicPath [ rootDir ] ) ;
5453
5554 if ( localDict ) {
@@ -85,12 +84,13 @@ function startCaseClassName(result) {
8584
8685export async function translate (
8786 rootDir ,
87+ translatePath ,
8888 baiduTranslateConfigs : IBaiduTranslateConfig [ ] ,
8989 text : string ,
9090 engineIndex = 0
9191) {
9292 if ( ! dicPath [ rootDir ] ) {
93- init ( rootDir ) ;
93+ init ( rootDir , translatePath ) ;
9494 }
9595
9696 if ( dict [ rootDir ] ?. [ text ] ) {
@@ -140,14 +140,15 @@ export async function translate(
140140 return enKey ;
141141 } catch ( err ) {
142142 console . error ( `translateEngine:${ translateEngine . name } text:${ text } err:${ err } ` ) ;
143- return translate ( rootDir , baiduTranslateConfigs , text , index + 1 ) ;
143+ return translate ( rootDir , translatePath , baiduTranslateConfigs , text , index + 1 ) ;
144144 }
145145}
146146
147147/** 翻译中文类名等 */
148148export async function translateChinese (
149149 jsonString : string ,
150150 rootDir : string ,
151+ translatePath : string ,
151152 baiduTranslateConfigs ?: IBaiduTranslateConfig [ ]
152153) {
153154 let retString = jsonString ;
@@ -168,7 +169,9 @@ export async function translateChinese(
168169 // 例如: 请求参数vo, 请求参数, 替换时先替换 请求参数vo, 后替换请求参数
169170 chineseKeyCollect . sort ( ( pre , next ) => next . length - pre . length ) ;
170171
171- let result = await Promise . all ( chineseKeyCollect . map ( ( text ) => translate ( rootDir , baiduTranslateConfigs , text ) ) ) ;
172+ let result = await Promise . all (
173+ chineseKeyCollect . map ( ( text ) => translate ( rootDir , translatePath , baiduTranslateConfigs , text ) )
174+ ) ;
172175 // const normalizeRegStr = (str: string) => str.replace(/(\W)/g, '$1');
173176 const toRegStr = ( str ) => str . replace ( / ( \W ) / g, '\\$1' ) ;
174177 result . forEach ( ( enKey : string , index ) => {
0 commit comments