Frimlik
Frimlik

Reputation: 429

.NET ResourceManager - using neutral culture localization file for specific culture

Maybe a stupid question, but I wonder what is the ResourceManager strategy of selecting specific localization file and localized strings if only neutral culture localization files (en, de etc.) are available (or a combination of neutral and specific culture), but specific culture (en-GB, de-DE etc.) is selected. Any link to documentation is appreciated.

Upvotes: 0

Views: 416

Answers (1)

NightOwl888
NightOwl888

Reputation: 56869

ResourceManager by default will fallback by calling CultureInfo.Parent (using the CultureInfo.CurrentUICulture property if not provided) until a matching resource is found. If no localized resource is found in any of those locations, it will fallback to the culture (and optionally the UltimateResourceFallbackLocation) that is set in the NeutralResourcesLanguageAttribute.

[assembly: NeutralResourcesLanguageAttribute("en", UltimateResourceFallbackLocation.MainAssembly)] 

To specify to fallback to the invariant culture, use an empty string.

[assembly: NeutralResourcesLanguageAttribute("", UltimateResourceFallbackLocation.MainAssembly)] 

To specify that the resource is in a satellite assembly, use UltimateResourceFallbackLocation.SatelliteAssembly.

For example you set de-DE as the CultureInfo.CurrentUICulture:

CultureInfo.CurrentUICulture = new CultureInfo("de-DE");

ResourceManager will first attempt to find the resource in a de-DE localized resource. If it doesn't exist, then it will attempt to use de. If the resource is still not found, it will fallback to the culture and assembly in NeutralResourcesLanguageAttribute.

Reference: https://flylib.com/books/en/3.147.1.43/1/

Upvotes: 1

Related Questions