我们有一个名为Resouce.NL.resx
的{{1}}文件。此文件包含特定语言的翻译。但是,资源文件中还没有很多@Html.GetResource()
个参数。
我现在必须遍历每个.cshtml
文件以手动添加所有这些资源。
是否有工具或 extionsion 来获取资源文件中尚不存在的@Html.GetResource()
个.cshtml
个文件?
答案 0 :(得分:1)
您可以使用C#中的System.Resources.ResourceManager
将所有资源作为字典获取。
示例:
var resorces =new System.Resources.ResourceManager("YourNamespace.YourResourceFileName", Assembly.GetExecutingAssembly())
.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
.OfType<DictionaryEntry>();
Razor:您可以创建和使用自定义helper.example:
<强>助手:强>
public static class MyClass{
public static string ResourceFor<T>(this HtmlHelper html, object key) {
return new System.Resources.ResourceManager(typeof(T)).GetString(key.ToString());
}
}
使用:强>
@Html.ResourceFor<MyProject.Resouce.NL>("Test") //where `MyProject.Resouce.NL` is your resource namespace with class name