C#:如何从一个特定的文化得到资源字符串 [英] C#: How to get a resource string from a certain culture

查看:112
本文介绍了C#:如何从一个特定的文化得到资源字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有各种语言的翻译文本资源集。项目那种看起来是这样的:

I have a resource assembly with translated texts in various languages. Project kind of looks like this:


  • FooBar.resx

  • FooBar.nb-NO.resx

  • FooBar.sv-SE.resx

  • ...

  • FooBar.resx
  • FooBar.nb-NO.resx
  • FooBar.sv-SE.resx
  • ...

我可以使用静态属性这样的文本得到:

I can get the texts using static properties like this:

var value = FooBar.Hello;

或使用反射像这样:

var value = resourceAssembly
      .GetType("Namespace.FooBar")
      .GetProperty("Hello")
      .GetValue(null, null) as string;



这两种方式都会让我属于当前线程的当前UI文化的价值。这是很好的,完全是我通常会喜欢的。

Both ways will get me the value belonging to the current UI culture of the current thread. Which is fine and totally what I would usually like.

不过,有东西,如果我明确地想例如瑞典的价值,我可以做,而不必更改UI文化是什么?

But, is there something I can do if I explicitly want for example the Swedish value, without having to change the UI culture?

推荐答案

您可以手动更改Foobar的文化属性类的Visual Studio生成。或者,如果您是直接使用 ResourceManager类,可以使用的过载的GetString ,是以所需的文化作为一个参数。

You can manually change the Culture property of the FooBar class that Visual Studio generates. Or if you are directly using the ResourceManager class, you can use the overload of GetString that takes the desired culture as a parameter.

这篇关于C#:如何从一个特定的文化得到资源字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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