在网上看了一些方法,觉得下面这个方法挺好,但是我在VS2008中就是找不到它所说的“Tools->Generate Local Resource
”。另外大家帮忙提供点建议,做这种界面什么方法比较实用、简单。

1. 跟以前一样做界面,只是注意,把所有需要有多语言界面的文字都用label来做   2. 做完以后,在Solution Explorer里选中这个文件,选Tools->Generate Local Resource  3. 你会发现生成了一个目录,App_LocalResources;这个目录里多了一个resx的文件。比如你的aspx文件是default.aspx,它就会生成一个叫做default.aspx.resx的文件。  4. 打开这个文件看看,原来在label中的那些文字都跑到这里来了  5. 打开原来的aspx文件看看source,会发现源码变了:

解决方案 »

  1.   

    我觉得这样其实不太好...这样生成的基本上一个页面就对应一个资源文件...维护起来不太好.
    你可以写一个公共的获取多语言的方法:
       public static string GetText(string name)
            {
                return Labels.ResourceManager.GetString(name);
          }
     Labels就是建立的资源文件生成的类这样的话,你在需要设置多语言的地方直接设置:
    比如在页面  <a href=""><%=GetText("Link")%></a>
    在后台代码: 
                this.button1.Text= GetText("OK");
              等等..然后通过在页面上角或者是登陆时选择多语言事件,来设置当前语言环境:
     比如在Application_BeginRequest中
              string language =  Request.Cookies["Language"] == null ? null : Request.Cookies["Language"].Value;
                 if (!string.IsNullOrEmpty(language))
                 {
                     System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(language);
                     System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
                     System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                 }
      

  2.   

    第一个问题自己解决了,要在设计状态下才看的到,另外我在复制一个其他语言版本的资源文件,如何设置用户打开时显示的语言,就是启用那个资源文件。
    是不是在culture="auto" meta:resourcekey="PageResource1" uiculture="auto" 怎么设置的?
      

  3.   

    如果,最终用户使用IE浏览, 使用XML 数据岛挺不错的.<xml id="xmlSrc" src="zh_cn/lang.xml"/>
    <span datasrc="#xmlSrc" datafld="langField">默认文本</span>
      

  4.   

    你是看的这个方法吧
    http://myrat.cnblogs.com/archive/2006/05/18/403154.html1个问题你已经解决了2.你要切换到aspx设计界面,然后再点击.上面的菜单工具---生成本地资源文件,然后会生成对应的页面的资源文件.会自动帮你修改aspx代码的
      
      

  5.   


     
                    System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(language); 
                    System.Threading.Thread.CurrentThread.CurrentUICulture = culture; 
                    System.Threading.Thread.CurrentThread.CurrentCulture = culture; 
     如果你不设置,或者是把页面的culture="auto",他会根据客户本地的环境显示对应的语言的.如果你要强制设置,或者要会自动转换语言,都可以利用上面的代码实现
    language 可以是zh-cn,en-us....
      

  6.   

    我一般是直接写个类似Label的控件
    这个Label自己去读取相应XML文件的指定节点的文本值比如<cc:label xpath="resource/Access.Login/userName" runat="server" />后台页:foreach(..) {
      label = ... as Label;
      if(label != null) {
        label.LanguageFile = GetLanguageFolder + "resource.xml";
      }
    }当然,处理上需要一些技巧,避免一个页面实例化多个IO对象去读取XML
      

  7.   

    我设计了下面这种方法遍历窗体中的控件名称,其他的空间都可以,但就是gridview不行,大家帮忙看看是什么原因
    void findcontrol(Control parent)
        {
            foreach (Control cname in parent.Controls)
            {
                switch (cname.GetType().Name.ToString().Trim())
                {
                    case "Label":
                        ((Label)cname).Text = Resources.lang.ResourceManager.GetString(((Label)cname).Text);
                        break;
                    case "Button":
                        ((Button)cname).Text = Resources.lang.ResourceManager.GetString(((Button)cname).Text);
                        break;
                    case "LinkButton":
                        ((LinkButton)cname).Text = Resources.lang.ResourceManager.GetString(((LinkButton)cname).Text);
                        break;
                    case "GridView":
                        foreach (DataControlField col in ((GridView)cname).Columns)
                        {
                            col.HeaderText = Resources.lang.ResourceManager.GetString(col.HeaderText);
                        }            if (cname.Controls.Count > 0)
                {
                    findcontrol(cname);
                }
            }
        }
      

  8.   

    生成一个全局性的ResourceFile,我们通过配置文件读到语言的种类,只要User选择他所需要的语言,我们就在相应的ResourceFile中去找到Label所对应的语言版本,
         这:   System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(language); 
                    System.Threading.Thread.CurrentThread.CurrentUICulture = culture; 
                    System.Threading.Thread.CurrentThread.CurrentCulture = culture; 
    是告诉.Net程式该用哪种语言显示给User。
      

  9.   

    没有报异常。异常就是显示出的head并没有改变,就是没有被上面的过程赋值