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&¤tStringList[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("=")&¤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<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();
|
}
|
}
|
}
|