Sdl-Community icon indicating copy to clipboard operation
Sdl-Community copied to clipboard

Google Plugin Glossary Creator

Open drkhateeb opened this issue 8 months ago • 0 comments

Hello kindly add a form to create a glossary for pre-post translation tweaking similar to this glossarycreator

tweaking

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:

  1. Namespaces:

    • System: Provides basic functionalities.
    • System.Collections.Generic: Provides the List<T> class.
    • System.Xml.Linq: Provides LINQ to XML classes.
  2. 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.
  3. EditItem Class:

    • A class EditItem is defined to hold the properties Enabled, EditItemType, FindText, and ReplaceText.
  4. XElement:

    • XElement is used to create elements in the XML.
    • The from item in editItems select new XElement(...) LINQ query is used to create EditItem elements dynamically based on the list of EditItem objects.
  5. Save Method:

    • root.Save(filePath) saves the XML structure to a file specified by filePath.

Running the Code:

  1. Open Visual Studio or any C# IDE.
  2. Create a new Console Application project.
  3. Replace the Program.cs content with the code above.
  4. Run the application.
  5. 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 and EditItemType 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

drkhateeb avatar May 25 '24 17:05 drkhateeb