using System; using System.IO; namespace Shared { public static class Language { static System.Collections.Generic.List currentStringList; static Language() { UpdateLanguage (); if (0 < currentStringList.Count&¤tStringList[0].StartsWith("CurrentLanguage=")) { CurrentLanguage = currentStringList [0].Substring ("CurrentLanguage=".Length); } } static System.Collections.Generic.List readStringList(string fileName,System.Text.Encoding encoding) { var stringList = new System.Collections.Generic.List (); 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 { } } } /// /// 重新更新语言库数据 /// public static void UpdateLanguage() { currentStringList = readStringList("Language.ini", System.Text.Encoding.UTF8); } /// /// 当前设置的语言 /// public static string CurrentLanguage="English"; /// /// 根据ID获取对应的备注 /// /// The by I. /// Identifier. 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("=")&¤tLine.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 (); 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(); } } }