c#:在 dotnet 类中,是否有一个属性表明“当前”是否为当前值。文化实际上是默认文化吗?

发布于 2024-10-27 06:10:27 字数 341 浏览 2 评论 0原文

某个类中是否有一个属性可以告诉我当前区域性是否实际上是默认区域性。

与 winform 的本地化工作方式类似。它以表格形式说明语言是否为默认语言。

假设我在 en-US - 我如何通过代码判断 en.US 是否是实际的默认值?

我需要为一些 .net 不支持的 XML 文件实现一些本地化,因此我想实现我自己的...

winforms 是如何工作的,即

nameofxml.default.xml (this is the default local)
nameofXml.de-de.xml (this is german) 

属性

是否存在?

Is there a property in some class that can tell me if the current culture is actually the default culture.

Similar to how localization works with winforms. It states in a form if the language is default.

lets say if i am in en-US - how can i tell via code if en.US is the actual default?

I need to implement some localization for some XML files which .net doesn't support hence i want to implement my own ...

And do it how winforms works i.e

nameofxml.default.xml (this is the default local)
nameofXml.de-de.xml (this is german) 

etc

does a property exist?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

记忆里有你的影子 2024-11-03 06:10:27

System.Globalization.CultureInfo.CurrentCulture 指示系统的控制面板区域设置,而 System.Globalization.CultureInfo.CurrentUICulture 对应系统的输入 UI 语言设置(您可以'除非您安装了多语言用户界面,否则请勿更改)。

因此,您可以使用以下代码片段来确定“默认”区域性:

using System.Globalization;
// N.B. execute the following line *before* you programmatically change the CurrentCulture
// (if you ever do this, of course)

// Gets the CultureInfo that represents the culture used by the current thread
CultureInfo culture = CultureInfo.CurrentCulture;
string code = culture.IetfLanguageTag; // e.g. "en-US", "de-DE", etc.

然后您可以使用 code 来查找您的 .xml 文件。

System.Globalization.CultureInfo.CurrentCulture indicates you system's Control Panel Region settings, while System.Globalization.CultureInfo.CurrentUICulture corresponds to the system's Input UI Language setting (which you can't change unless you have Multilingual User Interface installed).

Therefore you can use the following code snippet to determine the 'default' culture:

using System.Globalization;
// N.B. execute the following line *before* you programmatically change the CurrentCulture
// (if you ever do this, of course)

// Gets the CultureInfo that represents the culture used by the current thread
CultureInfo culture = CultureInfo.CurrentCulture;
string code = culture.IetfLanguageTag; // e.g. "en-US", "de-DE", etc.

Then you can use the code to locate your .xml files.

巾帼英雄 2024-11-03 06:10:27

您可以使用 NeutralResourcesLanguageAttribute

IIRC,这样,如果所需的文化是嵌入在程序集中的文化,资源管理器可以优化资源加载过程。

由于您正在滚动自己的本地化实现,我不知道这有什么用处,但您可以使用该属性来指示直接嵌入程序集中的 XML 本地化信息的区域性是特定的区域性,并且默认为搜索如果您发现程序集中声明的区域性与您正在查找的所需区域性不匹配,则附属程序集或其他自定义后台存储。

You can state at the assembly level that the embedded resources are of a specific culture by using the NeutralResourcesLanguageAttribute.

IIRC, this way the resource manager can optimize the process of resource loading if the required culture is the one embedded in the assembly.

Since you are rolling your own implementation for localization I don't know how this can be helpful, but you can use that attribute to indicate that the culture of the XML localization information embedded directly in the assembly is of a specific culture and default to searching satellite assemblies or other custom back store if you find a mismatch between the declared culture in the assembly and the required culture you are looking for.

不再让梦枯萎 2024-11-03 06:10:27

CultureInfo.CurrentCulture 是一个静态成员,“获取表示当前线程使用的区域性的 CultureInfo”。如果您只包含 System.Globalization 命名空间,则可以从任何类访问它。

文档:http://msdn.microsoft.com/en-us /library/system.globalization.cultureinfo.aspx

CultureInfo.CurrentCulture is a static member that "Gets the CultureInfo that represents the culture used by the current thread." It is accessible from any class if you just include the System.Globalization namespace.

Documentation: http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文