-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add persistent output locale override setting #6310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| #include "COMContext.h" | ||
| #include <AppInstallerFileLogger.h> | ||
| #include <winget/OutputDebugStringLogger.h> | ||
| #include <winrt/Windows.Globalization.h> | ||
| #include "Public/ShutdownMonitoring.h" | ||
|
|
||
| #ifndef AICLI_DISABLE_TEST_HOOKS | ||
|
|
@@ -78,6 +79,18 @@ namespace AppInstaller::CLI | |
| main.Wait = WaitOnMainWaitEvent; | ||
| ShutdownMonitoring::ServerShutdownSynchronization::AddComponent(main); | ||
| } | ||
|
|
||
| std::optional<std::string> ApplyOutputLocaleOverride() | ||
| { | ||
| std::string localePreference = Settings::User().Get<Settings::Setting::OutputLocale>(); | ||
| if (!localePreference.empty()) | ||
| { | ||
| winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride(Utility::ConvertToUTF16(localePreference)); | ||
| return localePreference; | ||
| } | ||
|
|
||
| return {}; | ||
| } | ||
| } | ||
|
|
||
| int CoreMain(int argc, wchar_t const** argv) try | ||
|
|
@@ -88,8 +101,7 @@ namespace AppInstaller::CLI | |
|
|
||
| std::signal(SIGABRT, abort_signal_handler); | ||
|
|
||
| init_apartment(); | ||
|
|
||
| init_apartment() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing ; |
||
| #ifndef AICLI_DISABLE_TEST_HOOKS | ||
| // We have to do this here so the auto minidump config initialization gets caught | ||
| Logging::OutputDebugStringLogger::Add(); | ||
|
|
@@ -120,6 +132,12 @@ namespace AppInstaller::CLI | |
| Logging::OutputDebugStringLogger::Remove(); | ||
| Logging::EnableWilFailureTelemetry(); | ||
|
|
||
| std::optional<std::string> outputLocaleOverride = ApplyOutputLocaleOverride(); | ||
| if (outputLocaleOverride) | ||
| { | ||
| AICLI_LOG(CLI, Info, << "Applied output locale override from settings: " << outputLocaleOverride.value()); | ||
| } | ||
|
|
||
| // Set output to UTF8 | ||
| ConsoleOutputCPRestore utf8CP(CP_UTF8); | ||
|
|
||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes to the wapproj were required for me to be able to verify the functionality locally with |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -925,6 +925,46 @@ TEST_CASE("SettingOutputSortDirection", "[settings]") | |
| } | ||
| } | ||
|
|
||
| TEST_CASE("SettingOutputLocale", "[settings]") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a case for "valid, unsupported locale" |
||
| { | ||
| auto again = DeleteUserSettingsFiles(); | ||
|
|
||
| SECTION("Default value") | ||
| { | ||
| UserSettingsTest userSettingTest; | ||
|
|
||
| REQUIRE(userSettingTest.Get<Setting::OutputLocale>().empty()); | ||
| REQUIRE(userSettingTest.GetWarnings().size() == 0); | ||
| } | ||
| SECTION("Valid locale") | ||
| { | ||
| std::string_view json = R"({ "output": { "locale": "en-US" } })"; | ||
| SetSetting(Stream::PrimaryUserSettings, json); | ||
| UserSettingsTest userSettingTest; | ||
|
|
||
| REQUIRE(userSettingTest.Get<Setting::OutputLocale>() == "en-US"); | ||
| REQUIRE(userSettingTest.GetWarnings().size() == 0); | ||
| } | ||
| SECTION("Invalid locale") | ||
| { | ||
| std::string_view json = R"({ "output": { "locale": "en_US.UTF-8" } })"; | ||
| SetSetting(Stream::PrimaryUserSettings, json); | ||
| UserSettingsTest userSettingTest; | ||
|
|
||
| REQUIRE(userSettingTest.Get<Setting::OutputLocale>().empty()); | ||
| REQUIRE(userSettingTest.GetWarnings().size() == 1); | ||
| } | ||
| SECTION("Wrong type") | ||
| { | ||
| std::string_view json = R"({ "output": { "locale": ["en-US"] } })"; | ||
| SetSetting(Stream::PrimaryUserSettings, json); | ||
| UserSettingsTest userSettingTest; | ||
|
|
||
| REQUIRE(userSettingTest.Get<Setting::OutputLocale>().empty()); | ||
| REQUIRE(userSettingTest.GetWarnings().size() == 1); | ||
| } | ||
| } | ||
|
|
||
| TEST_CASE("ConvertToSortField", "[settings]") | ||
| { | ||
| SECTION("Valid values - lowercase") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -561,6 +561,16 @@ namespace AppInstaller::Settings | |
|
|
||
| return {}; | ||
| } | ||
|
|
||
| WINGET_VALIDATE_SIGNATURE(OutputLocale) | ||
| { | ||
| if (Locale::IsWellFormedBcp47Tag(value)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also be checking that it is one of our supported locales? |
||
| { | ||
| return value; | ||
| } | ||
|
|
||
| return {}; | ||
| } | ||
| } | ||
|
|
||
| #ifndef AICLI_DISABLE_TEST_HOOKS | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit of a stretch, but would it make sense to put this in the
visualsettings?