Beispiel #1
0
 private void LoadFile(FileInfo file, bool winforms)
 {
     var doc = XDocument.Load(file.FullName);
     foreach (var item in doc.Root.Elements("data"))
     {
         var prop = item.Attribute("name")?.Value;
         var original = item.Element("value")?.Value;
         if (!Rules.IsTranslatable(winforms, prop, ref original, out _, out _))
         {
             continue;
         }
         if (!Strings.ContainsKey(original))
         {
             Strings[original] = new TranslatableString { Original = original, Context = new List<string>()};
         }
         Strings[original].Context.Add($"{file.Name}${prop}$Message");
     }
 }
Beispiel #2
0
        public void Load(string poFile)
        {
            using (var reader = new StreamReader(poFile))
            {
                string line;
                string NextLine() => line = reader.ReadLine()?.Trim();

                while (NextLine() != null)
                {
                    if (!line.StartsWith("msgid", StringComparison.InvariantCulture))
                    {
                        continue;
                    }

                    string original = line.Substring(7, line.Length - 8);
                    while (NextLine() != null && line.StartsWith("\"", StringComparison.InvariantCulture))
                    {
                        original += line.Substring(1, line.Length - 2);
                    }

                    if (line == null || !line.StartsWith("msgstr", StringComparison.InvariantCulture))
                    {
                        continue;
                    }

                    string translated = line.Substring(8, line.Length - 9);
                    while (NextLine() != null && line.StartsWith("\"", StringComparison.InvariantCulture))
                    {
                        translated += line.Substring(1, line.Length - 2);
                    }

                    Strings[original] = new TranslatableString
                    {
                        Original    = original,
                        Translation = translated
                    };
                }
            }
        }