/// <summary>Saves the strings for the selected entities into a new file.</summary> /// <param name="parts">The parts to export the strings from.</param> /// <param name="assemblies">The mod assemblies to export teh strinsg from.</param> void GuiActionExportStrings(IEnumerable <PartsRecord> parts, IEnumerable <AssemblyRecord> assemblies) { var partsLocs = parts .SelectMany(x => x.parts) .Select(Extractor.EmitItemsForPart) .SelectMany(x => x) .ToList(); var modulesLocs = assemblies .SelectMany(x => x.assembly.GetTypes()) .Select(Extractor.EmitItemsForType) .SelectMany(x => x) .ToList(); Debug.LogWarningFormat("Export {0} parts strings and {1} modules strings", partsLocs.Count, modulesLocs.Count); var locItems = partsLocs.Union(modulesLocs); var fileName = "strings.cfg"; if (assemblies.Count() == 1) { fileName = assemblies.First().assembly.GetName().Name + "_" + fileName; } var filePath = KspPaths.GetModsDataFilePath(this, "Lang/" + fileName); Directory.CreateDirectory(Path.GetDirectoryName(filePath)); ConfigStore.WriteLocItems(locItems, Localizer.CurrentLanguage, filePath); Debug.LogWarningFormat("Strings are written into: {0}", filePath); ShowCompletionDialog(StringsExportedDlgTitle, FileSavedTxt.Format(filePath)); }
/// <summary> /// Patches the part configs so that they refer the tags for the localizable fileds, and saves the /// modified fiels in the export location. /// </summary> /// <remarks></remarks> /// <param name="parts">The parts to patch.</param> void GuiExportPartConfigs(IEnumerable <PartsRecord> parts) { var exportParts = parts.SelectMany(x => x.parts); var exportPath = KspPaths.GetModsDataFilePath(this, "Parts/"); foreach (var part in exportParts) { var config = ConfigStore.LoadConfigWithComments( part.configFileFullName, localizeValues: false); if (config == null) { Debug.LogErrorFormat( "Cannot load config file for part {0}: {1}", part.name, part.configFileFullName); continue; } var partNode = config.GetNode("PART"); foreach (var fieldName in Extractor.localizablePartFields) { var field = partNode.values.Cast <ConfigNode.Value>() .FirstOrDefault(x => x.name == fieldName); if (field == null) { Debug.LogWarningFormat("Field '{0}' is not found in the part {1} config", fieldName, part.name); continue; } if (field.value.StartsWith("#", StringComparison.Ordinal)) { continue; // It's already localized. } var locTag = Extractor.MakePartFieldLocalizationTag(part.name, fieldName); field.comment = locTag + " = " + field.value; field.value = locTag; } var tgtPath = exportPath + part.name.Replace(".", "_") + ".cfg"; Debug.LogWarningFormat("Saving patched part config into: {0}", tgtPath); ConfigStore.SaveConfigWithComments(config, tgtPath); } ShowCompletionDialog( ConfigSavedDlgTitle, ConfigsSavedInFolderTxt.Format(exportParts.Count(), exportPath)); }
/// <summary>Saves the strings for the selected entities into a new file.</summary> /// <param name="parts">The parts to export the strings from.</param> /// <param name="assemblies">The mod assemblies to export teh strinsg from.</param> void GuiActionExportStrings(IEnumerable <PartsRecord> parts, IEnumerable <AssemblyRecord> assemblies) { var partsLocs = parts .SelectMany(x => x.parts) .Select(Extractor.EmitItemsForPart) .SelectMany(x => x) .ToList(); var modulesLocs = assemblies .SelectMany(x => x.assembly.GetTypes()) .Select(Extractor.EmitItemsForType) .SelectMany(x => x) .ToList(); Debug.LogWarningFormat("Export {0} parts strings and {1} modules strings", partsLocs.Count, modulesLocs.Count); var locItems = partsLocs.Union(modulesLocs); var filename = KspPaths.GetModsDataFilePath(this, "export.cfg", createMissingDirs: true); ConfigStore.WriteLocItems(locItems, Localizer.CurrentLanguage, filename); Debug.LogWarningFormat("Strings are written into: {0}", filename); }