From 37e62dabd5ed6f94f9a8d0ddfbbcfb2363854032 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett (MSFT)" Date: Tue, 14 Apr 2020 13:48:46 -0700 Subject: [PATCH] Fix localizability issues in Windows Terminal (#5339) Loc issues are given to us through the internal bug tracker. * Lock some strings, or parts of strings, that should not be localized. * Switch to positional format parameters * Remove the forced newlines in the warning resources; insert them at runtime Fixes MSFT:25936156. --- src/cascadia/TerminalApp/AppLogic.cpp | 4 ++ .../Resources/en-US/Resources.resw | 48 +++++++++---------- .../TerminalConnection/AzureConnection.cpp | 6 +-- .../TerminalConnection/ConptyConnection.cpp | 4 +- .../Resources/en-US/Resources.resw | 37 ++++++++------ .../Resources/en-US/Resources.resw | 1 + 6 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 001e67675a4..316b2459000 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -339,12 +339,14 @@ namespace winrt::TerminalApp::implementation const auto errorLabel = GetLibraryResourceString(contentKey); errorRun.Text(errorLabel); warningsTextBlock.Inlines().Append(errorRun); + warningsTextBlock.Inlines().Append(Documents::LineBreak{}); if (FAILED(settingsLoadedResult)) { if (!_settingsLoadExceptionText.empty()) { warningsTextBlock.Inlines().Append(_BuildErrorRun(_settingsLoadExceptionText, ::winrt::Windows::UI::Xaml::Application::Current().as<::winrt::TerminalApp::App>().Resources())); + warningsTextBlock.Inlines().Append(Documents::LineBreak{}); } } @@ -352,6 +354,7 @@ namespace winrt::TerminalApp::implementation winrt::Windows::UI::Xaml::Documents::Run usingDefaultsRun; const auto usingDefaultsText = RS_(L"UsingDefaultSettingsText"); usingDefaultsRun.Text(usingDefaultsText); + warningsTextBlock.Inlines().Append(Documents::LineBreak{}); warningsTextBlock.Inlines().Append(usingDefaultsRun); Controls::ContentDialog dialog; @@ -388,6 +391,7 @@ namespace winrt::TerminalApp::implementation if (!warningText.empty()) { warningsTextBlock.Inlines().Append(_BuildErrorRun(warningText, ::winrt::Windows::UI::Xaml::Application::Current().as<::winrt::TerminalApp::App>().Resources())); + warningsTextBlock.Inlines().Append(Documents::LineBreak{}); } } diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index ca938c5c2da..c31ad6448a5 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -118,37 +118,30 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Settings could not be loaded from file. Check for syntax errors, including trailing commas. - + Settings could not be loaded from file. Check for syntax errors, including trailing commas. - Could not find your default profile in your list of profiles - using the first profile. Check to make sure the defaultProfile matches the GUID of one of your profiles. - + Could not find your default profile in your list of profiles - using the first profile. Check to make sure the "defaultProfile" matches the GUID of one of your profiles. + {Locked="\"defaultProfile\""} - Found multiple profiles with the same GUID in your settings file - ignoring duplicates. Make sure each profile's GUID is unique. - + Found multiple profiles with the same GUID in your settings file - ignoring duplicates. Make sure each profile's GUID is unique. - Found a profile with an invalid "colorScheme". Defaulting that profile to the default colors. Make sure that when setting a "colorScheme", the value matches the "name" of a color scheme in the "schemes" list. - + Found a profile with an invalid "colorScheme". Defaulting that profile to the default colors. Make sure that when setting a "colorScheme", the value matches the "name" of a color scheme in the "schemes" list. + {Locked="\"colorScheme\"","\"name\"","\"schemes\""} - No profiles were found in your settings. - + No profiles were found in your settings. - All profiles were hidden in your settings. You must have at least one non-hidden profile. - + All profiles were hidden in your settings. You must have at least one non-hidden profile. - Settings could not be reloaded from file. Check for syntax errors, including trailing commas. - + Settings could not be reloaded from file. Check for syntax errors, including trailing commas. - -Temporarily using the Windows Terminal default settings. - + Temporarily using the Windows Terminal default settings. Failed to load settings @@ -164,6 +157,7 @@ Temporarily using the Windows Terminal default settings. https://go.microsoft.com/fwlink/?linkid=2125419 + {Locked}This is a FWLink, so it will be localized with the fwlink tool About @@ -176,21 +170,22 @@ Temporarily using the Windows Terminal default settings. Found a profile with an invalid "backgroundImage". Defaulting that profile to have no background image. Make sure that when setting a "backgroundImage", the value is a valid file path to an image. + {Locked="\"backgroundImage\""} Found a profile with an invalid "icon". Defaulting that profile to have no icon. Make sure that when setting an "icon", the value is a valid file path to an image. + {Locked="\"icon\""} The word "icon" in quotes is locked, the word icon OUTSIDE of quotes should be localized. - Warnings were found while parsing your keybindings: - + Warnings were found while parsing your keybindings: - Found a keybinding with too many strings for the "keys" array. There should only be one string value in the "keys" array. - + • Found a keybinding with too many strings for the "keys" array. There should only be one string value in the "keys" array. + {Locked="\"keys\"","•"} This glyph is a bullet, used in a bulleted list. - Found a keybinding that was missing a required parameter value. This keybinding will be ignored. - + • Found a keybinding that was missing a required parameter value. This keybinding will be ignored. + {Locked="•"} This glyph is a bullet, used in a bulleted list. An optional command, with arguments, to be spawned in the new tab or pane @@ -211,7 +206,7 @@ Temporarily using the Windows Terminal default settings. Create a new tab - Open with the given profile. Accepts either the name or guid of a profile + Open with the given profile. Accepts either the name or GUID of a profile Create a new split pane @@ -223,7 +218,8 @@ Temporarily using the Windows Terminal default settings. Create the new pane as a vertical split (think [|]) - Open in the given directory instead of the profile's set startingDirectory + Open in the given directory instead of the profile's set "startingDirectory" + {Locked="\"startingDirectory\""} Press the button to open a new terminal tab with your default profile. Open the flyout to select which profile you want to open. @@ -287,4 +283,4 @@ Temporarily using the Windows Terminal default settings. Command Prompt This is the name of "Command Prompt", as localized in Windows. The localization here should match the one in the Windows product for "Command Prompt" - \ No newline at end of file + diff --git a/src/cascadia/TerminalConnection/AzureConnection.cpp b/src/cascadia/TerminalConnection/AzureConnection.cpp index f09d440821b..57308b660c8 100644 --- a/src/cascadia/TerminalConnection/AzureConnection.cpp +++ b/src/cascadia/TerminalConnection/AzureConnection.cpp @@ -47,7 +47,7 @@ static constexpr int USER_INFO_COLOR = 97; // white - the color of clarifying in static inline std::wstring _colorize(const unsigned int colorCode, const std::wstring_view text) { - return wil::str_printf(L"\x1b[%um%.*s\x1b[m", colorCode, gsl::narrow_cast(text.size()), text.data()); + return fmt::format(L"\x1b[{0}m{1}\x1b[m", colorCode, text); } // Takes N resource names, loads the first one as a format string, and then @@ -57,12 +57,12 @@ static inline std::wstring _colorize(const unsigned int colorCode, const std::ws template static inline std::wstring _formatResWithColoredUserInputOptions(const std::wstring_view resourceKey, Args&&... args) { - return wil::str_printf(GetLibraryResourceString(resourceKey).data(), (_colorize(USER_INPUT_COLOR, GetLibraryResourceString(args)).data())...); + return fmt::format(std::wstring_view{ GetLibraryResourceString(resourceKey) }, (_colorize(USER_INPUT_COLOR, GetLibraryResourceString(args)))...); } static inline std::wstring _formatTenantLine(int tenantNumber, const std::wstring_view tenantName, const std::wstring_view tenantID) { - return wil::str_printf(RS_(L"AzureIthTenant").data(), _colorize(USER_INPUT_COLOR, std::to_wstring(tenantNumber)).data(), _colorize(USER_INFO_COLOR, tenantName).data(), tenantID.data()); + return fmt::format(std::wstring_view{ RS_(L"AzureIthTenant") }, _colorize(USER_INPUT_COLOR, std::to_wstring(tenantNumber)), _colorize(USER_INFO_COLOR, tenantName), tenantID); } namespace winrt::Microsoft::Terminal::TerminalConnection::implementation diff --git a/src/cascadia/TerminalConnection/ConptyConnection.cpp b/src/cascadia/TerminalConnection/ConptyConnection.cpp index 9c7b1cd26e8..be00982981a 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.cpp +++ b/src/cascadia/TerminalConnection/ConptyConnection.cpp @@ -246,7 +246,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // EXIT POINT const auto hr = wil::ResultFromCaughtException(); - winrt::hstring failureText{ wil::str_printf(RS_(L"ProcessFailedToLaunch").c_str(), gsl::narrow_cast(hr), _commandline.c_str()) }; + winrt::hstring failureText{ fmt::format(std::wstring_view{ RS_(L"ProcessFailedToLaunch") }, gsl::narrow_cast(hr), _commandline) }; _TerminalOutputHandlers(failureText); _transitionToState(ConnectionState::Failed); @@ -262,7 +262,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation { try { - winrt::hstring exitText{ wil::str_printf(RS_(L"ProcessExited").c_str(), status) }; + winrt::hstring exitText{ fmt::format(std::wstring_view{ RS_(L"ProcessExited") }, status) }; _TerminalOutputHandlers(L"\r\n"); _TerminalOutputHandlers(exitText); } diff --git a/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw b/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw index 464211bd5ad..ee23ddfcf9d 100644 --- a/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw @@ -124,13 +124,16 @@ Please enter the desired tenant number. - Enter %s to login with a different account + Enter {0} to login with a new account + {0} will be replaced with the resource from AzureUserEntry_NewLogin; it is intended to be a single-character shorthand for "new account" - Enter %s to remove the above saved connection settings. + Enter {0} to remove the above saved connection settings. + {0} will be replaced with the resource from AzureUserEntry_RemoveStored; it is intended to be a single-character shorthand for "remove stored" - Please enter a valid number to access the stored connection settings, %s to make a new one, or %s to remove the stored ones. + Please enter a valid number to access the stored connection settings, {0} to log in with a new account, or {1} to remove the saved connection settings. + {0} will be replaced with the resource from AzureUserEntry_NewLogin, and {1} will be replaced with AzureUserEntry_RemoveStored. This is an error message, used after AzureNewLogin/AzureRemoveStored if the user enters an invalid value. Please enter a number. @@ -143,12 +146,15 @@ You have not set up your cloud shell account yet. Please go to https://shell.azure.com to set it up. + {Locked="https://shell.azure.com"} This URL should not be localized. Everything else should. - Do you want to save these connection settings for future logins? [%s/%s] + Do you want to save these connection settings for future logins? [{0}/{1}] + {0} and {1} will be replaced with AzureUserEntry_Yes and AzureUserEntry_No. They are single-character shorthands for "yes" and "no" in this language. - Please enter %s or %s + Please enter {0} or {1} + {0} and {1} will be replaced with AzureUserEntry_Yes and AzureUserEntry_No. This resource will be used as an error response after AzureStorePrompt. Requesting a cloud shell instance... @@ -184,35 +190,36 @@ <unknown tenant name> - Tenant %s: %s (%s) + Tenant {0}: {1} ({2}) + {0} is the tenant's number, which the user will enter to connect to the tenant. {1} is the tenant's display name, which will be meaningful for the user. {2} is the tenant's internal ID number. Authenticated. n - The user must enter this character to say NEW LOGIN (AzureInvalidAccessInput, AzureNewLogin) + This is shorthand for "new login". The user must enter this character to activate the New Login feature (AzureInvalidAccessInput, AzureNewLogin) r - The user must enter this character to say REMOVE SAVED LOGINS (AzureRemoveStored, AzureInvalidAccessInput) + This is shorthand for "remove saved connections". The user must enter this character to activate the Remove Saved Logins feature (AzureRemoveStored, AzureInvalidAccessInput) y - The user must enter this character to signify YES + This is shorthand for "yes". The user must enter this character to CONFIRM a prompt. n - The user must enter this character to signify NO + This is shorthand for "no". The user must enter this character to DECLINE a prompt. - [process exited with code %u] - The first argument (%u) is the (positive) error code of the process. 0 is success. + [process exited with code {0}] + The first argument {0} is the (positive) error code of the process. When there is no error, the number ZERO will be displayed. - [error 0x%8.08x when launching `%ls'] - The first argument is the hexadecimal error code. The second is the process name. -If this resource spans multiple lines, it will not be displayed properly. Yeah. + [error {0:#08x} when launching `{1}'] + The first argument {0...} is the hexadecimal error code. The second argument {1} is the user-specified path to a program. + If this string is broken to multiple lines, it will not be displayed properly. Could not connect to telnet server. diff --git a/src/cascadia/TerminalControl/Resources/en-US/Resources.resw b/src/cascadia/TerminalControl/Resources/en-US/Resources.resw index 8bfc3c1bdd4..ed8616d2e43 100644 --- a/src/cascadia/TerminalControl/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalControl/Resources/en-US/Resources.resw @@ -163,6 +163,7 @@ Close Search Box + The explanation of the search box close button used by Narrator and other screen readers. This terminal has encountered an issue with the graphics driver and it could not recover in time. It has been suspended.