wxr
2020-06-15 b8e94316e41eba72d927d5ca7d931b26139ee8ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.IO;
 
namespace Shared
{
    public static class Language
    {
        static System.Collections.Generic.List<string> currentStringList;
        static Language()
        {
            UpdateLanguage ();
            if (0 < currentStringList.Count&&currentStringList[0].StartsWith("CurrentLanguage=")) {
                CurrentLanguage = currentStringList [0].Substring ("CurrentLanguage=".Length);
            }
        }
        static System.Collections.Generic.List<string> readStringList(string fileName,System.Text.Encoding encoding)
        {
            var stringList = new System.Collections.Generic.List<string> ();
            System.IO.StreamReader fs = null;
            try {
                var language = Application.Activity.Assets.Open(fileName);
                fs = new  StreamReader(language,encoding);
                string s;
                while(null!=(s=fs.ReadLine()))
                {
                    stringList.Add(s.Trim());
                }
                language.Close();
                return stringList;
            } catch {
                return stringList;
            } finally {
                try {
                    if (fs != null) {
                        fs.Close ();    
                    }
                } catch {
 
                }
            }
        }
        /// <summary>
        /// 重新更新语言库数据
        /// </summary>
        public static void UpdateLanguage()
        {
            currentStringList = readStringList("Language.ini", System.Text.Encoding.UTF8);
        }
        /// <summary>
        /// 当前设置的语言
        /// </summary>
        public static string CurrentLanguage="English";
        /// <summary>
        /// 根据ID获取对应的备注
        /// </summary>
        /// <returns>The by I.</returns>
        /// <param name="id">Identifier.</param>
        public static string StringByID(int id)
        {
            bool flag = false;
            for (int i = 0; i < currentStringList.Count; i++) {
                string currentLine = currentStringList [i];
                if (flag) {
                    if (currentLine.Contains("=")&&currentLine.StartsWith(id.ToString()+"=")) {
                        return currentLine.Substring (id.ToString ().Length + 1);
                    }
                } else if (currentLine == "[" + CurrentLanguage + "]") {
                    flag = true;
                } else {
                    continue;
                }
            }
            return string.Empty;
        }
 
        public static string  []GetAllLanguage()
        {
            System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string> ();
 
            for (int i = 0; i < currentStringList.Count; i++) {
                string currentLine = currentStringList [i].Trim();
                if (currentLine.StartsWith ("[") && currentLine.EndsWith ("]")) {
                    list.Add(currentLine.Substring(1,currentLine.Length-2));
                }
            }
            return list.ToArray();
        }
    }
}