Skip to content
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

PTRun UnitConvert - Cannot use en-US abbreviations in other localizations #22257

Closed
Tantalus13A98B5F opened this issue Nov 23, 2022 · 5 comments
Labels
Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams

Comments

@Tantalus13A98B5F
Copy link
Contributor

Microsoft PowerToys version

0.64.1

Installation method

Microsoft Store

Running as admin

No response

Area(s) with issue?

PowerToys Run

Steps to reproduce

  1. Set the locale to zh-CN
  2. %%1 ft in m
  3. %%1 foot in meter
  4. %%1 feet in meters
  5. %%1 英尺 - 米

✔️ Expected Behavior

  1. 0.3048 m
  2. 0.3048 meter
  3. 0.3048 meters
  4. 0.3048 米

❌ Actual Behavior

  1. failed
  2. 0.3048 meter
  3. failed
  4. 0.3048 米

Other Software

No response

@Tantalus13A98B5F Tantalus13A98B5F added Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Nov 23, 2022
@Tantalus13A98B5F
Copy link
Contributor Author

Tantalus13A98B5F commented Nov 23, 2022

This looks very similar to #21472 but in fact different. This is a localization issue.

According to the following code, we only accept a unit in the following format,

private static Enum GetUnitEnum(string unit, QuantityInfo unitInfo)
{
UnitInfo first = Array.Find(unitInfo.UnitInfos, info =>
unit.ToLowerInvariant() == info.Name.ToLowerInvariant() || unit.ToLowerInvariant() == info.PluralName.ToLowerInvariant());
if (first != null)
{
return first.Value;
}
if (UnitParser.Default.TryParse(unit, unitInfo.UnitType, out Enum enum_unit))
{
return enum_unit;
}
return null;
}

  • in its full name or plural form in English, e.g. foot, meter, meters, but not feet which is always translated to ft here
    /// <summary>
    /// The plural form "feet" is not recognized by UniteNets. Replace it with "ft".
    /// </summary>
    public static void FeetToFt(ref string[] split)
  • in its abbreviations defined in the current locale, e.g. 英尺,
  • in its abbreviations defined in the en-US locale, only if no abbreviations are defined for the current locale, and that's why ft and m are not accepted.

@Tantalus13A98B5F
Copy link
Contributor Author

Tantalus13A98B5F commented Nov 23, 2022

The shadowing of localized abbreviations over English abbreviations is defined by UnitsNet. However, the Chinese would also use ft and m, as 英尺 and are more like full names in Chinese. Also, there are many other units (e.g. km/h) for which no Chinese abbreviations have been defined in UnitsNet, and thus we have to keep a careful mixture of English and Chinese abbreviations, like,

  • 1 mph in km/h but not 1 英里每小时 in 千米每小时
  • 1 英里 in 千米 but not 1 mile in km

To resolve this twisted condition, one can initiate a systematic fix on the UnitsNet side. However, before that, I'd suggest that we do a two step lookup in PTRun, the first step in the current locale, and the second step in en-US.

A potential fix which works well on my side is at #22270

@jaimecbernardo
Copy link
Collaborator

That fix you did on #22270 looks good. It's essentially a fallback to en-US culture if all else fails. You can mark that as ready for review once you feel it's ready ;) Thank you!

@Tantalus13A98B5F
Copy link
Contributor Author

Thank you! I've marked it as ready.

@jaimecbernardo
Copy link
Collaborator

The code for this issue has been released in 0.65. Please update PowerToys to the latest version:
https://github.com/microsoft/PowerToys/releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams
Projects
None yet
Development

No branches or pull requests

2 participants