示例#1
0
        private void LoadLocalisationFile(string path)
        {
            using (var file = new StreamReader(path, Encoding.Default))
            {
                var key       = new StringBuilder();
                var value     = new StringBuilder();
                var readKey   = true;
                var readValue = false;
                var comment   = true;
                //var inQuotes = false;
                while (!file.EndOfStream)
                {
                    var ch = Convert.ToChar(file.Read());

                    if (Environment.NewLine.Contains(ch))
                    {
                        readValue = false;
                        readKey   = true;
                        if (key.Length > 0 && value.Length > 0 && !Localisation.ContainsKey(key.ToString()))
                        {
                            Localisation.Add(key.ToString(), value.ToString());
                        }
                        key     = new StringBuilder();
                        value   = new StringBuilder();
                        comment = false;
                        continue;
                    }
                    if (ch == '#' || comment)
                    {
                        comment = true;
                        continue;
                    }
                    if (ch == ';')
                    {
                        if (readValue)
                        {
                            readValue = false;
                        }
                        if (readKey)
                        {
                            readKey   = false;
                            readValue = true;
                        }

                        continue;
                    }


                    if (readKey)
                    {
                        key.Append(ch);
                    }
                    if (readValue)
                    {
                        value.Append(ch);
                    }
                }
                if (key.Length > 0 && value.Length > 0)
                {
                    Localisation.Add(key.ToString(), value.ToString());
                }
            }
        }