简体   繁体   中英

How do I create a neutral fallback satellite resource for localization in C#.?

I am trying to modify an existing WPF application for localization. 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.

[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.

If I switch back to putting the fallback resource (en-US) in the main assembly, everything works fine again. 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). Am I correct?

What seems fishy to me in the exception is the g (.g.en-US). Does that signify something? The g doesn't exist in any of my resource files?

Am I creating my resources correctly. I first create a generic Resources.resx file, put all my strings in it. Then, I simply copy/paste within Visual Studio and rename for each specific locale (ar, es-MX, etc.). 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?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM