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

6953: use native locale when comparing command names #8017

Closed
wants to merge 6 commits into from

Conversation

Don-Vito
Copy link
Contributor

@Don-Vito Don-Vito commented Oct 22, 2020

Summary of the Pull Request

Sort the names in the command palette based on the user level localization settings

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

Loading user local when palette is created (to perform caching and ensure consistent behavior). Using WINAPI's GetUserDefaultLocaleName explicitly to retrieve the user's default locale, as std::locale("") crashes.

Validation Steps Performed

  • Tried to set the system locale to Hebrew. Got the same result as when using English locale... so at least it doesn't regress 😄
  • Played with a debugger and some Russian chars, seem to do the job - but this is of course not a perfect testing
  • Someone speaking (and typing) a character-rich language could help 😄

@ghost ghost added Area-Localization Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. labels Oct 22, 2020
@Don-Vito
Copy link
Contributor Author

Don-Vito commented Oct 22, 2020

@PankajBhojwani - Do not merge this 😄. This is still not ready - with the std::locale("") i am getting an access violation. Hopefully, tomorrow I will windbg it (need symbols and stuff).

Everything works with std::locale(), which is not surprising, as this is a default. But it probably means that the problem is not with the code, but rather with the "", which is somehow not considered valid. I believe we can also resolve this by explicitly obtaining user locale via an API.

@Don-Vito
Copy link
Contributor Author

Accidentally wrote this in the ticket rather than here - was able to workaround by explicitly calling GetUserDefaultLocaleName. I still need to cleanup the code, but hope you can take a look and let me know what you think.

return std::locale();
}

std::wstring loadedLocale(userLocaleName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: std::wstring loadedLocale{ userLocaleName };

(we prefer using curly braces for variable initialization)

@Don-Vito Don-Vito marked this pull request as ready for review October 25, 2020 22:36
Copy link
Contributor

@PankajBhojwani PankajBhojwani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you for the contribution

@PankajBhojwani PankajBhojwani added the Needs-Second It's a PR that needs another sign-off label Oct 27, 2020
@@ -795,6 +828,7 @@ namespace winrt::TerminalApp::implementation
const bool addAll = searchText.empty();

auto commandsToFilter = _commandsToFilter();
auto pfnCompareCommandNames = std::bind(&CommandPalette::_compareCommandNames, this, std::placeholders::_1, std::placeholders::_2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DHowett, didn't we have a better option than std::bind?

// Loading user locale name explicitly using GetUserDefaultLocaleName,
// as std:locale("") crashes on some setups.
wchar_t userLocaleName[LOCALE_NAME_MAX_LENGTH + 1];
auto localeNameSize = GetUserDefaultLocaleName(userLocaleName, ARRAYSIZE(userLocaleName));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShawnSteele, is this an appropriate way of getting the locale for std::locale and using it to compare correctly below?

@zadjii-msft zadjii-msft self-assigned this Oct 28, 2020
@Don-Vito
Copy link
Contributor Author

Abandoning this one. It is blocked for more than 3 weeks already and with all the changes requires a complete rework. I can try to work on this again, if it is still relevant. I hope other blocking PRs will have a better fate 😊

@Don-Vito Don-Vito closed this Nov 18, 2020
@zadjii-msft
Copy link
Member

Hey @Don-Vito, sorry for the delays in getting back to you on this one. It must've been lost in all the other PR's 😆

Part of me thinks that the better solution to this problem is what was outlined over in #7039. Apparently VSCode displays both the localized command name, but also the English one (the un-localized one), and then the palette filters based off the English string. I don't know if there is an easy way at getting at the en-us version of a resource from a non-en-us build of an app.

I also don't know if it only does that for Chinese, Japanese, Korean, but not German or other latin scripts - that might need to be investigated more.

@Don-Vito
Copy link
Contributor Author

Don-Vito commented Nov 19, 2020

Hey @Don-Vito, sorry for the delays in getting back to you on this one. It must've been lost in all the other PR's 😆

Part of me thinks that the better solution to this problem is what was outlined over in #7039. Apparently VSCode displays both the localized command name, but also the English one (the un-localized one), and then the palette filters based off the English string. I don't know if there is an easy way at getting at the en-us version of a resource from a non-en-us build of an app.

I also don't know if it only does that for Chinese, Japanese, Korean, but not German or other latin scripts - that might need to be investigated more.

@zadjii-msft - I am actually tracking this #7039 for a while, and agree that it suggests a better solution (I guess not localizing the palette is even better, but I cannot say for everyone). I think yo need to close one of them as they seem quite mutually exclusive - no?

@zadjii-msft
Copy link
Member

They sure do, don't they!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Localization Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Second It's a PR that needs another sign-off Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants