gpt4 book ai didi

.NET ResourceManager.GetResourceSet : "en-GB" not working on english resource

转载 作者:行者123 更新时间:2023-12-03 04:27:58 24 4
gpt4 key购买 nike

.NET 中有没有办法进行以下调用:

ResourceManager.GetResourceSet(new CultureInfo("en-GB"), true, false)
ResourceManager.GetResourceSet(new CultureInfo("en-US"), true, false)

也适用于非英国(仅“en”)资源,例如:

Resources.en.resx

如果没有“en-GB.resx/en-US.resx” - 上面定义的文件调用将始终返回 null。如果找不到更具体的文件(如 en-GB.resx 或 en-US.resx),我希望它们回退到默认的 en.resx。

注意:将 GetResourceSet (tryParaments) 的第三个参数设置为 true 只会返回默认的非标记 Resources.resx 文件,即使在 CultureInfos 父属性中设置了 en。

最佳答案

您必须从不变文化中获取所有键,然后才能查找所有翻译。所以后备有效。

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("en-US")));

关于.NET ResourceManager.GetResourceSet : "en-GB" not working on english resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26992032/

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