[英]How do I create a neutral fallback satellite resource for localization in C#.?
I am trying to modify an existing WPF application for localization. 我正在尝试修改现有的WPF应用程序以进行本地化。 One of my restrictions is that all resources (including the default en-US fallback resource) have to be satellite resources. 我的限制之一是所有资源(包括默认的美国后备资源)必须是卫星资源。 None of them can be embedded in the main assembly. 它们都不能嵌入到主部件中。
Through some reading on codeplex, I found that all I need to do is make the following change in my AssemblyInfo.cs file. 通过对Codeplex的阅读,我发现我需要做的就是在AssemblyInfo.cs文件中进行以下更改。
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
When I do this, I get an exception on application startup saying: 当我这样做时,我在应用程序启动时遇到一个异常:
Could not find any resources appropriate for the specified culture or the neutral culture. 找不到适合于指定区域性或中性区域性的任何资源。 Make sure "XXX.YYY.ZZZ.g.en-US.resources" was correctly embedded or linked into assembly "XXX.YYY.ZZZ" at compile time, or that all the satellite assemblies required are loadable and fully signed. 确保在编译时已将“ XXX.YYY.ZZZ.g.en-US.resources”正确地嵌入或链接到程序集“ XXX.YYY.ZZZ”中,或者确保所需的所有附属程序集均已加载并完全签名。
If I switch back to putting the fallback resource (en-US) in the main assembly, everything works fine again. 如果我转回将后备资源(en-US)放入主程序集中,则一切正常。 From what I've read, if you want to have the fallback resource as a satellite resource, you must have a specific resource for that locale (ie you must have a Resources.en-US.resx). 根据我的阅读,如果您希望将后备资源作为卫星资源,则必须具有针对该语言环境的特定资源(即,必须具有Resources.en-US.resx)。 Am I correct? 我对么?
What seems fishy to me in the exception is the g (.g.en-US). 在我看来,除了g(.g.en-US)之外,我似乎很讨厌。 Does that signify something? 这表示什么吗? The g doesn't exist in any of my resource files? 我的任何资源文件中都不存在g?
Am I creating my resources correctly. 我在正确创建资源吗? I first create a generic Resources.resx file, put all my strings in it. 我首先创建一个通用的Resources.resx文件,并将所有字符串放入其中。 Then, I simply copy/paste within Visual Studio and rename for each specific locale (ar, es-MX, etc.). 然后,我只需在Visual Studio中复制/粘贴并为每个特定的语言环境(ar,es-MX等)重命名。 Then, make the appropriate translations. 然后,进行适当的翻译。
For now, I am just focusing on one projects resource files. 现在,我仅关注一个项目资源文件。 Maybe it's getting hung up on a different project that doesn't have an en-US version of it's resource file?? 也许它挂在另一个没有资源文件的美国版的项目上了? If so, is there any way to get Visual Studio to tell me more about what it's really getting hung up on? 如果是这样,是否有任何方法可以使Visual Studio告诉我有关它真正挂在身上的更多信息?
In short, your understanding of the resource files and what needs built seems correct. 简而言之,您对资源文件和需要构建的内容的理解似乎是正确的。
The .g is for the compiled XAML files and built for you automatically. .g用于已编译的XAML文件,并自动为您构建。 Nothing special or magical going on here. 这里没有什么特别的或不可思议的事情。
Normally the fallback resource is embedded in the main assembly. 通常,后备资源嵌入在主程序集中。 If you are not doing that, you must create a satellite resource assembly for every culture you are going to do, plus an en-US one. 如果您不这样做,则必须为要进行的每种文化创建一个卫星资源程序集,以及一个美国英语版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.