From d809e5610784cc4bebf1cf32414742b482f3983d Mon Sep 17 00:00:00 2001 From: Beena352 Date: Mon, 29 Dec 2025 09:34:14 -0800 Subject: [PATCH 1/5] Localize wsladiag user-facing messages --- localization/strings/en-US/Resources.resw | 48 ++++++++++++++++++++++- src/windows/wsladiag/wsladiag.cpp | 35 ++++++++++++----- 2 files changed, 73 insertions(+), 10 deletions(-) diff --git a/localization/strings/en-US/Resources.resw b/localization/strings/en-US/Resources.resw index 0e20a4e83..6a69641bd 100644 --- a/localization/strings/en-US/Resources.resw +++ b/localization/strings/en-US/Resources.resw @@ -1871,4 +1871,50 @@ You can also access more VS Code Remote options through the command palette with The number of milliseconds that a VM is idle, before it is shut down. - + + The number of milliseconds that a VM is idle, before it is shut down. + + + wsladiag - WSLA diagnostics tool +Usage: + wsladiag list + wsladiag shell <SessionName> [--verbose] + wsladiag --help + {Locked="wsladiag"}{Locked="list"}{Locked="shell"}{Locked="--verbose"}{Locked="--help"}Command line arguments should not be translated + + + Session not found: '{}' + {FixedPlaceholder="{}"}String insert should not be translated + + + OpenSessionByName('{}') failed + {FixedPlaceholder="{}"}String insert should not be translated + + + No WSLA sessions found. + + + Found {} WSLA session(s): + {FixedPlaceholder="{}"}String insert should not be translated + + + {} exited with: {} + {FixedPlaceholder="{}"}String inserts should not be translated + + + (signalled) + + + ID + + + Creator PID + + + Display Name + + + Unknown command: '{}' + {FixedPlaceholder="{}"}String insert should not be translated + + \ No newline at end of file diff --git a/src/windows/wsladiag/wsladiag.cpp b/src/windows/wsladiag/wsladiag.cpp index eef2f3150..2af638649 100644 --- a/src/windows/wsladiag/wsladiag.cpp +++ b/src/windows/wsladiag/wsladiag.cpp @@ -23,6 +23,9 @@ Module Name: using namespace wsl::shared; namespace wslutil = wsl::windows::common::wslutil; +using wsl::shared::Localization; +using wsl::windows::common::Context; +using wsl::windows::common::ExecutionContext; using wsl::windows::common::WSLAProcessLauncher; // Adding a helper to factor error handling between all the arguments. @@ -64,11 +67,11 @@ static int RunShellCommand(const std::wstring& sessionName, bool verbose) { if (hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) { - wslutil::PrintMessage(std::format(L"Session not found: '{}'", sessionName), stderr); + wslutil::PrintMessage(Localization::MessageWslaSessionNotFound(sessionName.c_str()), stderr); return 1; } - return ReportError(std::format(L"OpenSessionByName('{}') failed", sessionName), hr); + return ReportError(Localization::MessageWslaOpenSessionFailed(sessionName.c_str()), hr); } log(L"[diag] OpenSessionByName succeeded"); @@ -182,7 +185,8 @@ static int RunShellCommand(const std::wstring& sessionName, bool verbose) auto [code, signalled] = process.GetExitState(); std::wstring shellWide(shell.begin(), shell.end()); - wslutil::PrintMessage(std::format(L"{} exited with: {}{}", shellWide, code, signalled ? L" (signalled)" : L""), stdout); + wslutil::PrintMessage( + Localization::MessageWslaShellExited(shellWide.c_str(), exitCode) + (signalled ? Localization::MessageWslaShellSignalled() : L""), stdout); return 0; } @@ -198,11 +202,11 @@ static int RunListCommand(bool /*verbose*/) if (sessions.size() == 0) { - wslutil::PrintMessage(L"No WSLA sessions found.", stdout); + wslutil::PrintMessage(Localization::MessageWslaNoSessionsFound(), stdout); return 0; } - wslutil::PrintMessage(std::format(L"Found {} WSLA session{}:", sessions.size(), sessions.size() > 1 ? L"s" : L""), stdout); + wslutil::PrintMessage(Localization::MessageWslaSessionsFound(sessions.size()), stdout); // Compute column widths from headers + data (same pattern as wsl --list). size_t idWidth = wcslen(L"ID"); @@ -215,12 +219,19 @@ static int RunListCommand(bool /*verbose*/) } // Header - wprintf(L"%-*ls %-*ls %ls\n", static_cast(idWidth), L"ID", static_cast(pidWidth), L"Creator PID", L"Display Name"); + wprintf( + L"%-*ls %-*ls %ls\n", + static_cast(idWidth), + Localization::MessageWslaHeaderId().c_str(), + static_cast(pidWidth), + Localization::MessageWslaHeaderCreatorPid().c_str(), + Localization::MessageWslaHeaderDisplayName().c_str()); // Underline std::wstring idDash(idWidth, L'-'); std::wstring pidDash(pidWidth, L'-'); - std::wstring nameDash(wcslen(L"Display Name"), L'-'); + size_t nameWidth = Localization::MessageWslaHeaderDisplayName().size(); + std::wstring nameDash(nameWidth, L'-'); wprintf( L"%-*ls %-*ls %ls\n", static_cast(idWidth), idDash.c_str(), static_cast(pidWidth), pidDash.c_str(), nameDash.c_str()); @@ -240,6 +251,11 @@ static int RunListCommand(bool /*verbose*/) return 0; } +static void PrintUsage() +{ + wslutil::PrintMessage(Localization::MessageWsladiagUsage(), stderr); +} + int wsladiag_main(std::wstring_view commandLine) { wslutil::ConfigureCrt(); @@ -314,8 +330,9 @@ int wsladiag_main(std::wstring_view commandLine) } else { - wslutil::PrintMessage(std::format(L"Unknown command: '{}'", verb), stderr); - printUsage(); + wslutil::PrintMessage(Localization::MessageWslaUnknownCommand(verb.c_str()), stderr); + PrintUsage(); + return 1; } } From 7ddb400e6b14d50a9022856a154d0ff86f06ffe8 Mon Sep 17 00:00:00 2001 From: Beena352 Date: Mon, 29 Dec 2025 13:07:47 -0800 Subject: [PATCH 2/5] Localize wsladiag messages and fix list output formatting --- localization/strings/en-US/Resources.resw | 79 +++++++++++------------ src/windows/wsladiag/wsladiag.cpp | 53 ++++++++++----- 2 files changed, 75 insertions(+), 57 deletions(-) diff --git a/localization/strings/en-US/Resources.resw b/localization/strings/en-US/Resources.resw index 6a69641bd..d65673b16 100644 --- a/localization/strings/en-US/Resources.resw +++ b/localization/strings/en-US/Resources.resw @@ -1871,50 +1871,47 @@ You can also access more VS Code Remote options through the command palette with The number of milliseconds that a VM is idle, before it is shut down. - - The number of milliseconds that a VM is idle, before it is shut down. - - wsladiag - WSLA diagnostics tool + wsladiag - WSLA diagnostics tool Usage: wsladiag list wsladiag shell <SessionName> [--verbose] wsladiag --help - {Locked="wsladiag"}{Locked="list"}{Locked="shell"}{Locked="--verbose"}{Locked="--help"}Command line arguments should not be translated - - - Session not found: '{}' - {FixedPlaceholder="{}"}String insert should not be translated - - - OpenSessionByName('{}') failed - {FixedPlaceholder="{}"}String insert should not be translated - - - No WSLA sessions found. - - - Found {} WSLA session(s): - {FixedPlaceholder="{}"}String insert should not be translated - - - {} exited with: {} - {FixedPlaceholder="{}"}String inserts should not be translated - - - (signalled) - - - ID - - - Creator PID - - - Display Name - - - Unknown command: '{}' - {FixedPlaceholder="{}"}String insert should not be translated - + {Locked="--verbose]"}{Locked="--help"}Command line arguments, file names and string inserts should not be translated + + + Session not found: '{}' + {FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated + + + OpenSessionByName('{}') failed + {FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated + + + No WSLA sessions found. + + + Found {} WSLA session(s): + {FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated + + + {} exited with: {} + {FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated + + + (signalled) + + + ID + + + Creator PID + + + Display Name + + + Unknown command: '{}' + {FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated + \ No newline at end of file diff --git a/src/windows/wsladiag/wsladiag.cpp b/src/windows/wsladiag/wsladiag.cpp index 2af638649..04f32d0c2 100644 --- a/src/windows/wsladiag/wsladiag.cpp +++ b/src/windows/wsladiag/wsladiag.cpp @@ -31,15 +31,15 @@ using wsl::windows::common::WSLAProcessLauncher; // Adding a helper to factor error handling between all the arguments. static int ReportError(const std::wstring& context, HRESULT hr) { - const std::wstring hrMessage = wslutil::ErrorCodeToString(hr); + const std::wstring hrMessage = wslutil::GetErrorString(hr); if (!hrMessage.empty()) { - wslutil::PrintMessage(std::format(L"{}: 0x{:08x} - {}", context, static_cast(hr), hrMessage), stderr); + wslutil::PrintMessage(std::format(L"{}: 0x{:08x} - {}", context, static_cast(hr), hrMessage), stderr); } else { - wslutil::PrintMessage(std::format(L"{}: 0x{:08x}", context, static_cast(hr)), stderr); + wslutil::PrintMessage(std::format(L"{}: 0x{:08x}", context, static_cast(hr)), stderr); } return 1; @@ -185,8 +185,14 @@ static int RunShellCommand(const std::wstring& sessionName, bool verbose) auto [code, signalled] = process.GetExitState(); std::wstring shellWide(shell.begin(), shell.end()); - wslutil::PrintMessage( - Localization::MessageWslaShellExited(shellWide.c_str(), exitCode) + (signalled ? Localization::MessageWslaShellSignalled() : L""), stdout); + std::wstring message = Localization::MessageWslaShellExited(shellWide.c_str(), exitCode); + + if (signalled) + { + message += Localization::MessageWslaShellSignalled(); + } + + wslutil::PrintMessage(message, stdout); return 0; } @@ -208,44 +214,59 @@ static int RunListCommand(bool /*verbose*/) wslutil::PrintMessage(Localization::MessageWslaSessionsFound(sessions.size()), stdout); - // Compute column widths from headers + data (same pattern as wsl --list). - size_t idWidth = wcslen(L"ID"); - size_t pidWidth = wcslen(L"Creator PID"); + // Compute column widths from headers + data . + const auto idHeader = Localization::MessageWslaHeaderId(); + const auto pidHeader = Localization::MessageWslaHeaderCreatorPid(); + const auto nameHeader = Localization::MessageWslaHeaderDisplayName(); + + size_t idWidth = idHeader.size(); + size_t pidWidth = pidHeader.size(); + size_t nameWidth = nameHeader.size(); for (const auto& s : sessions) { idWidth = std::max(idWidth, std::to_wstring(s.SessionId).size()); pidWidth = std::max(pidWidth, std::to_wstring(s.CreatorPid).size()); + nameWidth = std::max(nameWidth, static_cast(s.DisplayName ? wcslen(s.DisplayName) : 0)); } // Header wprintf( - L"%-*ls %-*ls %ls\n", + L"%-*ls %-*ls %-*ls\n", static_cast(idWidth), - Localization::MessageWslaHeaderId().c_str(), + idHeader.c_str(), static_cast(pidWidth), - Localization::MessageWslaHeaderCreatorPid().c_str(), - Localization::MessageWslaHeaderDisplayName().c_str()); + pidHeader.c_str(), + static_cast(nameWidth), + nameHeader.c_str()); // Underline std::wstring idDash(idWidth, L'-'); std::wstring pidDash(pidWidth, L'-'); - size_t nameWidth = Localization::MessageWslaHeaderDisplayName().size(); std::wstring nameDash(nameWidth, L'-'); wprintf( - L"%-*ls %-*ls %ls\n", static_cast(idWidth), idDash.c_str(), static_cast(pidWidth), pidDash.c_str(), nameDash.c_str()); + L"%-*ls %-*ls %-*ls\n", + static_cast(idWidth), + idDash.c_str(), + static_cast(pidWidth), + pidDash.c_str(), + static_cast(nameWidth), + nameDash.c_str()); // Rows for (const auto& s : sessions) { + const wchar_t* displayName = s.DisplayName ? s.DisplayName : L""; + wprintf( - L"%-*lu %-*lu %ls\n", + L"%-*lu %-*lu %-*ls\n", static_cast(idWidth), static_cast(s.SessionId), static_cast(pidWidth), static_cast(s.CreatorPid), - s.DisplayName); + static_cast(nameWidth), + displayName); } return 0; From fe55bf7d5d949eb2dfc4f9bf80f205728dc83119 Mon Sep 17 00:00:00 2001 From: Beena352 Date: Tue, 30 Dec 2025 13:34:18 -0800 Subject: [PATCH 3/5] Fix undefined variable --- src/windows/wsladiag/wsladiag.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/wsladiag/wsladiag.cpp b/src/windows/wsladiag/wsladiag.cpp index 04f32d0c2..14dc511f5 100644 --- a/src/windows/wsladiag/wsladiag.cpp +++ b/src/windows/wsladiag/wsladiag.cpp @@ -182,7 +182,7 @@ static int RunShellCommand(const std::wstring& sessionName, bool verbose) wsl::windows::common::relay::InterruptableRelay(ttyOut.get(), consoleOut, exitEvent.get()); process.GetExitEvent().wait(); - auto [code, signalled] = process.GetExitState(); + auto [exitCode, signalled] = process.GetExitState(); std::wstring shellWide(shell.begin(), shell.end()); std::wstring message = Localization::MessageWslaShellExited(shellWide.c_str(), exitCode); From 88e20d2ce95c9b2e0888a134c4da254af2cb13d7 Mon Sep 17 00:00:00 2001 From: Beena352 Date: Fri, 2 Jan 2026 07:48:54 -0800 Subject: [PATCH 4/5] Apply Copilot suggestions --- localization/strings/en-US/Resources.resw | 2 +- src/windows/wsladiag/wsladiag.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/localization/strings/en-US/Resources.resw b/localization/strings/en-US/Resources.resw index d65673b16..f56f27ebc 100644 --- a/localization/strings/en-US/Resources.resw +++ b/localization/strings/en-US/Resources.resw @@ -1877,7 +1877,7 @@ Usage: wsladiag list wsladiag shell <SessionName> [--verbose] wsladiag --help - {Locked="--verbose]"}{Locked="--help"}Command line arguments, file names and string inserts should not be translated + {Locked="--verbose"}{Locked="--help"}Command line arguments, file names and string inserts should not be translated Session not found: '{}' diff --git a/src/windows/wsladiag/wsladiag.cpp b/src/windows/wsladiag/wsladiag.cpp index 14dc511f5..95c08c7ad 100644 --- a/src/windows/wsladiag/wsladiag.cpp +++ b/src/windows/wsladiag/wsladiag.cpp @@ -213,7 +213,6 @@ static int RunListCommand(bool /*verbose*/) } wslutil::PrintMessage(Localization::MessageWslaSessionsFound(sessions.size()), stdout); - // Compute column widths from headers + data . const auto idHeader = Localization::MessageWslaHeaderId(); const auto pidHeader = Localization::MessageWslaHeaderCreatorPid(); From 57c5c1de84bdcbfd0b56220fb056f6b5aa624d17 Mon Sep 17 00:00:00 2001 From: Beena352 Date: Fri, 2 Jan 2026 10:18:49 -0800 Subject: [PATCH 5/5] Restore correct locked token for wsladiag usage localization --- localization/strings/en-US/Resources.resw | 2 +- src/windows/wsladiag/wsladiag.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/localization/strings/en-US/Resources.resw b/localization/strings/en-US/Resources.resw index f56f27ebc..d65673b16 100644 --- a/localization/strings/en-US/Resources.resw +++ b/localization/strings/en-US/Resources.resw @@ -1877,7 +1877,7 @@ Usage: wsladiag list wsladiag shell <SessionName> [--verbose] wsladiag --help - {Locked="--verbose"}{Locked="--help"}Command line arguments, file names and string inserts should not be translated + {Locked="--verbose]"}{Locked="--help"}Command line arguments, file names and string inserts should not be translated Session not found: '{}' diff --git a/src/windows/wsladiag/wsladiag.cpp b/src/windows/wsladiag/wsladiag.cpp index 95c08c7ad..e52d0079d 100644 --- a/src/windows/wsladiag/wsladiag.cpp +++ b/src/windows/wsladiag/wsladiag.cpp @@ -213,7 +213,7 @@ static int RunListCommand(bool /*verbose*/) } wslutil::PrintMessage(Localization::MessageWslaSessionsFound(sessions.size()), stdout); - // Compute column widths from headers + data . + // Compute column widths from headers + data. const auto idHeader = Localization::MessageWslaHeaderId(); const auto pidHeader = Localization::MessageWslaHeaderCreatorPid(); const auto nameHeader = Localization::MessageWslaHeaderDisplayName();