我正计划实现一个多语言的网站,所以我的第一个想法是使用resx文件,但是我有一个要求,允许来自行政部门的所有文本都可以编辑,
can i do such a feature with resx files or should I store them in a database (schemaless) or is there a better way to do this?发布于 2013-11-09 07:55:07
您可以使用xml或sql表。您应该为管理员准备一个页面,并列出所有需要翻译的单词。基础语言管理员登录,更新将单词翻译到您的表或xml文件。另外,为了获得最佳的性能,将每个语言单词加载到系统捕获。
编写如下代码,将单词输入到表或xml中。
<%=PLang.GetString("YourWordInEnglish")%>在你的aspx里
.
public static string GetString(string word)
{
try
{
if (String.IsNullOrWhiteSpace(word)) return "";
Dictionary<string, string> resourcesDictionary = GetResource(GetLanguageID());
if (resourcesDictionary != null)
{
if (!resourcesDictionary.ContainsKey(word.ToLower()))
{
Expression exp = new Expression();
exp.Word = exp.Translation = word;
exp.LanguageID = GetLanguageID();
exp.SiteID = Globals.GetSiteID();
if (exp.SiteID == 0 && exp.LanguageID == 0)
return word;
if (FLClass.createExpression(exp, ref resourcesDictionary) > 0)
return resourcesDictionary[word];
else
return word;
}
return resourcesDictionary[word.ToLower()];
}
else
return word;
}
catch
{
return word;
}
}.用于编辑的函数
public class ViewExpressionListEdit : BaseWebService
{
[WebMethod(EnableSession = true)]
public bool updateExpression(ExpressionService expressionService)
{
Expression expression = new Expression();
expression.ExpressionID = expressionService.ExpressionID;
expression.Translation = expressionService.Translation;
expression.LanguageID = expressionService.LanguageID;
expression.SiteID = Globals.GetSiteID();
return FLClass.updateExpression(expression);
}
}发布于 2013-11-09 07:43:00
您可以使用XML文件进行翻译,在应用程序启动时解析它们,并将翻译存储在缓存中。您可以使用FileSystemWatcher类查看何时有人更新文件,然后使缓存失效。
https://stackoverflow.com/questions/19873576
复制相似问题