示例#1
0
        public void ParseFile(string path)
        {
            using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader reader = new StreamReader(stream, FileEncoding))
                {
                    string   allData = reader.ReadToEnd();
                    string[] lines   = allData.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    if (lines.Length <= 1)
                    {
                        throw new NotSupportedException();
                    }
                    string[] line           = lines[0].Split(_splitCharacters, StringSplitOptions.None);
                    int      languagesCount = line.Length - 1;
                    _parsedDictionary = new ParsedDictionary(languagesCount);
                    for (int i = 1; i < line.Length; i++)
                    {
                        _parsedDictionary.AvailableLanguages[i - 1] = line[i];
                    }

                    for (int i = 1; i < lines.Length; i++)
                    {
                        line = lines[i].Split(_splitCharacters, StringSplitOptions.None);
                        string   key          = line[0];
                        string[] translations = new string[languagesCount];
                        Array.Copy(line, 1, translations, 0, languagesCount);
                        _parsedDictionary.SetTranslation(key, translations);
                    }
                }
            }
        }
示例#2
0
 public Translator(string filePath, IFileParser fileParser)
 {
     fileParser.ParseFile(filePath);
     _parsedDictionary = fileParser.ResultDictionary;
     if (_parsedDictionary.AvailableLanguages.Length > 0)
     {
         _currentLanguage = 0;
     }
 }