microsoft / microsoft/WindowsAppSDK
ApplicationLanguages.PrimaryLanguageOverride cannot be unset
- Dominant language
- C++
- Stars
- 4.7k
- Forks
- 471
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 28
Description
### 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: https://github.com/microsoft/WindowsAppSDK/blob/3d8013bbcaaa1cc9da3fcdf0d453d0017027493e/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ApplicationLanguages.cpp#L44
### 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_
Contributor guide
No contributing guide indexed for this repository
Research direction
Inspect dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ApplicationLanguages.cpp at the check around line 44. Reproduce the issue by setting PrimaryLanguageOverride to "fr-FR" and then to an empty string, and compare the behavior with Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride. Done means an empty string no longer throws and resets the language override.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop, internationalization
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100