Share via


What does the NeutralResourcesLanguageAttribute do?

NeutralResourcesLanguageAttribute marks the neutral culture for an assembly. That sounds self-referential, but a full description would require another blog post. To avoid getting bogged down, think of neutral culture roughly as the default language. (Fingers crossed that Michael Kaplan doesn't flame me for that oversimplification.)

The NeutralResourcesLanguageAttribute does two things:

1. Can speed up resource probes.

First note that the default location for neutral resources is the main assembly. In other words:
[assembly:NeutralResourcesLanguageAttribute("en-US")]
...is the same as:
[assembly:NeutralResourcesLanguageAttribute("en-US", UltimateResourceFallbackLocation.MainAssembly)]

If you have one of the above attributes on your assembly, then the ResourceManager looks for "en-US" resources directly in the main assembly, instead of searching first in an “en-US” folder. Since resource probes can be expensive, this attribute can help improve perf.

2. Specifies a fallback culture if resource probes fail; i.e. neutral resources are the resources that should always be there.

Suppose you want to deploy an app on a machine typically set to de-DE culture. Suppose you have partially localized strings for de-DE and de, and a full set of resources for fr-FR. You can use NeutralResourcesLanguageAttribute to say fr-FR resources are always there. So if the resource probe doesn't find an entry for de-DE or de, then it will fallback to fr-FR.

You can use the accompanying attribute UltimateResourceFallbackLocation.Satellite to say these resources are located in a satellite assembly, i.e.:
[assembly:NeutralResourcesLanguageAttribute("fr-FR", UltimateResourceFallbackLocation.MainAssembly)]

Comments