C#类库本地化 [英] C# Class Library Localization

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

问题描述

我需要在类库一个非常快速的介绍本地化

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

我不感兴趣,从用户上下文拉动区域,而我已经存储在用户DB和他们的语言环境也是在DB设置....

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...

和耶 - 我已经用Google搜索这一点,一些研究,但我能看到的是我的需要太复杂的教程

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.

要utlize的资源,你所要做的就是像你的组件中的以下内容:

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#类库本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆