[英]How to read “.resources” file generated by “resgen.exe”?
By using resgen.exe, I can generate the "resources" file from a txt file. 通过使用resgen.exe,我可以从txt文件生成“资源”文件。 I can use the "resources" file in WPF, however I am not sure how can I populate the value in "cshtml" file.
我可以在WPF中使用“资源”文件,但是我不确定如何在“ cshtml”文件中填充值。 Any help would be appreciated.
任何帮助,将不胜感激。
Design-time .resx
files are compiled into binary .resources
blobs within .NET assemblies that are then read with the ResourceManager
class. 设计时
.resx
文件被编译为.NET程序集中的二进制.resources
blob,然后使用ResourceManager
类读取。 These blobs are essentially just key/value dictionaries. 这些Blob本质上只是键/值字典。
Like so: 像这样:
ResourceManager res = new ResourceManager("NameOfEmbedded.resources", GetType().GetExecutingAssembly());
String localizedString = res.GetString("resourceKey");
In Visual Studio will create a strongly-typed wrapper around each (non-localized) .resx
file so you don't need to remember each resource's string key and also makes it available from a static context, so all you need to do is: 在Visual Studio中,将在每个(非本地化的)
.resx
文件周围创建一个强类型的包装,因此您无需记住每个资源的字符串键,也可以在静态上下文中使用它,因此,您需要做的是:
String localizedString = Resources.ResourceKey;
(Assuming Resources
is the name of your .resx
-wrapper class) (假设
Resources
是您的.resx
-wrapper类的名称)
In your .cshtml
files, to render localized text, use the @
syntax to render accordingly: 在您的
.cshtml
文件中,要呈现本地化的文本,请使用@
语法进行相应的呈现:
<p>Hello this next text is localized: @Resources.ResourceKey</p>
This is different to WPF where you would do it like this: 这与WPF不同,在WPF中您可以这样做:
xmlns:r="MyNamespace.Properties"
<TextBlock Content="{x:Static r:Resources.ResourceKey}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.