public static void Verify(Args.ValidateCommand cmd) { Verbose(cmd, $"Validating file '{cmd.MuiDB}' against MuiDB schema"); var muidb = new MuiDBFile(cmd.MuiDB); muidb.Validate(); if (cmd.ReFormat) { Verbose(cmd, $"Applying default format to '{cmd.MuiDB}'"); muidb.Save(); } }
public static void ImportFile(Args.ImportFileCommand cmd) { var muidb = new MuiDBFile(cmd.Muidb, MuiDBFile.OpenMode.CreateIfMissing); switch (cmd.Type.ToLowerInvariant()) { case "resx": var result = muidb.ImportResX(cmd.In, cmd.Lang); if (cmd.Verbose) { foreach (var added in result.AddedItems) { Console.WriteLine($"Added resource '{added}'"); } foreach (var updated in result.UpdatedItems) { Console.WriteLine($"Updated resource '{updated}'"); } } Console.WriteLine($"Added items: {result.AddedItems.Count}\nupdated items: {result.UpdatedItems.Count}"); break; case "xliff": var doc = new XliffParser.XlfDocument(cmd.In); var file = doc.Files.First(); Verbose(cmd, $"Adding/updating resources for language '{cmd.Lang}..."); foreach (var unit in file.TransUnits) { var id = unit.Id; if (string.Equals(id, "none")) { id = unit.Optional.Resname; } var comment = unit.Optional.Notes.Any() ? unit.Optional.Notes.First().Value : null; Verbose(cmd, $"Adding/updating resource '{id}': text='{unit.Target}', state='{unit.Optional.TargetState}'"); string translatedState; try { translatedState = StateConverter.ToMuiDB(unit.Optional.TargetState); } catch (Exception) { translatedState = StateConverter.MuiDbStates.New; Console.Error.WriteLine($"Warning: state '{unit.Optional.TargetState}' of item '{id}' is unknown and will be mapped to '{translatedState}'"); } muidb.AddOrUpdateString(id, cmd.Lang, unit.Target, translatedState, comment); } break; default: throw new Exception($"Unknown format: {cmd.Type}"); } muidb.Save(); }