<legend id='AfMgw'><style id='AfMgw'><dir id='AfMgw'><q id='AfMgw'></q></dir></style></legend>
  • <small id='AfMgw'></small><noframes id='AfMgw'>

      <bdo id='AfMgw'></bdo><ul id='AfMgw'></ul>

      1. <i id='AfMgw'><tr id='AfMgw'><dt id='AfMgw'><q id='AfMgw'><span id='AfMgw'><b id='AfMgw'><form id='AfMgw'><ins id='AfMgw'></ins><ul id='AfMgw'></ul><sub id='AfMgw'></sub></form><legend id='AfMgw'></legend><bdo id='AfMgw'><pre id='AfMgw'><center id='AfMgw'></center></pre></bdo></b><th id='AfMgw'></th></span></q></dt></tr></i><div id='AfMgw'><tfoot id='AfMgw'></tfoot><dl id='AfMgw'><fieldset id='AfMgw'></fieldset></dl></div>
      2. <tfoot id='AfMgw'></tfoot>

        C# 本地化和资源文件

        时间:2023-08-26

            <tbody id='K5OaC'></tbody>

          <tfoot id='K5OaC'></tfoot>
          • <legend id='K5OaC'><style id='K5OaC'><dir id='K5OaC'><q id='K5OaC'></q></dir></style></legend>
            <i id='K5OaC'><tr id='K5OaC'><dt id='K5OaC'><q id='K5OaC'><span id='K5OaC'><b id='K5OaC'><form id='K5OaC'><ins id='K5OaC'></ins><ul id='K5OaC'></ul><sub id='K5OaC'></sub></form><legend id='K5OaC'></legend><bdo id='K5OaC'><pre id='K5OaC'><center id='K5OaC'></center></pre></bdo></b><th id='K5OaC'></th></span></q></dt></tr></i><div id='K5OaC'><tfoot id='K5OaC'></tfoot><dl id='K5OaC'><fieldset id='K5OaC'></fieldset></dl></div>

              <small id='K5OaC'></small><noframes id='K5OaC'>

                <bdo id='K5OaC'></bdo><ul id='K5OaC'></ul>

                  本文介绍了C# 本地化和资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试在我的应用程序中进行本地化.我的解决方案中有名为ui.resx"和ui.de.resx"的 ui 资源文件.但是,我的实现中有些地方是不正确的,我很难过.

                  I'm trying to get localization working in my application. I have my ui resource files, named "ui.resx" and "ui.de.resx" in my solution. However, something in my implementation is incorrect, and I'm stumped.

                  ResourceManager res_man;
                  CultureInfo culture;
                  string exception;
                  
                  private void myForm_Load(object sender, EventArgs e)
                  {
                      culture = CultureInfo.CreateSpecificCulture("de");
                      res_man = new ResourceManager("MyApp.ui.resx", typeof(myForm).Assembly);
                      doTheThing();
                  }
                  
                  private void doTheThing()
                  {
                      try
                      {
                          BTN_save.text = ui.SAVE;
                          //Do code here
                      }
                      catch(Exception e)
                      {
                          exception = e.toString();
                      }
                  }
                  

                  当我运行程序时,它会出错并显示异常:

                  When I run the program, it errors out and exception reads:

                  异常:System.Resources.MissingManifestResourceException:找不到适合指定区域性或中性区域性的任何资源.确保ui.resx.resources"在编译时正确嵌入或链接到程序集myProgram"中,或者所需的所有附属程序集都是可加载的且完全签名的."

                  "Exception: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "ui.resx.resources" was correctly embedded or linked into assembly "myProgram" at compile time, or that all the satellite assemblies required are loadable and fully signed."

                  推荐答案

                  你应该使用你的类的全名(带命名空间)作为第一个参数,比如:

                  You should use the full name (with namespace) of your class as first parameter lik:

                  var resman= new ResourceManager("Sample.Resources", typeof(Resources).Assembly);
                  

                  要知道应该使用什么名称,请打开 ui.resx 节点下的 ui.cs 并查看类的命名空间和类名并使用它们如上图.

                  To know what name you should use, open ui.cs under the ui.resx node and look at the namespace of the class and the class name and use them as shown above.

                  注意不要传"MyApp.ui.resx",而是传"MyApp.ui"

                  然后您可以简单地使用管理器来获取特定文化的资源,如下所示:

                  Then you can simply use the manager to get a resource for specific culture like this:

                  var str = resman.GetString("YourResourceKey", culture);
                  

                  注意:

                  您应该注意的另一件事是,阅读特定文化资源的方法更简单.您可以简单地设置:

                  Another thing you should notice, there is more simple way to read culture specific resources. You can simply set :

                  var culture= ...    
                  
                  System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
                  System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                  

                  设置文化后,无论您在何处使用,例如 MyApp.Ui.Key,都将使用特定于该文化的 Key 的值.

                  After setting culture, wherever you use for example MyApp.Ui.Key the value of the Key specific to that culture will be used.

                  这篇关于C# 本地化和资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:本地化:如何将文化信息映射到脚本名称或 Unico 下一篇:用户消息中的多个

                  相关文章

                  最新文章

                • <i id='h9RCK'><tr id='h9RCK'><dt id='h9RCK'><q id='h9RCK'><span id='h9RCK'><b id='h9RCK'><form id='h9RCK'><ins id='h9RCK'></ins><ul id='h9RCK'></ul><sub id='h9RCK'></sub></form><legend id='h9RCK'></legend><bdo id='h9RCK'><pre id='h9RCK'><center id='h9RCK'></center></pre></bdo></b><th id='h9RCK'></th></span></q></dt></tr></i><div id='h9RCK'><tfoot id='h9RCK'></tfoot><dl id='h9RCK'><fieldset id='h9RCK'></fieldset></dl></div>

                  • <bdo id='h9RCK'></bdo><ul id='h9RCK'></ul>
                  <tfoot id='h9RCK'></tfoot><legend id='h9RCK'><style id='h9RCK'><dir id='h9RCK'><q id='h9RCK'></q></dir></style></legend>
                • <small id='h9RCK'></small><noframes id='h9RCK'>