static RecyclingData() { LanguageWrapper.SetDefault(recycleTextID, recycleText); LanguageWrapper.SetDefault(recycleTooltipID, recycleTooltip); LanguageWrapper.SetDefault(nonRecyclableTextID, nonRecyclableText); LanguageWrapper.SetDefault(nonRecyclableTooltipID, nonRecyclableTooltip); }
private Dictionary <int, LanguageWrapper> ParseAutoGenerateLanguageExcel(SheetData sheet) { Dictionary <int, LanguageWrapper> cacheLanguages = new Dictionary <int, LanguageWrapper>(); // 遍历所有行 foreach (var table in sheet.Tables) { // 获取格子数值 int firsetCellNum = table.Row.FirstCellNum; string cell1Value = table.GetCellValue(firsetCellNum); //id string cell2Value = table.GetCellValue(++firsetCellNum); //source string cell3Value = table.GetCellValue(++firsetCellNum); //language int hashCode = Convert.ToInt32(cell1Value); LanguageWrapper wrapper = new LanguageWrapper(); wrapper.Source = cell2Value; wrapper.Content = cell3Value; cacheLanguages.Add(hashCode, wrapper); } // 检测字典里是否有重复值 var duplicateValues = cacheLanguages.GroupBy(x => x.Value.Content).Where(x => x.Count() > 1); foreach (var item in duplicateValues) { throw new Exception($"多语言总表发现重复值:{item.Key}"); } return(cacheLanguages); }
public void ConfigureServices(IServiceCollection services) { services.AddSingleton <ICultureProvider, CultureProvider>(); services.AddSingleton <IStringLocalizerFactory, StringLocalizerFactory>(); GetServiceProvider = services.BuildServiceProvider(); IHostingEnvironment environment = GetServiceProvider.GetRequiredService <IHostingEnvironment>(); InstalledCultures = LanguageWrapper.GetInstalledLanguages(environment.ContentRootPath); List <CultureInfo> cultures = new List <CultureInfo>(); for (int i = 0; i < InstalledCultures.Length; i++) { cultures.Add(new CultureInfo(InstalledCultures[i])); } services.Configure <RequestLocalizationOptions>( opts => { opts.DefaultRequestCulture = new RequestCulture(InstalledCultures[0]); opts.SupportedCultures = cultures; opts.SupportedUICultures = cultures; }); }
private static void LoadRecyclingTooltip(TechType recyclingTech) { TooltipFactoryWrapper.RegisterTech(recyclingTech); var lang = Language.main; if (lang == null) { return; } if (IsBlackListed(recyclingTech)) { var errorText = lang.Get(nonRecyclableTooltipID); LanguageWrapper.SetDefault("Tooltip_" + recyclingTech.AsString(), errorText); return; } var data = CraftData.Get(recyclingTech); if (data == null) { return; } var ings = new Dictionary <TechType, int>(); for (var i = 0; i < data.linkedItemCount; i++) { var item = data.GetLinkedItem(i); ings[item] = ings.ContainsKey(item) ? (ings[item] + 1) : 1; } var builder = new System.Text.StringBuilder(); foreach (var ing in ings) { builder.Append(lang.Get(ing.Key.AsString())); if (ing.Value > 1) { builder.Append(" (x"); builder.Append(ing.Value); builder.Append(')'); } builder.Append(", "); } if (builder.Length >= 2) { builder.Length -= 2; } var ingList = builder.ToString(); var tooltip = lang.Get(recycleTooltipID); var formated = StringUtil.FormatWithFallback(tooltip, recycleTooltip, ingList); LanguageWrapper.SetDefault("Tooltip_" + recyclingTech.AsString(), formated); }
/// <summary> /// 缓存多语言数据 /// </summary> public void CacheLanguage(Dictionary <int, LanguageWrapper> data) { foreach (var pair in data) { int hashCode = pair.Key; LanguageWrapper value = pair.Value; if (_cacheLanguage.ContainsKey(hashCode) == false) { _cacheLanguage.Add(hashCode, value); } } }
private void SetStrings() { if (Strings == null) { return; } foreach (var pair in Strings) { if (string.IsNullOrEmpty(pair.Value)) { Logger.Warning($"Invalid text at line '{pair.Key}' in {Path}."); continue; } var text = Config.Debug ? (ModTag + pair.Value) : pair.Value; LanguageWrapper.Set(TargetLanguage, pair.Key, text); } }
private static void ParseSingleLanguageToCache(Dictionary <int, LanguageWrapper> cacheLanguages, SheetData sheet, int cellNum) { foreach (var table in sheet.Tables) { // 获取格子内容 string cellValue = table.GetCellValue(cellNum); int hashCode = cellValue.GetHashCode(); if (cacheLanguages.ContainsKey(hashCode) == false) { LanguageWrapper wrapper = new LanguageWrapper(); wrapper.Source = sheet.FileName; wrapper.Content = cellValue; cacheLanguages.Add(hashCode, wrapper); } } }
public List <Tag> GetLocalVariables(int currPos) { List <Tag> tags = null; int funcStart = 0, funcOpenBrace = 0, funcEnd = 0; int lineNum = m_editor.Lines.FromPosition(currPos).Number; if (GetFunctionStartEnd(lineNum, ref funcStart, ref funcOpenBrace, ref funcEnd)) { int openParenPos = FindNextString(funcStart, "(", false); } else { return(null); } CtagsManagerWrapper cmw = Singleton <CtagsManagerWrapper> .Instance; //string textToHere = m_editor.GetTextToPos(funcOpenBrace + 1); LanguageWrapper lw = new LanguageWrapper(); //string scope = lw.OptimizeScope(textToHere); string localText = m_editor.GetTextChunk(funcOpenBrace, funcEnd); Tag func = cmw.FunctionFromFileLine(m_editor.Filename, lineNum, false); if (func == null) { return(null); } string signature = func.extFields["signature"]; List <Tag> localVars = lw.GetLocalVariables(localText, "", 0); List <Tag> funcVars = lw.GetLocalVariables(signature, "", 0); tags = funcVars; tags.AddRange(localVars); return(tags); }
private static void ParseListLanguageToCache(Dictionary <int, LanguageWrapper> cacheLanguages, SheetData sheet, int cellNum) { foreach (var table in sheet.Tables) { // 获取格子内容 string cellValue = table.GetCellValue(cellNum); List <string> splitValues = StringConvert.StringToStringList(cellValue, ConstDefine.StrSplitChar); for (int i = 0; i < splitValues.Count; i++) { string splitValue = splitValues[i]; int hashCode = splitValue.GetHashCode(); if (cacheLanguages.ContainsKey(hashCode) == false) { LanguageWrapper wrapper = new LanguageWrapper(); wrapper.Source = sheet.FileName; wrapper.Content = splitValue; cacheLanguages.Add(hashCode, wrapper); } } } }
private static void LoadRecyclingText(TechType originTech, TechType recyclingTech) { var lang = Language.main; if (lang == null) { return; } if (IsBlackListed(recyclingTech)) { var translation1 = lang.Get(nonRecyclableTextID); LanguageWrapper.SetDefault(recyclingTech.AsString(), translation1); return; } var techName = lang.Get(originTech.AsString()); var translation = lang.Get(recycleTextID); var formated = StringUtil.FormatWithFallback(translation, recycleText, techName); LanguageWrapper.SetDefault(recyclingTech.AsString(), formated); }
public void OnConsoleCommand_lgfind(NotificationCenter.Notification note) { if (note == null || note.data == null || note.data.Count == 0) { return; } var pattern = (string)note.data[0]; if (string.IsNullOrEmpty(pattern)) { return; } pattern = pattern.Replace('_', ' '); int maxTextSize = 128; if (note.data.Count > 1) { int.TryParse((string)note.data[1], out maxTextSize); } ErrorMessage.AddMessage($"Searching for '{pattern}'..."); var regex = pattern == "-eng" ? onlyASCIIRegex : new Regex($"{Regex.Escape(pattern)}", RegexOptions.IgnoreCase); var searchResult = LanguageWrapper.FindAll(x => regex.IsMatch(x.Value)); if (searchResult.Count > 0) { ErrorMessage.AddMessage($"Found <color=#00FF00FF>{searchResult.Count}</color> strings. Check log for details."); AGLogger.Message($"Searched '{pattern}'. Found {searchResult.Count} strings:"); ReportSearch(searchResult, maxTextSize); } else { ErrorMessage.AddMessage($"Nothing found."); AGLogger.Message($"Searched '{pattern}'. Nothing found."); } }
/// <summary> /// 创建多语言总表文件 /// </summary> public void CreateAutoGenerateLanguageFile() { try { int nextRow = 0; List <string> typeList = new List <string>() { "int", "#", "string" }; List <string> nameList = new List <string>() { "id", "#", "lang" }; List <string> flagList = new List <string>() { "C", "#", "C" }; // 创建工作簿 XSSFWorkbook workbook = new XSSFWorkbook(); // 创建Sheet页 ISheet sheet = workbook.CreateSheet($"t_{StrAutoGenerateLanguageExcelName}"); // 创建第一行 IRow firstRow = sheet.CreateRow(nextRow); for (int i = 0; i < typeList.Count; i++) { string value = typeList[i]; ICell cell = firstRow.CreateCell(i); cell.SetCellValue(value); } // 创建第二行 IRow secondRow = sheet.CreateRow(++nextRow); for (int i = 0; i < nameList.Count; i++) { string value = nameList[i]; ICell cell = secondRow.CreateCell(i); cell.SetCellValue(value); } // 创建第三行 IRow thirdRow = sheet.CreateRow(++nextRow); for (int i = 0; i < flagList.Count; i++) { string value = flagList[i]; ICell cell = thirdRow.CreateCell(i); cell.SetCellValue(value); } ICellStyle style = workbook.CreateCellStyle(); style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; //左对齐 // 创建数据行 foreach (var pair in _cacheLanguage) { int hashCode = pair.Key; LanguageWrapper wrapper = pair.Value; IRow row = sheet.CreateRow(++nextRow); int cellNum = 0; // id ICell cell1 = row.CreateCell(cellNum); cell1.SetCellValue(hashCode); cell1.CellStyle = style; // source ICell cell2 = row.CreateCell(++cellNum); cell2.SetCellValue(wrapper.Source); cell2.CellStyle = style; // language ICell cell3 = row.CreateCell(++cellNum); cell3.SetCellValue(wrapper.Content); cell3.CellStyle = style; } // 设置格式 sheet.SetColumnWidth(0, 15 * 256); //设置列宽为30个字符 sheet.SetColumnWidth(1, 30 * 256); //设置列宽为30个字符 sheet.SetColumnWidth(2, 30 * 256); //设置列宽为30个字符 // 保存Excel文件 string filePath = ExportConfig.Instance.LastOpenExcelPath + "\\" + StrAutoGenerateLanguageExcelName + ".xlsx"; using (FileStream file = new FileStream(filePath, FileMode.Create)) { workbook.Write(file); file.Close(); } // 销毁句柄 workbook.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void OnConsoleCommand_lgpatch(NotificationCenter.Notification note) { LanguageWrapper.Clear(); LanguagePatcher.Patch(); ErrorMessage.AddMessage("Language patches reloaded."); }