【问题标题】:Load Resources for other Language加载其他语言的资源
【发布时间】:2011-01-23 16:17:42
【问题描述】:

我有一个应用程序,它使用资源进行翻译。这很好用。 现在,我有一个特殊的要求。为此,我必须加载另一种语言的资源 dll(例如,应用程序启动并使用英语工作,然后我还必须加载德语翻译)并查看它的翻译。

有没有简单的方法来做到这一点?

【问题讨论】:

    标签: c# resources load translation


    【解决方案1】:

    您需要加载资源管理器,如果您需要特定语言的资源,则需要使用特定的文化来请求它们,使用:

    GetObject(String, CultureInfo)
    

    您可以使用以下方法创建您需要的文化:

    new CultureInfo(string name)
    

    或者

    CultureInfo.CreateSpecificCulture(string name)
    

    或者

    CultureInfo.GetCultureInfo(string name)
    

    名称是文化名称:“en”英语,“de”德语...您可以在以下链接中查看完整列表:cultures

    【讨论】:

      【解决方案2】:
      using System.Resources;
      using System.Reflection;
      
      Assembly gerResAssembly = Assembly.LoadFrom("YourGerResourceAssembly.dll");
      var resMgr = new ResourceManager("StringResources.Strings", gerResAssembly);
      string gerString = resMgr.GetString("TheNameOfTheString");
      

      【讨论】:

        【解决方案3】:

        您可以使用GetString 与您需要的特定 CultureInfo 一起调用。 例如:

        using System.Resources;
        using System.Reflection;
        
        Assembly gerResAssembly = Assembly.LoadFrom("YourGerResourceAssembly.dll");
        var resMgr = new ResourceManager("StringResources.Strings", gerResAssembly);
        
        // for example german:
        string strDE = resMgr.GetString("TheNameOfTheString",  new CultureInfo("de"));
        // for example spanish
        string strES = resMgr.GetString("TheNameOfTheString",  new CultureInfo("es"));
        

        `

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-01-20
          • 1970-01-01
          • 1970-01-01
          • 2011-11-23
          • 1970-01-01
          • 2017-11-04
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多