Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronwhite committed Dec 23, 2023
1 parent 4ebf090 commit 9384fff
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions installer/addins/Program.cs
Original file line number Diff line number Diff line change
@@ -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. <Name locale="es">Translated string</Name>
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. <Name locale="es">Translated string</Name>
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<FileInfo> (
name: "--manifest-file") {
IsRequired = true
name: "--manifest-file") {
IsRequired = true
}.ExistingOnly ();

var resourceFilesOption = new Option<FileInfo[]> (
name: "--resource-files") {
IsRequired = true,
AllowMultipleArgumentsPerToken = true
name: "--resource-files") {
IsRequired = true,
AllowMultipleArgumentsPerToken = true
}.ExistingOnly ();

var localizeManifestCommand = new Command (
Expand All @@ -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);
rootCommand.Invoke (args);

0 comments on commit 9384fff

Please sign in to comment.