Skip to content

ApplicationLanguages.PrimaryLanguageOverride cannot be unset #5335

Open
@whiskhub

Description

@whiskhub

Describe the bug

The Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride property by default returns an empty string (if the app has not set a language override before). However, once a language override was set, it can no longer be unset to remove the override. Setting PrimaryLanguageOverride = "" or PrimaryLanguageOverride = null will both throw an exception.

In comparison, Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride does allow setting an empty string, which will clear the previous override. However setting Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride will not clear the Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride property for packaged apps, so it is only an incomplete workaround.

The following check must be changed to also allow an empty string:

bool isValidLanguageTag = IsWellFormedTag(language.c_str());

Steps to reproduce the bug

  1. Set the override to some language, e.g. Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "fr-FR";
  2. Try to unset the override, e.g. Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "";

Expected behavior

No exception is thrown when an empty string is set, and the language override will be reset.

Screenshots

No response

NuGet package version

Windows App SDK 1.7.1: 1.7.250401001

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 24H2 (22621, October 2024 Update)

IDE

Visual Studio 2022

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions