You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importfsfrom'fs';importpathfrom'path';asyncfunctionreadFiles(dir: string,originFileName: string,targetFileName: string,alsoReplaceExistFile: boolean=false,){constfiles=fs.readdirSync(dir);awaitPromise.all(files.map(async(filePath)=>{// if this is a folder, Recursive call it to handle the files from this folder;constisFolder=fs.lstatSync(path.resolve(dir,filePath)).isDirectory();if(isFolder){awaitreadFiles(path.resolve(dir,filePath),originFileName,targetFileName,alsoReplaceExistFile,);// 是否存在被拷贝的文件 && (是否要忽略已存在的文件 || 要生成的文件是否已存在(存在就不会覆盖)}elseif(newRegExp(originFileName).test(filePath.toString())&&(alsoReplaceExistFile||!fs.existsSync(path.resolve(dir,targetFileName)))){fs.readFile(path.resolve(dir,filePath),'utf8',(err,content)=>{if(err)throwerr;fs.writeFile(`${dir}/${targetFileName}`,content,(err)=>{if(err)throwerr;});});}}),);}export{readFiles};// use with gulpgulp.task('copy-en-AU-as-en-GB',async()=>{awaitreadFiles(path.resolve(__dirname,''),'en-AU.ts','en-GB.ts');});
PM给的userstory:
也就是我们集成在Zendesk(一个产品)上的应用需要支持香港版的翻译(用户在浏览器选择香港语言,我们的应用的语言需要跟着变成香港的),
然而台湾和香港都是繁体,所以在每个翻译文件夹直接拷贝已有的台湾翻译内容穿件新的zh-HK文件即可,作为程序员,手动去一个一个创建文件是不可能的,一辈都不可能的😂所以写个脚本解放双手。
代码:
完成的源码repo地址
The text was updated successfully, but these errors were encountered: