wpf 未生成资源文件代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17942588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resource file code not generated
提问by TRS
I have my default resource file Resources.resxfor which visual studio nicely generates a designer.csclass, but when I try to create Resources.de-DE.resx, it does not generate.
我有我的默认资源文件Resources.resx,visual studio 很好地为其生成了一个designer.cs类,但是当我尝试创建时Resources.de-DE.resx,它不会生成。
I checked all the properties for both files are same.
我检查了两个文件的所有属性都相同。
It does generate for Resources1.resx, but not for Resources.de-DE.resxor Resources.en-US.resx.
它确实生成 for Resources1.resx,但不生成forResources.de-DE.resx或Resources.en-US.resx。
采纳答案by loop
hello @TRS you may be confused about that there is a Designer.cspresent For Resources.resxand there should be someDesigner.csfor Resources.de-DE.resxbut this is not the case because designer file would be same for all the resource files. and also the property that is created in Designer.csis also common that means you will use this property for every conversion so the difference that you can make is on the basis of ResourceCulture.
你好@TRS,您可能对Resources.resx存在Designer.cs感到困惑,Resources.de-DE.resx应该有someDesigner.cs,但事实并非如此,因为设计器文件对于所有资源文件。并且在Designer.cs 中创建的属性也很常见,这意味着您将在每次转换时使用此属性,因此您可以根据 ResourceCulture 做出不同。
回答by Sud
Yes, Designer resx file remains empty. you should follow the below steps, it will work 100%. 1) Create Resource.resx file under any folder
是的,Designer resx 文件保持为空。您应该按照以下步骤操作,它将 100% 工作。1)在任意文件夹下创建Resource.resx文件
2) set CustomTools = PublicResXFileCodeGenerator and Build Action = Embedded Resource in Resource.resx file property.
2) 在 Resource.resx 文件属性中设置 CustomTools = PublicResXFileCodeGenerator 和 Build Action = Embedded Resource。
3) Now create the different language files like below, Resources.en-US.resx Resources.nl-NL.resx etc
3) 现在创建不同的语言文件,如下所示,Resources.en-US.resx Resources.nl-NL.resx 等
4)If MVC, in your MVC Model refer this namespace as project.folder
4)如果是MVC,在你的MVC模型中将此命名空间称为project.folder
5) change the one of the property as below (example)
5)更改属性之一如下(示例)
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MMM/yyyy}"), Display(Name = "dtMovinDate",ResourceType = typeof(Resources.Resource))]
public DateTime dtMovinDate { get; set; }
6)
6)
In config file add this under System.web
<globalization enableClientBasedCulture="true" culture="en-US" uiCulture="en-US" />
7) rebuild the project and test it.
7) 重建工程并测试。
It will work. The real reason of designer.cs file empty is resource designer.cs will refer these files based on your web.config file.
它会起作用。Designer.cs 文件为空的真正原因是资源designer.cs 将根据您的web.config 文件引用这些文件。
回答by Wael Alshabani
Interestingly, I had similar situation today. I will share the scenario and solution here because I think it's related to your question.
有趣的是,我今天也遇到了类似的情况。我将在这里分享场景和解决方案,因为我认为这与您的问题有关。
I wanted to have a resource file for Arabic culture only, SharedResources.ar.resx, and I don't have another resource called SharedResources.resx.
我只想有一个阿拉伯文化的资源文件SharedResources.ar.resx,我没有另一个名为SharedResources.resx.
The solution was to create the resource file with single [dot] in it, then rename it.
解决方案是创建包含单个 [点] 的资源文件,然后重命名它。
For example, in my case, I created the file with this name, SharedResources-ar.resx. Then double click and change its access modifier to public using the editor, like this:
例如,在我的例子中,我创建了这个名称的文件,SharedResources-ar.resx. 然后双击并使用编辑器将其访问修饰符更改为 public,如下所示:
This will generate .cs file with the correct static properties.
After that, rename the file to the correct format. SharedResources.ar.resx. Otherwise it will not be generated!
这将生成具有正确静态属性的 .cs 文件。之后,将文件重命名为正确的格式。SharedResources.ar.resx. 否则不会生成!
I don't know if it's a good solution, but solve my problem and hope to solve someone's else too.
我不知道这是否是一个好的解决方案,但解决了我的问题并希望也解决其他人的问题。


