From f56abb83c18e77a6037624a523702c274e38db62 Mon Sep 17 00:00:00 2001 From: Vaibhav Sharma <48472541+GhostVaibhav@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:36:02 +0530 Subject: [PATCH] [PT-Run] Resolving the confusion between ounces (#33962) ## Summary of the Pull Request - Replaced "ounce" to "usounce" and "imperialounce" for two different results ## PR Checklist - [x] **Closes:** #32841 - [x] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end user facing strings can be localized - [x] **Dev docs:** Added/updated - [x] **New binaries:** Added on the required places - [x] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [x] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [x] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [x] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [x] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments - Convert `ounce` to `usounce` and `imperialounce` and show the converted results ## Validation Steps Performed - Manual validation --- .github/actions/spell-check/expect.txt | 2 + .../InputInterpreter.cs | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 0cfc383559..87296b7409 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -672,6 +672,7 @@ imageresizerinput imageresizersettings imagingdevices ime +imperialounce inetcpl Infobar INFOEXAMPLE @@ -1672,6 +1673,7 @@ USERDATA Userenv USESHOWWINDOW USESTDHANDLES +usounce USRDLL UType uuidv diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs index aadab74821..3a36b3b175 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/InputInterpreter.cs @@ -237,6 +237,43 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter } } + /// + /// Choose "UsOunce" or "ImperialOunce" according to current culture when the input contains "o.z", "o.z.", "oz" or "ounce". + /// + public static void OunceHandler(ref string[] split, CultureInfo culture) + { + HashSet britishCultureNames = new HashSet() { "en-AI", "en-VG", "en-GB", "en-KY", "en-MS", "en-AG", "en-DM", "en-GD", "en-KN", "en-LC", "en-VC", "en-IE", "en-GY", "en-AE" }; + if (string.Equals(split[1], "o.z", StringComparison.OrdinalIgnoreCase) || + string.Equals(split[1], "ounce", StringComparison.OrdinalIgnoreCase) || + string.Equals(split[1], "o.z.", StringComparison.OrdinalIgnoreCase) || + string.Equals(split[1], "oz", StringComparison.OrdinalIgnoreCase)) + { + if (britishCultureNames.Contains(culture.Name)) + { + split[1] = "ImperialOunce"; + } + else + { + split[1] = "UsOunce"; + } + } + + if (string.Equals(split[3], "o.z", StringComparison.OrdinalIgnoreCase) || + string.Equals(split[3], "ounce", StringComparison.OrdinalIgnoreCase) || + string.Equals(split[3], "o.z.", StringComparison.OrdinalIgnoreCase) || + string.Equals(split[3], "oz", StringComparison.OrdinalIgnoreCase)) + { + if (britishCultureNames.Contains(culture.Name)) + { + split[3] = "ImperialOunce"; + } + else + { + split[3] = "UsOunce"; + } + } + } + public static ConvertModel Parse(Query query) { string[] split = query.Search.Split(' '); @@ -257,6 +294,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter InputInterpreter.FeetToFt(ref split); InputInterpreter.KPHHandler(ref split); InputInterpreter.GallonHandler(ref split, CultureInfo.CurrentCulture); + InputInterpreter.OunceHandler(ref split, CultureInfo.CurrentCulture); if (!double.TryParse(split[0], out double value)) { return null;