public ActionResult Layout(string path_po) { Dictionary <string, string> dic = GetLanPo(path_po); List <Po> poList = new List <Po>(); foreach (var key in dic.Keys) { poList.Add(new Po(key, dic[key])); } // 获取最大长度 int max = poList.Select(c => c.msgid).Max(c => c.Length); List <Po> res = new List <Po>(); // 依次取出 for (int i = 1; i <= max; i++) { List <Po> temp = poList.Where(c => c.msgid.Length == i).OrderBy(c => c.msgid).ToList(); if (temp != null && temp.Count > 0) { res.AddRange(temp); } } foreach (var item in res) { // 单词长度小于三个的时候,首字母大写 string con = $"msgid \"{item.msgid}\"\nmsgstr \"{Utils.StrToUpper(item.msgstr.Trim(), 2)}\"\n\n"; FileAction.AppendStr(path_po + "_out", con); } FileAction.AppendStr(path_po + "_out", $"共{res.Count}条!"); return(Success("排版完成!", "Index", false)); }
public void GetCode(int type) { DT_DataItem _DataItem = _DataItemService.FindEntity(type); List <DT_DataItemDetail> list = _DataItemDetailService.LoadEntities(c => c.DataItemId == type).ToList(); string enumType = "D:\\Code\\enumType.cs"; string classData = "D:\\Code\\classData.cs"; // 开头 FileAction.AppendStr(enumType, $" #region {_DataItem.ItemName}\n\n"); FileAction.AppendStr(classData, $" #region {_DataItem.ItemName}\n\n"); // 父级 DT_DataItemDetail begin = new DT_DataItemDetail(); begin.Id = _DataItem.Id; begin.ItemCode = _DataItem.ItemCode; begin.ByName = _DataItem.ByName; begin.ItemName = _DataItem.ItemName; // 添加父级 FileAction.AppendStr(enumType, GetEnumType(begin)); FileAction.AppendStr(classData, GetClassData(begin, "GetDataItem")); // 添加详情 foreach (var item in list) { FileAction.AppendStr(enumType, GetEnumType(item)); FileAction.AppendStr(classData, GetClassData(item)); } // 结束 FileAction.AppendStr(enumType, $" #endregion\n\n"); FileAction.AppendStr(classData, $" #endregion\n\n"); }
public void SaveLanJs(Dictionary <string, string> dic) { StringBuilder builder = new StringBuilder(); builder.Append("var lang = '';\n"); builder.Append("/**\n"); builder.Append("* 获取指定名称的cookie的值\n"); builder.Append("* @param {string} objName\n"); builder.Append("*/\n"); builder.Append("function getCookie(objName) {\n"); builder.Append(" var arrStr = document.cookie.split('; ');\n"); builder.Append(" for (var i = 0; i < arrStr.length; i++) {\n"); builder.Append(" var temp = arrStr[i].split('=');\n"); builder.Append(" if (temp[0] == objName) return unescape(temp[1]);\n"); builder.Append(" }\n"); builder.Append(" return '';\n"); builder.Append("}\n"); builder.Append("\n\n"); builder.Append("var CN = {\n"); builder.Append(" GetLang: function (name) {\n"); builder.Append(" // 判断中文英文\n"); builder.Append(" if (lang == '')\n"); builder.Append(" lang = getCookie('culture');\n"); builder.Append(" if (lang != 'zh-CN' || lang != 'en')\n"); builder.Append(" lang = 'zh-CN';\n"); builder.Append("\n"); builder.Append(" if (lang == 'zh-CN')\n"); builder.Append(" return name;\n"); builder.Append(" var str = '';\n"); builder.Append(" switch (name) { \n"); foreach (var item in dic.Keys) { string key = DataCheck.RepLanguage(item).Replace("'", "\\\'"); string val = DataCheck.RepLanguage(dic[item]).Replace("'", "\\\'"); builder.Append($" case '{key}': str = '{val}'; break;\n"); } builder.Append($" default : str = name; break;\n"); builder.Append(" }\n"); builder.Append(" return str;\n"); builder.Append(" }\n"); builder.Append("}\n"); FileAction.AppendStr("F:\\Lang.js", builder.ToString()); }
public ActionResult RepFile(string path_js, string path_po, string path_out) { Stopwatch watch = new Stopwatch(); watch.Start(); #region 文件数据读取 List <FileInfo> JSFileList = FileAction.ReadDir(path_js, "js"); if (JSFileList == null || JSFileList.Count <= 0) { return(Error("不存在此目录,或目录下无对应文件!", "Index", false)); } #endregion // 赋予必要参数 RepFilePara.dic = GetLanPo(path_po); RepFilePara.path = path_js; RepFilePara.outpath = path_out; RepFilePara.errInfo = new List <string>(); Thread thread; // 循环所有文件 foreach (var item in JSFileList) { RepFilePara para = new RepFilePara { file = item }; // 每一个文件,开辟一个线程 thread = new Thread(new ThreadStart(para.RepFile)); thread.Start(); } // 输出日志信息,保存为文件 StringBuilder builder = new StringBuilder(); foreach (var item in RepFilePara.errInfo) { builder.Append(item + "\n"); } FileAction.AppendStr(path_out + "\\log.txt", builder.ToString()); watch.Stop(); return(Success($"导出成功!开启线程{JSFileList.Count}个," + $"用时:{watch.ElapsedMilliseconds * 1.0 / 1000 / 60}分钟", "Index", false)); }
public void RepFile() { try { List <string> list = FileAction.ReadToArr(file.FullName); string p = file.FullName.Replace(path, outpath); // 匹配注释正则 string regNotes = "([/]{2,}|[*]+).*"; // 匹配中文正则 string regChinese = @"([\u4e00-\u9fa5]{1,}[\s,,‘“;(()):、:.&\\-a-zA-Z0-9\u4e00-\u9fa5]{0,}[。”’!0-9\u4e00-\u9fa5]{1,})|([\u4e00-\u9fa5]{1})"; int index = 0; foreach (var item in list) { index++; // 去掉注释 string str = DataCheck.RepStr(item.Trim(), regNotes, ""); //是否包含中文 if (!DataCheck.CheckReg(str, regChinese)) { FileAction.AppendStr(p, item + "\n"); } else { // 取出中文 string[] strArr = DataCheck.GetRegStrArr(str, regChinese); string temp = str; string get = ""; // 在语言包中寻找匹配 foreach (var chinese in strArr) { // 如果没有包含汉字,查找下一个 if (!DataCheck.CheckReg(chinese, "[\u4e00-\u9fa5]+")) { continue; } // 若语言包中存在对应中文,直接替换 if (dic.ContainsKey(chinese)) { get = dic[chinese]; temp = temp.Replace(chinese, DataCheck.RepLanguage(dic[chinese], false)); errInfo.Add($"{chinese}\t{dic[chinese]}\t{file.FullName}"); } // 否则,去寻找最类似的中文 else { // 获取极限长度 int min = chinese.Length - 2; int max = chinese.Length + 2; // 判断是否替换 bool bl = false; // 循环字典 foreach (var key in dic.Keys) { // 超出极限长度,则跳出 if (max < key.Length || key.Length < min) { continue; } // 若符合极限长度,且包含当前文字 if (key.Contains(chinese)) { // 进行替换 temp = temp.Replace(chinese, DataCheck.RepLanguage(dic[key], false)); errInfo.Insert(0, $"^{chinese}:{index}行\t{dic[key]}\t{file.FullName}"); bl = true; } } if (!bl) { errInfo.Insert(0, $"^^{chinese}:{index}行\t{file.FullName}"); } } } // 将当前行写入文件 FileAction.AppendStr(p, item.Replace(str, temp) + "\n"); } } } catch (Exception e) { errInfo.Add("错误:" + file.FullName + "\t" + e.Message); } }
/// <summary> /// 写入日志文本 /// </summary> /// <param name="context">内容</param> public void SetLogTxt(string context) { string path = Path.GetFullPath($"../../LogTxt/{DateTime.Now.ToString("yyyy-MM-dd")}.txt"); FileAction.AppendStr(path, context); }
private void bt_Start_Click(object sender, EventArgs e) { //CheckBox temp; //Crawler crawler = new Crawler(); //crawler.OnCompleted += Crawler_OnCompleted; //crawler.OnError += Crawler_OnError; //foreach (Control item in pl_UrlList.Controls) { // if (item is CheckBox) { // temp = item as CheckBox; // if (temp.Checked) { // SetLog("开始爬取:" + temp.Text, Color.Black); // crawler.Start(temp.Tag + "", "<a[^>]+?href=[\"']?http://3g.163.com/all/article/([^\"']+)[\"']?[^>]*>(.+?)</a>").Wait(); // } // temp.Enabled = true; // } //} //SetLog("结束!", Color.OrangeRed); #region 翻译 string ReadPath = @"F:\01.Porject\NanNing\050Coding\New_NaNing_SSC\WebFront\App_Data\Localization\en\orchard.module.po"; string SavePath = @"F:\orchard.module.po"; string content = FileAction.ReadToStr(ReadPath); string reg = "msgid \"(?<msgid>.*)\" \r\nmsgstr \"(?<msgstr>.*)\""; string[] strArr = DataCheck.GetRegStrArr(content, reg); Translate translate = new Translate("20171116000095832", "PuVyBlMqMOOjqfks4GJ7"); // 记录运行时间 Stopwatch watch = new Stopwatch(); int con = 0; foreach (var str in strArr) { SetLog("开始翻译!", Color.Black); watch.Start(); MatchCollection res = Regex.Matches(str, reg, RegexOptions.IgnoreCase); foreach (Match item in res) { // BaiduTransAPI transAPI = translate.BaiduTranslate(item.Groups["msgid"].Value, "zh", "en"); string context = "" + "msgid \"" + item.Groups["msgid"].Value + "\"\n" + "msgstr \"" + Utils.StrToUpper(item.Groups["msgstr"].Value, 2) + "\"\n\n"; FileAction.AppendStr(SavePath, context); } SetLog("翻译结束,用时:" + watch.ElapsedMilliseconds * 0.1 / 1000 + " s,第" + (++con) + "条", Color.Brown); watch.Stop(); } #endregion bt_Start.Enabled = true; }