wxr
2020-03-05 0bdc0a135dbe31761b53f432ed34f347f0a4e36b
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
90
91
92
93
94
95
96
97
98
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 filePath = Foundation.NSBundle.MainBundle.PathForResource(fileName, null);
                if (filePath == null)
                {
                    return stringList;
                }
                //if (System.IO.File.Exists (System.IO.Path.Combine (Application.RootPath, fileName))) {
                    //fs = new   StreamReader (System.IO.Path.Combine (Application.RootPath, fileName),encoding);
                //} else if (System.IO.File.Exists (fileName)) {
                    fs = new  StreamReader (filePath,encoding);
                //} else {
                    //return stringList;
                //}
                string s;
                while(null!=(s=fs.ReadLine()))
                {
                    stringList.Add(s.Trim());
                }
                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()
        {
            var 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();
        }
    }
}