From 9384fff4b98225c26173c10dc8c87b7193f22d51 Mon Sep 17 00:00:00 2001 From: Cameron White Date: Sat, 23 Dec 2023 15:32:15 -0500 Subject: [PATCH] Fix formatting --- installer/addins/Program.cs | 112 ++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/installer/addins/Program.cs b/installer/addins/Program.cs index f1e7a6d67..5b253d194 100644 --- a/installer/addins/Program.cs +++ b/installer/addins/Program.cs @@ -1,68 +1,68 @@ -using System; +using System; using System.CommandLine; using System.IO; using System.Linq; -using System.Xml; - -// Insert translations from the resource files into the manifest (.addin.xml) -// See https://github.com/mono/mono-addins/wiki/The-add-in-header +using System.Xml; + +// Insert translations from the resource files into the manifest (.addin.xml) +// See https://github.com/mono/mono-addins/wiki/The-add-in-header static void LocalizeManifest (FileInfo manifestFile, FileInfo[] resourceFiles) -{ - Console.WriteLine ($"Loading manifest from {manifestFile}"); - var manifestDoc = new XmlDocument () { PreserveWhitespace = true }; - manifestDoc.Load (manifestFile.FullName); - - // The properties to translate. - string[] headerProperties = new[] { "Name", "Description" }; - var headerPropertyNodes = headerProperties.Select (propertyName => - manifestDoc.SelectSingleNode ($"/Addin/Header/{propertyName}") ?? - throw new InvalidDataException ($"Add-in manifest does not specify header property '{propertyName}'")); - - foreach (var resourceFile in resourceFiles) { - // Parse the locale name from filenames like Language.es.resx. - // We don't need to process the template file (Language.resx). - var components = resourceFile.Name.Split ('.'); - if (components.Length != 3) { - Console.WriteLine ($"Skipping file {resourceFile}"); - continue; - } - - string langCode = components[1]; - - Console.WriteLine ($"{langCode}: Loading resource {resourceFile}"); - var resourceDoc = new XmlDocument (); - resourceDoc.Load (resourceFile.FullName); - - foreach (XmlNode headerPropertyNode in headerPropertyNodes) { - string propertyName = headerPropertyNode.Name; - var translationNode = resourceDoc.SelectSingleNode ($"/root/data[@name='{headerPropertyNode.InnerText}']/value"); - if (translationNode is not null) { - Console.WriteLine ($" - Adding translation for {propertyName}: {translationNode.InnerText}"); - - // Add a sibling node, e.g. Translated string - var newNode = manifestDoc.CreateElement (propertyName); - newNode.SetAttribute ("locale", langCode); - newNode.InnerText = translationNode.InnerText; - - headerPropertyNode.ParentNode!.AppendChild (newNode); - } else - Console.WriteLine ($" - Did not find translation for {propertyName}"); - } - } - - Console.WriteLine ($"Updating {manifestFile}"); - manifestDoc.Save (manifestFile.FullName); +{ + Console.WriteLine ($"Loading manifest from {manifestFile}"); + var manifestDoc = new XmlDocument () { PreserveWhitespace = true }; + manifestDoc.Load (manifestFile.FullName); + + // The properties to translate. + string[] headerProperties = new[] { "Name", "Description" }; + var headerPropertyNodes = headerProperties.Select (propertyName => + manifestDoc.SelectSingleNode ($"/Addin/Header/{propertyName}") ?? + throw new InvalidDataException ($"Add-in manifest does not specify header property '{propertyName}'")); + + foreach (var resourceFile in resourceFiles) { + // Parse the locale name from filenames like Language.es.resx. + // We don't need to process the template file (Language.resx). + var components = resourceFile.Name.Split ('.'); + if (components.Length != 3) { + Console.WriteLine ($"Skipping file {resourceFile}"); + continue; + } + + string langCode = components[1]; + + Console.WriteLine ($"{langCode}: Loading resource {resourceFile}"); + var resourceDoc = new XmlDocument (); + resourceDoc.Load (resourceFile.FullName); + + foreach (XmlNode headerPropertyNode in headerPropertyNodes) { + string propertyName = headerPropertyNode.Name; + var translationNode = resourceDoc.SelectSingleNode ($"/root/data[@name='{headerPropertyNode.InnerText}']/value"); + if (translationNode is not null) { + Console.WriteLine ($" - Adding translation for {propertyName}: {translationNode.InnerText}"); + + // Add a sibling node, e.g. Translated string + var newNode = manifestDoc.CreateElement (propertyName); + newNode.SetAttribute ("locale", langCode); + newNode.InnerText = translationNode.InnerText; + + headerPropertyNode.ParentNode!.AppendChild (newNode); + } else + Console.WriteLine ($" - Did not find translation for {propertyName}"); + } + } + + Console.WriteLine ($"Updating {manifestFile}"); + manifestDoc.Save (manifestFile.FullName); } var manifestFileOption = new Option ( - name: "--manifest-file") { - IsRequired = true + name: "--manifest-file") { + IsRequired = true }.ExistingOnly (); var resourceFilesOption = new Option ( - name: "--resource-files") { - IsRequired = true, - AllowMultipleArgumentsPerToken = true + name: "--resource-files") { + IsRequired = true, + AllowMultipleArgumentsPerToken = true }.ExistingOnly (); var localizeManifestCommand = new Command ( @@ -76,4 +76,4 @@ static void LocalizeManifest (FileInfo manifestFile, FileInfo[] resourceFiles) var rootCommand = new RootCommand ("Command-line utilities for Pinta add-ins."); rootCommand.AddCommand (localizeManifestCommand); -rootCommand.Invoke (args); \ No newline at end of file +rootCommand.Invoke (args);