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 48a7170e62..7f66e58319 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 @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation +// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text.RegularExpressions; @@ -151,6 +152,53 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter } } + /// + /// The plural form "feet" is not recognized by UniteNets. Replace it with "ft". + /// + public static void FeetToFt(ref string[] split) + { + if (split[1].ToLower() == "feet") + { + split[1] = "ft"; + } + + if (split[3].ToLower() == "feet") + { + split[3] = "ft"; + } + } + + /// + /// Choose "UsGallon" or "ImperialGallon" according to current culture when the input contains "gal" or "gallon". + /// + public static void GallonHandler(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 (split[1].ToLower() == "gal" || split[1].ToLower() == "gallon") + { + if (britishCultureNames.Contains(culture.Name)) + { + split[1] = "ImperialGallon"; + } + else + { + split[1] = "UsGallon"; + } + } + + if (split[3].ToLower() == "gal" || split[3].ToLower() == "gallon") + { + if (britishCultureNames.Contains(culture.Name)) + { + split[3] = "ImperialGallon"; + } + else + { + split[3] = "UsGallon"; + } + } + } + public static ConvertModel Parse(Query query) { string[] split = query.Search.Split(' '); @@ -167,6 +215,8 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter } InputInterpreter.DegreePrefixer(ref split); + InputInterpreter.FeetToFt(ref split); + InputInterpreter.GallonHandler(ref split, CultureInfo.CurrentCulture); if (!double.TryParse(split[0], out double value)) { return null;