Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Plugin Glossary Creator #1558

Open
drkhateeb opened this issue May 25, 2024 · 0 comments
Open

Google Plugin Glossary Creator #1558

drkhateeb opened this issue May 25, 2024 · 0 comments

Comments

@drkhateeb
Copy link

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 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:

  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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant