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

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

      <legend id='LRqWE'><style id='LRqWE'><dir id='LRqWE'><q id='LRqWE'></q></dir></style></legend>

        <bdo id='LRqWE'></bdo><ul id='LRqWE'></ul>
      1. C# 类库本地化

        时间:2023-08-26
      2. <tfoot id='m5DDD'></tfoot>
          <tbody id='m5DDD'></tbody>
        <legend id='m5DDD'><style id='m5DDD'><dir id='m5DDD'><q id='m5DDD'></q></dir></style></legend>

          • <small id='m5DDD'></small><noframes id='m5DDD'>

            • <bdo id='m5DDD'></bdo><ul id='m5DDD'></ul>

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

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

                  问题描述

                  我需要快速了解类库中的本地化

                  I need a very quick introduction to localization in a class library

                  我对从用户上下文中提取语言环境不感兴趣,而是我将用户存储在数据库中,并且他们的语言环境也在数据库中设置....

                  I am not interested in pulling the locale from the user context, rather I have users stored in the db, and their locale is also setup in the db....

                  我在类库中的函数已经可以从数据库中的用户配置文件中提取语言环境代码...现在我想根据语言环境包含使用 resx...

                  my functions in the class library can already pull the locale code from the user profile in the db... now I want to include use resx depending on locale...

                  我需要几个步骤才能正确执行此操作...

                  I need a few steps to do this correctly...

                  是的 - 我已经用谷歌搜索了这个,并进行了一些研究,但我能找到的所有教程都太复杂了,无法满足我的需求.

                  And yeah - I have already googled this, and some research, but all the tutorials I can find are way too complex for my needs.

                  推荐答案

                  不幸的是,这个主题太复杂了.;) 我知道,我也做过研究.

                  Unfortunately, this subject is way too complicated. ;) I know, I've done the research as well.

                  为了让你开始,

                  1. 在您的程序集中创建一个 Resources 目录.

                  1. create a Resources directory in your assembly.

                  从英语开始,然后将资源文件"(.resx) 添加到该目录.将其命名为text.resx".如果找不到本地化资源,应用程序将默认拉出该文件.

                  Start with English and add a "Resources File" (.resx) to that directory. Name it something like "text.resx". In the event that the localized resource can't be found, the app will default to pulling out of this file.

                  添加您的文本资源.

                  添加另一个资源文件.将其命名为text.es.resx".注意文件名的es"部分.在这种情况下,这定义了西班牙语.请注意,每种语言都有自己的字符代码定义.查一下.

                  Add another resources file. Name this one something like "text.es.resx" Note the "es" part of the file name. In this case, that defines spanish. Note that each language has it's own character code definition. Look that up.

                  将您的西班牙语资源添加到其中.

                  Add your spanish resources to it.

                  现在我们有了可以使用的资源文件,让我们尝试实现.

                  Now that we have resource files to work from, let's try to implement.

                  为了设置文化,从您的数据库记录中提取它.然后执行以下操作:

                  In order to set the culture, pull that from your database record. Then do the following:

                  String culture = "es-MX"; // defines spanish culture
                  Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
                  Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
                  

                  这可能发生在已加载程序集的应用程序或程序集初始化本身中.你选.

                  This could happen in the app that has loaded your assembly OR in the assembly initialization itself. You pick.

                  要利用资源,您只需在程序集中执行以下操作:

                  To utlize the resource, all you have to do is something like the following within your assembly:

                  public string TestMessage() {
                    return Resources.Text.SomeTextValue;
                  }
                  

                  达达.资源变得容易.如果您需要更改用户控件或直接在 aspx 页面中执行某些操作,事情可能会变得更复杂一些.如果您需要更多信息,请更新您的问题.

                  Ta Da. Resources made easy. Things can get a little more complicated if you need to change usercontrols or do something directly in an aspx page. Update your question if you need more info.

                  请注意,您可以拥有名为text.es-mx.resx"的资源文件,这将是特定于墨西哥西班牙语的.但是,这并不总是必要的,因为es-mx"会在回退到默认值之前回退到es".只有您自己知道您的资源需要有多具体.

                  Note that you could have resource files named like "text.es-mx.resx" That would be specific to mexican spanish. However, that's not always necessary because "es-mx" will fall back to "es" before it falls back to the default. Only you will know how specific your resources need to be.

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

                  上一篇:带有自定义 ResourceProvider 的 DataAnnotation 下一篇:带有 json 文件的 Asp.net Core 本地化

                  相关文章

                  最新文章

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

                  3. <small id='emwM5'></small><noframes id='emwM5'>

                      <legend id='emwM5'><style id='emwM5'><dir id='emwM5'><q id='emwM5'></q></dir></style></legend>