gpt4 book ai didi

C#:如何从某种文化中获取资源字符串

转载 作者:IT王子 更新时间:2023-10-29 04:42:37 25 4
gpt4 key购买 nike

我有一个资源集,其中包含各种语言的翻译文本。项目看起来像这样:

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

我可以像这样使用静态属性获取文本:

var value = FooBar.Hello;

或者像这样使用反射:

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

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

但是,如果我明确想要 Swedish 值,而不必更改 UI 文化,我可以做些什么吗?

最佳答案

试试下面的代码。至少对我来说效果很好:

FooBar.ResourceManager.GetString("Hello", CultureInfo.GetCultureInfo("sv-SE"))

关于C#:如何从某种文化中获取资源字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1825574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com