当前注册人数24460人 邮箱: 密码: 注册新用户 忘记密码
首页 C/C++/MFC C# ASP.NET VB.NET MATLAB   站内搜索 BBS讨论社区 下载代码说明/积分规则
为什么要注册?

1. 可以直接免费从本站下载代码,防止邮件发送不到您的邮箱,或登录不了国外网站

2. 可以设定关键字,当有您关心的代码收录时,邮件通知您

3. 对这里的代码进行评分和评论

4. 可以和大家一起分享你的源代码,得到跟多的建议

ASP.NET网站动态多语言本地化/国际化支持入门完全教程及源代码

Dynamic Website Multi-languages Management

2008年03月03日
C#, C# 1.0, C# 2.0, C# 3.0, Windows, .NET, ASP.NET, IIS, VS, IE, WebForms, IIS 7, IIS 6, VS2005
现在确实很多的文章说过多语言支持这个话题,不过很多都比较复杂,对于一个入门的人来说并不是好事。这里的代码和文章,非常详细地告诉你如何动态的让你的网站支持多个语言,其方法非常简单,使用资源记录多个支持的语言,每个浏览器可以选择自己的语言,如果在资源文件中没有就会取一个默认的值。

源代码及技术文章下载(请点击下面的原文链接下载)


源码图片
请点击链接查看大图
关键内容
static LanguageManager()
    {
        //
        // Available Cultures
        //
        List<string> availableResources = new List<string>();
        string resourcespath = Path.Combine(System.Web.HttpRuntime.AppDomainAppPath, "App_GlobalResources");
        DirectoryInfo dirInfo = new DirectoryInfo(resourcespath);
        foreach (FileInfo fi in dirInfo.GetFiles("*.*.resx", SearchOption.AllDirectories))
        {
            //Take the cultureName from resx filename, will be smt like en-US
            string cultureName = Path.GetFileNameWithoutExtension(fi.Name); //get rid of .resx
            if (cultureName.LastIndexOf(".") == cultureName.Length - 1)
                continue; //doesnt accept format FileName..resx
            cultureName = cultureName.Substring(cultureName.LastIndexOf(".") + 1);
            availableResources.Add(cultureName);
        }
        List result = new List();
        foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
        {
            //If language file can be found
            if (availableResources.Contains(culture.ToString()))
            {
                result.Add(culture);
            }
        }
        AvailableCultures = result.ToArray();
        //
        // Current Culture
        //
        CurrentCulture = DefaultCulture;
        // If default culture is not available, take another available one to use
        if (!result.Contains(DefaultCulture) && result.Count>0)
        {
            CurrentCulture = result[0];
        }
    }
从本站下载附件及源代码(1个附件,已经成功下载42次)

最值得关注的外文源代码

Web Conference
Instantly Changing Language in the Form
The localizable Dropdown for ASP.NET 2.0
port scan with asp.net
评论(评论是增加积分的一个有效途径)
字数在300字内
请如实评论
所有评论

wolfzero  2008年12月31日
好!源代码
yan1248  2008年12月11日
怎么下载不了啊?
spsh68  2008年10月29日
不错
ctgu0002  2008年10月19日
66888888  2008年10月14日
good
小朱  2008年09月05日
挺好的
lry  2008年08月28日
ASP.NET网站动态多语言本地化/国际化支持入门完全教程及源代码
pp2008  2008年08月07日
挺好的
akunge  2008年08月05日
挺好的
CopyRight (C) codesoso.com 2007-2008 All Rights Reserved   免责声明