-
Notifications
You must be signed in to change notification settings - Fork 249
Localization: document NeutralLanguage requirement and runtime culture switching pattern #3255
Description
Summary
The localization documentation is missing two pieces of guidance:
NeutralLanguagemust be set in the.csproj— without it,ResourceManagermay returnnullfor default-culture lookups at runtime, causing silent fallback failures instead of a clear error.- Runtime culture switching — the docs show how to set up localized resources, but do not document the
LocalizationResourceManagerpattern that allows users to switch language at runtime without restarting the app.
Why it matters
Missing NeutralLanguage
If <NeutralLanguage> is not set in the .csproj, resource lookups for the default language may silently return null instead of the expected string. The app shows blank labels with no error — extremely hard to diagnose because it only happens for the default culture (other cultures work fine via satellite assemblies).
No runtime switching pattern
Many apps need a "change language" settings page. The official docs show resource file setup and XAML x:Static bindings, but these bindings do not update when the culture changes at runtime. Developers need a LocalizationResourceManager pattern that raises PropertyChanged to trigger XAML rebinding.
What should be documented
NeutralLanguage requirement
Add to the setup section:
<!-- .csproj — Always set NeutralLanguage -->
<PropertyGroup>
<NeutralLanguage>en-US</NeutralLanguage>
</PropertyGroup>Warning: Without
NeutralLanguageset,ResourceManagermay returnnullfor default-culture string lookups at runtime. Always set this property to match your default.resxfile's culture.
Runtime culture switching
Document the LocalizationResourceManager pattern:
public class LocalizationResourceManager : INotifyPropertyChanged
{
public static LocalizationResourceManager Instance { get; } = new();
public string this[string key] => AppResources.ResourceManager.GetString(key, CultureInfo.CurrentUICulture) ?? key;
public event PropertyChangedEventHandler? PropertyChanged;
public void SetCulture(CultureInfo culture)
{
CultureInfo.CurrentUICulture = culture;
CultureInfo.CurrentCulture = culture;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null));
}
}<!-- XAML binding that updates when culture changes -->
<Label Text="{Binding [WelcomeMessage], Source={x:Static local:LocalizationResourceManager.Instance}}" />Suggested location
docs/fundamentals/localization.md — add NeutralLanguage to the setup section; add a new "Switch language at runtime" section