-
Notifications
You must be signed in to change notification settings - Fork 138
Google Plugin Glossary Creator #1558
Description
Hello
kindly add a form to create a glossary for
pre-post translation tweaking
similar to this

XML architecture
`using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace BatchFindReplaceXmlCreator
{
class Program
{
static void Main(string[] args)
{
// Define the list of find/replace items
List editItems = new List
{
new EditItem
{
Enabled = true,
EditItemType = "plain_text",
FindText = "Hello",
ReplaceText = "Hi"
},
new EditItem
{
Enabled = false,
EditItemType = "regular_expression",
FindText = "\d+",
ReplaceText = "[number]"
},
new EditItem
{
Enabled = true,
EditItemType = "plain_text",
FindText = "World",
ReplaceText = "Earth"
}
};
// Create the XML structure
XElement root = new XElement("EditCollection",
new XElement("Items",
from item in editItems
select new XElement("EditItem",
new XAttribute("Enabled", item.Enabled),
new XAttribute("EditItemType", item.EditItemType),
new XElement("FindText", item.FindText),
new XElement("ReplaceText", item.ReplaceText)
)
)
);
// Save the XML to a file
string filePath = "batch_find_replace.xml";
root.Save(filePath);
Console.WriteLine($"XML file created at {filePath}");
}
}
// Define a class to represent an EditItem
public class EditItem
{
public bool Enabled { get; set; }
public string EditItemType { get; set; }
public string FindText { get; set; }
public string ReplaceText { get; set; }
}
}
`
Certainly! Below is a C# console application that creates an XML file with the specified structure for batch find/replace lists. This application will allow you to define multiple find/replace pairs with attributes and save them to an XML file.
using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace BatchFindReplaceXmlCreator
{
class Program
{
static void Main(string[] args)
{
// Define the list of find/replace items
List<EditItem> editItems = new List<EditItem>
{
new EditItem
{
Enabled = true,
EditItemType = "plain_text",
FindText = "Hello",
ReplaceText = "Hi"
},
new EditItem
{
Enabled = false,
EditItemType = "regular_expression",
FindText = "\\d+",
ReplaceText = "[number]"
},
new EditItem
{
Enabled = true,
EditItemType = "plain_text",
FindText = "World",
ReplaceText = "Earth"
}
};
// Create the XML structure
XElement root = new XElement("EditCollection",
new XElement("Items",
from item in editItems
select new XElement("EditItem",
new XAttribute("Enabled", item.Enabled),
new XAttribute("EditItemType", item.EditItemType),
new XElement("FindText", item.FindText),
new XElement("ReplaceText", item.ReplaceText)
)
)
);
// Save the XML to a file
string filePath = "batch_find_replace.xml";
root.Save(filePath);
Console.WriteLine($"XML file created at {filePath}");
}
}
// Define a class to represent an EditItem
public class EditItem
{
public bool Enabled { get; set; }
public string EditItemType { get; set; }
public string FindText { get; set; }
public string ReplaceText { get; set; }
}
}Explanation:
-
Namespaces:
System: Provides basic functionalities.System.Collections.Generic: Provides theList<T>class.System.Xml.Linq: Provides LINQ to XML classes.
-
Main Method:
- The
Mainmethod is the entry point of the application. - A list of
EditItemobjects is created to represent the find/replace pairs.
- The
-
EditItem Class:
- A class
EditItemis defined to hold the propertiesEnabled,EditItemType,FindText, andReplaceText.
- A class
-
XElement:
XElementis used to create elements in the XML.- The
from item in editItems select new XElement(...)LINQ query is used to createEditItemelements dynamically based on the list ofEditItemobjects.
-
Save Method:
root.Save(filePath)saves the XML structure to a file specified byfilePath.
Running the Code:
- Open Visual Studio or any C# IDE.
- Create a new Console Application project.
- Replace the
Program.cscontent with the code above. - Run the application.
- Check the output directory for the
batch_find_replace.xmlfile.
Customization:
- Modify the
editItemslist to add, remove, or change find/replace pairs. - Adjust the
EnabledandEditItemTypeattributes as needed. - Add more complex structures or additional attributes if required.
This example provides a basic template for creating an XML file with the specified structure for batch find/replace lists. You can expand and customize it according to your specific needs.
https://github.com/RWS/Sdl-Community/tree/master/MT%20Enhanced%20Provider#xml-structure
