|
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Localization
{
public class Linguist
{
private static Dictionary<string, XmlDocument> languageCache = new Dictionary<string, XmlDocument>();
public static string Phrase(string keyName)
{
string value = keyName;
if (keyName.Trim() == "") return value;
try
{
string languageId = Context.Current.CurrentLanguage.Id;
XmlDocument xmldoc = new XmlDocument();
if (languageCache.ContainsKey(languageId))
{
xmldoc = languageCache[languageId];
}
else
{
string xmlFilePath = System.Windows.Forms.Application.StartupPath + "\\Localization\\Languages\\" + languageId + ".xml";
if (System.IO.File.Exists(xmlFilePath))
{
xmldoc.Load(xmlFilePath);
languageCache.Add(languageId, xmldoc);
}
else
{
return keyName;
}
}
StringBuilder xpathExpression = new StringBuilder();
xpathExpression.Append("//phrases//phrase[@id='");
xpathExpression.Append(keyName);
xpathExpression.Append("']");
XmlNode node = xmldoc.SelectSingleNode(xpathExpression.ToString());
if (node != null)
value = node.InnerText;
if (value == "") value = keyName;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
return value;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Been programming since 2001 interested in finance, security, workflows, SharePoint and algorithms. He is an MCSD, MCDBA, MCAD, MCSD, (again), MCTS, MCPD and MCT.
My Blog: www.alihamdar.com