Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Xml.Linq;
- namespace CloseCaption_to_xliff
- {
- class Program
- {
- static void Main(string[] args)
- {
- string pattern = @"\s*""([A-Za-z0-9\.\/' _-]+)""\s+""(.*?)""\s*";
- string[] input = System.IO.File.ReadAllLines(@"J:\Inny\Desktop\Black Mesa PL WIP\PL latest\bms_spolszczenie\resource\bmsmp_english.txt");
- Dictionary<string, string> polishDict = new Dictionary<string, string>();
- foreach (string line in input)
- {
- Match match = Regex.Match(line, pattern);
- if (match.Success)
- {
- try
- {
- polishDict.Add(match.Groups[1].Value, match.Groups[2].Value);
- }
- catch (Exception)
- {
- Console.WriteLine(match.Groups[1].Value);
- throw;
- }
- }
- }
- XDocument doc = XDocument.Load("C:\\Users\\Eselter\\Downloads\\Black Mesa.xliff");
- XNamespace df = doc.Root.Name.Namespace;
- int count = 0;
- foreach (XElement transUnitNode in doc.Descendants(df + "trans-unit"))
- {
- try
- {
- XElement sourceNode = transUnitNode.Element(df + "note");
- if (polishDict.ContainsKey(sourceNode.Value.Split('\n').Last().Trim()))
- {
- count++;
- transUnitNode.Element(df + "target").Value = polishDict[sourceNode.Value.Split('\n').Last().Trim()];
- transUnitNode.Element(df + "target").Attribute("state").Value = "translated";
- }
- }
- catch (Exception)
- {
- Console.WriteLine(transUnitNode.Attribute("id").Value);
- }
- }
- doc.Save("C:\\Users\\Eselter\\Downloads\\Black Mesa.xliff");
- Console.WriteLine(count);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement