Sdl-Community
Sdl-Community copied to clipboard
Google Plugin Glossary Creator
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<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; }
}
} ` 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
Main
method is the entry point of the application. - A list of
EditItem
objects is created to represent the find/replace pairs.
- The
-
EditItem Class:
- A class
EditItem
is defined to hold the propertiesEnabled
,EditItemType
,FindText
, andReplaceText
.
- A class
-
XElement:
-
XElement
is used to create elements in the XML. - The
from item in editItems select new XElement(...)
LINQ query is used to createEditItem
elements dynamically based on the list ofEditItem
objects.
-
-
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.cs
content with the code above. - Run the application.
- Check the output directory for the
batch_find_replace.xml
file.
Customization:
- Modify the
editItems
list to add, remove, or change find/replace pairs. - Adjust the
Enabled
andEditItemType
attributes 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