Skip to content

Commit

Permalink
Add localization to debugger components (#6064)
Browse files Browse the repository at this point in the history
* Add localization to debugger components

This PR adds in localization via vscode.l10n.t(...) calls to the strings
used in the debugger components of vscode-csharp.

This also moves the tests that now call vscode.l10n.t to be integration tests.
Also refactored DotnetInfo to its own file to avoid pulling in vscode for unit tests.
  • Loading branch information
WardenGnaw authored Aug 9, 2023
1 parent b9c9591 commit 0614ce4
Show file tree
Hide file tree
Showing 19 changed files with 302 additions and 131 deletions.
64 changes: 63 additions & 1 deletion l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
{
"Cannot create .NET debug configurations. No workspace folder was selected.": "Cannot create .NET debug configurations. No workspace folder was selected.",
"Cannot create .NET debug configurations. The server is still initializing or has exited unexpectedly.": "Cannot create .NET debug configurations. The server is still initializing or has exited unexpectedly.",
"Cannot create .NET debug configurations. The active C# project is not within folder '{0}'.": "Cannot create .NET debug configurations. The active C# project is not within folder '{0}'.",
"Does not contain .NET Core projects.": "Does not contain .NET Core projects.",
"No launchable target found for '{0}'": "No launchable target found for '{0}'",
"Cannot resolve .NET debug configurations. The server is still initializing or has exited unexpectedly.": "Cannot resolve .NET debug configurations. The server is still initializing or has exited unexpectedly.",
"'{0}' is not an executable project.": "'{0}' is not an executable project.",
"Unable to determine debug settings for project '{0}'": "Unable to determine debug settings for project '{0}'",
"No process was selected.": "No process was selected.",
"Can't parse envFile {0} because of {1}": "Can't parse envFile {0} because of {1}",
"Open envFile": "Open envFile",
"Yes": "Yes",
"Not Now": "Not Now",
"More Information": "More Information",
"The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?": "The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?",
"Self-signed certificate sucessfully {0}": "Self-signed certificate sucessfully {0}",
"Show Output": "Show Output",
"Couldn't create self-signed certificate. See output for more information.": "Couldn't create self-signed certificate. See output for more information.",
"No executable projects": "No executable projects",
"Select the project to launch": "Select the project to launch",
"Invalid project index": "Invalid project index",
"Startup project not set": "Startup project not set",
"Use IntelliSense to find out which attributes exist for C# debugging": "Use IntelliSense to find out which attributes exist for C# debugging",
"Use hover for the description of the existing attributes": "Use hover for the description of the existing attributes",
"For further information visit {0}.": "For further information visit {0}.",
"If you have changed target frameworks, make sure to update the program path.": "If you have changed target frameworks, make sure to update the program path.",
"Enable launching a web browser when ASP.NET Core starts. For more information: {0}": "Enable launching a web browser when ASP.NET Core starts. For more information: {0}",
"For further information visit {0}": "For further information visit {0}",
"For more information about the 'console' field, see {0}": "For more information about the 'console' field, see {0}",
"WARNING": "WARNING",
"The C# extension was unable to automatically decode projects in the current workspace to create a runnable launch.json file. A template launch.json file has been created as a placeholder.\n\nIf the server is currently unable to load your project, you can attempt to resolve this by restoring any missing project dependencies (example: run 'dotnet restore') and by fixing any reported errors from building the projects in your workspace.\nIf this allows the server to now load your project then --\n * Delete this file\n * Open the Visual Studio Code command palette (View->Command Palette)\n * run the command: '.NET: Generate Assets for Build and Debug'.\n\nIf your project requires a more complex launch configuration, you may wish to delete this configuration and pick a different template using the 'Add Configuration...' button at the bottom of this file.": "The C# extension was unable to automatically decode projects in the current workspace to create a runnable launch.json file. A template launch.json file has been created as a placeholder.\n\nIf the server is currently unable to load your project, you can attempt to resolve this by restoring any missing project dependencies (example: run 'dotnet restore') and by fixing any reported errors from building the projects in your workspace.\nIf this allows the server to now load your project then --\n * Delete this file\n * Open the Visual Studio Code command palette (View->Command Palette)\n * run the command: '.NET: Generate Assets for Build and Debug'.\n\nIf your project requires a more complex launch configuration, you may wish to delete this configuration and pick a different template using the 'Add Configuration...' button at the bottom of this file.",
"Failed to parse tasks.json file": "Failed to parse tasks.json file",
"Don't Ask Again": "Don't Ask Again",
"Required assets to build and debug are missing from '{0}'. Add them?": "Required assets to build and debug are missing from '{0}'. Add them?",
"Cancel": "Cancel",
"Replace existing build and debug assets?": "Replace existing build and debug assets?",
"Unable to generate assets to build and debug. {0}.": "Unable to generate assets to build and debug. {0}.",
"Cannot load Razor language server because the directory was not found: '{0}'": "Cannot load Razor language server because the directory was not found: '{0}'",
"Could not find '{0}' in or above '{1}'.": "Could not find '{0}' in or above '{1}'.",
"Invalid trace setting for Razor language server. Defaulting to '{0}'": "Invalid trace setting for Razor language server. Defaulting to '{0}'",
Expand Down Expand Up @@ -81,5 +118,30 @@
"View Debug Docs": "View Debug Docs",
"Ignore": "Ignore",
"Run and Debug: A valid browser is not installed": "Run and Debug: A valid browser is not installed",
"Restart Language Server": "Restart Language Server"
"Restart Language Server": "Restart Language Server",
"pipeArgs must be a string or a string array type": "pipeArgs must be a string or a string array type",
"Name not defined in current configuration.": "Name not defined in current configuration.",
"Configuration \"{0}\" in launch.json does not have a {1} argument with {2} for remote process listing.": "Configuration \"{0}\" in launch.json does not have a {1} argument with {2} for remote process listing.",
"Select the process to attach to": "Select the process to attach to",
"Pipe transport failed to get OS and processes.": "Pipe transport failed to get OS and processes.",
"Operating system \"{0}\" not supported.": "Operating system \"{0}\" not supported.",
"Transport attach could not obtain processes list.": "Transport attach could not obtain processes list.",
"Error Message: ": "Error Message: ",
"See {0} output": "See {0} output",
"Failed to set extension directory": "Failed to set extension directory",
"Failed to set debugadpter directory": "Failed to set debugadpter directory",
"Failed to set install complete file path": "Failed to set install complete file path",
"Unexpected RuntimeId '{0}'.": "Unexpected RuntimeId '{0}'.",
"Ignoring non-parseable lines in envFile {0}: {1}.": "Ignoring non-parseable lines in envFile {0}: {1}.",
"Unexpected message received from debugger.": "Unexpected message received from debugger.",
"[ERROR]: C# Extension failed to install the debugger package.": "[ERROR]: C# Extension failed to install the debugger package.",
"Could not find a process id to attach.": "Could not find a process id to attach.",
"[ERROR] The debugger cannot be installed. The debugger requires macOS 10.12 (Sierra) or newer.": "[ERROR] The debugger cannot be installed. The debugger requires macOS 10.12 (Sierra) or newer.",
"[ERROR] The debugger cannot be installed. Unknown platform.": "[ERROR] The debugger cannot be installed. Unknown platform.",
"Failed to complete the installation of the C# extension. Please see the error in the output window below.": "Failed to complete the installation of the C# extension. Please see the error in the output window below.",
"An error occurred during installation of the .NET Debugger. The C# extension may need to be reinstalled.": "An error occurred during installation of the .NET Debugger. The C# extension may need to be reinstalled.",
"Get the SDK": "Get the SDK",
"Disable message in settings": "Disable message in settings",
"Help": "Help",
"The C# extension is still downloading packages. Please see progress in the output window below.": "The C# extension is still downloading packages. Please see progress in the output window below."
}
40 changes: 28 additions & 12 deletions src/coreclrDebug/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export async function activate(
// a warning was already issued, so do nothing.
if (isValidArchitecture) {
eventStream.post(
new DebuggerPrerequisiteFailure('[ERROR]: C# Extension failed to install the debugger package.')
new DebuggerPrerequisiteFailure(
vscode.l10n.t('[ERROR]: C# Extension failed to install the debugger package.')
)
);
showInstallErrorMessage(eventStream);
}
Expand All @@ -60,7 +62,7 @@ export async function activate(
const attachItem = await RemoteAttachPicker.ShowAttachEntries(args, platformInformation);
return attachItem
? attachItem.id
: Promise.reject<string>(new Error('Could not find a process id to attach.'));
: Promise.reject<string>(new Error(vscode.l10n.t('Could not find a process id to attach.')));
})
);

Expand Down Expand Up @@ -117,7 +119,9 @@ async function checkIsValidArchitecture(
) {
eventStream.post(
new DebuggerPrerequisiteFailure(
'[ERROR] The debugger cannot be installed. The debugger requires macOS 10.12 (Sierra) or newer.'
vscode.l10n.t(
'[ERROR] The debugger cannot be installed. The debugger requires macOS 10.12 (Sierra) or newer.'
)
)
);
return false;
Expand All @@ -128,7 +132,9 @@ async function checkIsValidArchitecture(
if (platformInformation.architecture === 'x86') {
eventStream.post(
new DebuggerPrerequisiteWarning(
`[WARNING]: x86 Windows is not supported by the .NET debugger. Debugging will not be available.`
vscode.l10n.t(
`[WARNING]: x86 Windows is not supported by the .NET debugger. Debugging will not be available.`
)
)
);
return false;
Expand All @@ -140,7 +146,9 @@ async function checkIsValidArchitecture(
}
}

eventStream.post(new DebuggerPrerequisiteFailure('[ERROR] The debugger cannot be installed. Unknown platform.'));
eventStream.post(
new DebuggerPrerequisiteFailure(vscode.l10n.t('[ERROR] The debugger cannot be installed. Unknown platform.'))
);
return false;
}

Expand All @@ -156,7 +164,9 @@ async function completeDebuggerInstall(
if (!isValidArchitecture) {
eventStream.post(new DebuggerNotInstalledFailure());
vscode.window.showErrorMessage(
'Failed to complete the installation of the C# extension. Please see the error in the output window below.'
vscode.l10n.t(
'Failed to complete the installation of the C# extension. Please see the error in the output window below.'
)
);
return false;
}
Expand All @@ -179,16 +189,18 @@ async function completeDebuggerInstall(
function showInstallErrorMessage(eventStream: EventStream) {
eventStream.post(new DebuggerNotInstalledFailure());
vscode.window.showErrorMessage(
'An error occurred during installation of the .NET Debugger. The C# extension may need to be reinstalled.'
vscode.l10n.t(
'An error occurred during installation of the .NET Debugger. The C# extension may need to be reinstalled.'
)
);
}

function showDotnetToolsWarning(message: string): void {
const config = vscode.workspace.getConfiguration('csharp');
if (!config.get('suppressDotnetInstallWarning', false)) {
const getDotNetMessage = 'Get the SDK';
const goToSettingsMessage = 'Disable message in settings';
const helpMessage = 'Help';
const getDotNetMessage = vscode.l10n.t('Get the SDK');
const goToSettingsMessage = vscode.l10n.t('Disable message in settings');
const helpMessage = vscode.l10n.t('Help');
// Buttons are shown in right-to-left order, with a close button to the right of everything;
// getDotNetMessage will be the first button, then goToSettingsMessage, then the close button.
vscode.window.showErrorMessage(message, goToSettingsMessage, getDotNetMessage, helpMessage).then((value) => {
Expand Down Expand Up @@ -248,7 +260,9 @@ export class DebugAdapterExecutableFactory implements vscode.DebugAdapterDescrip
if (!installLock) {
this.eventStream.post(new DebuggerNotInstalledFailure());
throw new Error(
'The C# extension is still downloading packages. Please see progress in the output window below.'
vscode.l10n.t(
'The C# extension is still downloading packages. Please see progress in the output window below.'
)
);
}
// install.complete does not exist, check dotnetCLI to see if we can complete.
Expand All @@ -262,7 +276,9 @@ export class DebugAdapterExecutableFactory implements vscode.DebugAdapterDescrip
if (!success) {
this.eventStream.post(new DebuggerNotInstalledFailure());
throw new Error(
'Failed to complete the installation of the C# extension. Please see the error in the output window below.'
vscode.l10n.t(
'Failed to complete the installation of the C# extension. Please see the error in the output window below.'
)
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/coreclrDebug/debuggerEventsProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';

// This contains the definition of messages that VsDbg-UI can send back to a listener which registers itself via the 'debuggerEventsPipeName'
// property on a launch or attach request.
//
Expand All @@ -28,7 +30,7 @@ export interface ProcessLaunchedEvent extends DebuggerEvent {
export function decodePacket(packet: Buffer): DebuggerEvent {
// Verify the message ends in a newline
if (packet[packet.length - 1] != 10 /*\n*/) {
throw new Error('Unexpected message received from debugger.');
throw new Error(vscode.l10n.t('Unexpected message received from debugger.'));
}

const message = packet.toString('utf-8', 0, packet.length - 1);
Expand Down
7 changes: 6 additions & 1 deletion src/coreclrDebug/parsedEnvironmentFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as fs from 'fs';

export class ParsedEnvironmentFile {
Expand Down Expand Up @@ -66,7 +67,11 @@ export class ParsedEnvironmentFile {
// show error message if single lines cannot get parsed
let warning: string | undefined;
if (parseErrors.length !== 0) {
warning = `Ignoring non-parseable lines in envFile ${envFile}: ${parseErrors.join(', ')}.`;
warning = vscode.l10n.t(
'Ignoring non-parseable lines in envFile {0}: {1}.',
envFile,
parseErrors.join(', ')
);
}

return new ParsedEnvironmentFile(env, warning);
Expand Down
Loading

0 comments on commit 0614ce4

Please sign in to comment.