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

Add a language switcher using PrimaryLanguageOverride #10309

Merged
7 commits merged into from
Jun 10, 2021

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Jun 2, 2021

Summary of the Pull Request

This PR adds a global "language" setting, which may be set to any supported BCP 47 tag.
Additionally a ComboBox is added to the settings UI under "Appearance", listing all languages with their localized names.

This PR introduces one new issue: If you change the language while the app is running, the UI will be in a torn state, as not all UI elements refresh automatically if the PrimaryLanguageOverride is changed.

PR Checklist

Validation Steps Performed

  • UI language changes when changing the "language" in settings.json before starting WT / while WT is running. ✔️
  • "language" field is removed from settings.json if "Use system default" is selected. ✔️
  • "language" field is added or updated in settings.json if any other language is selected. ✔️
  • Removes qps- languages if debugFeatures is false. ✔️
  • Correctly refreshes all UI elements with the new language. ❌

@lhecker lhecker requested a review from carlos-zamora June 2, 2021 00:52
@ghost ghost added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. labels Jun 2, 2021
@lhecker lhecker force-pushed the dev/lhecker/language-setting branch 2 times, most recently from 48a2cd9 to 8e7b994 Compare June 2, 2021 01:01
@microsoft microsoft deleted a comment from github-actions bot Jun 2, 2021
@microsoft microsoft deleted a comment from github-actions bot Jun 2, 2021
@lhecker lhecker force-pushed the dev/lhecker/language-setting branch from 8e7b994 to d92f4ca Compare June 2, 2021 01:04
@lhecker lhecker force-pushed the dev/lhecker/language-setting branch from d92f4ca to 249f152 Compare June 2, 2021 01:12
@@ -25,40 +25,39 @@

#include <wil/cppwinrt.h>

#include <unknwn.h>

#include <hstring.h>
Copy link
Member Author

Choose a reason for hiding this comment

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

Since I had to add <winrt/Windows.Globalization.h> to some pch.h files I decided to cleaned them up by removing unused includes and ordering and reordered the includes alphabetically.

Copy link
Member

Choose a reason for hiding this comment

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

be careful! you must include unknwn and hstring BEFORE any c++/winrt headers; wil is also sensitive to include order (!)

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed those entirely, because it compiles without them.

<!-- Theme -->
<local:SettingContainer x:Uid="Globals_Theme"
<!-- Language -->
<local:SettingContainer x:Uid="Globals_Language"
Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure where I should put the ComboBox. Would it look better elsewhere? Maybe not as the first item in the Appearances section?
The reason I put it as the first item was simply because I thought it looked nicer that way.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine for now. Ideally, this would go into some kind of "General" page, but we're just not there yet imo.

@cinnamon-msft thoughts?

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

Mostly nits.

Concerned about the torn state where some stuff stays localized and other stuff doesn't update.

Comment on lines 60 to 61
// Returns an array of {"und", "en-US", "de-DE", "es-ES", ...}.
// "und" is short for "undefined" and is synonym for "Use system language" in this code.
Copy link
Member

Choose a reason for hiding this comment

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

nit: follow the format we use for method descriptions

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I had hoped we only use that format for existing code/files...
It's rather verbose and sometimes redundant. (I'll change this comment.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I've extended the comment, better detailing what it does...
If you don't mind I'll wait for others to concur with you until I change the style to what I perceive as the more verbose form.

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 2, 2021
@DHowett
Copy link
Member

DHowett commented Jun 2, 2021

regarding the resw file: please re-save it using visual studio to "repair" the spacing 😄

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 2, 2021
@lhecker
Copy link
Member Author

lhecker commented Jun 2, 2021

@DHowett @carlos-zamora If I change something in the .resw file and re-save it the spaces continue to be gone.
Would you like me to revert the changes to the trailing whitespace regardless?

@DHowett
Copy link
Member

DHowett commented Jun 2, 2021

I am surprised about that. I guess we can just commit it; the next person to change it using VS will reintroduce them. 😄

@lhecker
Copy link
Member Author

lhecker commented Jun 2, 2021

Oooooh... Nevermind... Apparently VS Code suppresses whitespace differences by default in the diff viewer!

@github-actions

This comment has been minimized.

@marypq
Copy link

marypq commented Jun 3, 2021

X

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

I cannot find fault with this. Very well done!

@@ -5,6 +5,10 @@
#include "GlobalAppearance.h"
#include "GlobalAppearance.g.cpp"
#include "GlobalAppearancePageNavigationState.g.cpp"

#include <LibraryResources.h>
Copy link
Member

Choose a reason for hiding this comment

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

This should be part of the precompiled header precomp.h or pch.h and not be necessary here

<numeric> should be in LibraryIncludes

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure putting it into <LibraryIncludes> or the pch.h file is a good idea?
<numeric> is basically only used in 2 places throughout the project.

@DHowett
Copy link
Member

DHowett commented Jun 3, 2021

Now, what happens if:

  • the user sets language to qps-ploc in their json while debugFeatures is false?
  • the user sets language to foo-bar in their json?

@lhecker
Copy link
Member Author

lhecker commented Jun 3, 2021

@DHowett This PR """abuses""" the fact that the SUI saves the settings.json and triggers a settings reload in AppLogic. Then in AppLogic I compare the "language" settings value with the one returned by PrimaryLanguageOverride(). If they're different I call PrimaryLanguageOverride(newLanguage) (see AppLogic.cpp).
This means you can basically write whatever you want into the settings.json, without being constrained to what the SUI allows you to do. 🙂

@DHowett
Copy link
Member

DHowett commented Jun 3, 2021

@DHowett This PR """abuses""" the fact that the SUI saves the settings.json and triggers a settings reload in AppLogic. Then in AppLogic I compare the "language" settings value with the one returned by PrimaryLanguageOverride(). If they're different I call PrimaryLanguageOverride(newLanguage) (see AppLogic.cpp).

This means you can basically write whatever you want into the settings.json, without being constrained to what the SUI allows you to do. 🙂

Indeed. I'm just hoping that it doesn't crash or overwrite the setting or do something weird if the JSON value doesn't exist in the actual language Combo list.

if (!_State.Globals().DebugFeaturesEnabled())
{
// [4] part 1:
it = std::remove_if(it, tagsEnd, [](const winrt::hstring& tag) mutable -> bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

@DHowett FYI I just realized this is a programming error and should be std::remove_if(tagsBegin, it, ...) instead. std::unique returns an iterator for the new end of the range, which I have to use instead of tagsEnd here.

Copy link
Member

@carlos-zamora carlos-zamora 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! Just create a follow-up task for...

  1. Settings UI not being reloaded entirely
    • offline discussion: looks like you need to reload all of the NavigationView's menu items and also reload the page footer (with the save button)
  2. Command Palette sometimes not reloading (nested?) commands

@lhecker lhecker added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jun 10, 2021
@ghost
Copy link

ghost commented Jun 10, 2021

Hello @lhecker!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit e34897c into main Jun 10, 2021
@ghost ghost deleted the dev/lhecker/language-setting branch June 10, 2021 23:24
@ghost
Copy link

ghost commented Jul 14, 2021

🎉Windows Terminal Preview v1.10.1933.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Choose language in settings.json
4 participants