我有两个文件:Resources.resx和Resources.de.resx.

Resources.de.resx只包含一个已翻译的值.我使用以下方法加载所有资源键/值:
ResourceSet resourceSet = Resources.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true);
Run Code Online (Sandbox Code Playgroud)
当我第一次加载资源集时,我的Thread.CurrentThread.CurrentCulture.Name是空字符串,Thread.CurrentThread.CurrentCulture.NativeName ="Invariant Language(Invariant Country)",Thread.CurrentThread.CurrentCulture.LCID = 127.
因此,资源集有200个键,其值从Resources.resx按预期加载.然后我使用以下代码切换当前文化,该代码通过单击按钮触发:
Thread.CurrentThread.CurrentCulture = new CultureInfo("de");
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
Run Code Online (Sandbox Code Playgroud)
当我现在加载资源集时,我在集合中只有一个键.它是Resources.de.resx的翻译密钥.但我仍然期望有200个键,只有一个项目被翻译成德语(de)语言.
当前德语(de)文化的父文化是与我第一次调用该方法获取资源集时相同的不变语言文化.基本上,由于某些原因看起来后备不起作用.你能告诉我我做错了什么吗?
您必须从不变文化中获取所有键,然后才能查找所有翻译。所以回退有效。
查找到的资源可以存储在字典中。
var keys = Resources.ResourceManager
.GetResourceSet(CultureInfo.InvariantCulture, true, true)
.Cast<DictionaryEntry>()
.Select(entry => entry.Key)
.Cast<string>();
var enUsResources = keys.ToDictionary(
key => key,
key => Resources.ResourceManager.GetString(key, CultureInfo.GetCultureInfo("de")));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1096 次 |
| 最近记录: |