zoukankan      html  css  js  c++  java
  • 如何使用App_LocalResources实现界面多语言

    方法一:在网上看了一些方法,觉得下面这个方法挺好,但是我在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,会发现源码变了:

    方法二:我觉得这样其实不太好...这样生成的基本上一个页面就对应一个资源文件...维护起来不太好.
    你可以写一个公共的获取多语言的方法:
      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;
      }

  • 相关阅读:
    关于时间:UTC/GMT/xST/ xDT
    javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.Size' validating type 'java.util.Date'.
    svn tree confflect
    spring+mybatis 配置双数据源
    JUC 之 ThreadPoolExecutor 的一些研究
    关于 Thread.currentThread()
    swagger 基础入门
    oryx 分离&集成
    Jenkins 之邮件配置
    Jenkins 简单配置
  • 原文地址:https://www.cnblogs.com/hxwzwiy/p/2412253.html
Copyright © 2011-2022 走看看