首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建动态多语言网站

创建动态多语言网站
EN

Stack Overflow用户
提问于 2013-11-09 07:37:00
回答 2查看 2.2K关注 0票数 0

我正计划实现一个多语言的网站,所以我的第一个想法是使用resx文件,但是我有一个要求,允许来自行政部门的所有文本都可以编辑,

代码语言:javascript
复制
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?
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-09 07:55:07

您可以使用xml或sql表。您应该为管理员准备一个页面,并列出所有需要翻译的单词。基础语言管理员登录,更新将单词翻译到您的表或xml文件。另外,为了获得最佳的性能,将每个语言单词加载到系统捕获。

编写如下代码,将单词输入到表或xml中。

代码语言:javascript
复制
<%=PLang.GetString("YourWordInEnglish")%>

在你的aspx里

.

代码语言:javascript
复制
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;
        }
    }

.用于编辑函数

代码语言:javascript
复制
 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);
    }
}
票数 1
EN

Stack Overflow用户

发布于 2013-11-09 07:43:00

您可以使用XML文件进行翻译,在应用程序启动时解析它们,并将翻译存储在缓存中。您可以使用FileSystemWatcher类查看何时有人更新文件,然后使缓存失效。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19873576

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档