Ejemplo n.º 1
0
        static void FillEmpty()
        {
            // Read original .po
            Console.WriteLine("Write path or drag the original full .po file with empty lines.");

            string OriginalPath = Console.ReadLine().Replace("\"", "");

            string[] OriginalLines = System.IO.File.ReadAllLines(OriginalPath);

            ParsedPo OriginalPo = new ParsedPo();

            OriginalPo.ReadFromLines(OriginalLines);

            // Read translated .po
            Console.WriteLine("Write path or drag the old .po file.");

            string ExtractedPath = Console.ReadLine().Replace("\"", "");

            string[] ExtractedLines = System.IO.File.ReadAllLines(ExtractedPath);

            ParsedPo ExtractedPo = new ParsedPo();

            ExtractedPo.ReadFromLines(ExtractedLines);

            // cycle all original .po entries
            if (OriginalPo.Entries != null)
            {
                for (int OrigPoEntryIndex = 0; OrigPoEntryIndex < OriginalPo.Entries.Count; OrigPoEntryIndex++)
                {
                    if (OriginalPo.Entries[OrigPoEntryIndex].bIsTranslationEmpty)
                    {
                        Entry FoundEntry = ExtractedPo.GetEntryWithSourceString(OriginalPo.Entries[OrigPoEntryIndex].OriginalString);

                        if (!String.IsNullOrEmpty(FoundEntry.TranslatedString))
                        {
                            OriginalPo.Entries[OrigPoEntryIndex].TranslatedString = FoundEntry.TranslatedString;
                        }
                    }
                }
            }

            string pathSave = OriginalPath.Remove(OriginalPath.Length - 3, 3);

            pathSave = pathSave + "_filled.po";

            System.IO.File.WriteAllLines(pathSave, OriginalPo.WritePoToLines());
        }
Ejemplo n.º 2
0
        static void Extract()
        {
            Console.WriteLine("Write path or drag .po file with empty lines to extract.");

            string path = Console.ReadLine().Replace("\"", "");

            string[] lines = System.IO.File.ReadAllLines(path);

            ParsedPo PoToExtract = new ParsedPo();

            PoToExtract.ReadFromLines(lines);


            // Create a new parsed .po that will contain only empty entries
            ParsedPo PoWithOnlyEmptyEntries = new ParsedPo();

            PoWithOnlyEmptyEntries.Intro = PoToExtract.Intro;

            PoWithOnlyEmptyEntries.Entries = new List <Entry>();

            for (int EntryIndex = 0; EntryIndex < PoToExtract.Entries.Count; EntryIndex++)
            {
                if (PoToExtract.Entries[EntryIndex].bIsTranslationEmpty)
                {
                    Entry newEntry = new Entry();

                    newEntry = PoToExtract.Entries[EntryIndex];

                    PoWithOnlyEmptyEntries.Entries.Add(newEntry);
                }
            }

            string pathSave = path.Remove(path.Length - 3, 3);

            pathSave = pathSave + "_extracted.po";

            System.IO.File.WriteAllLines(pathSave, PoWithOnlyEmptyEntries.WritePoToLines());
        }