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

Enable loading translated strings from razor TS code #5962

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: Issue with Razor (Blazor) tooling
url: https://github.com/dotnet/razor-tooling/issues/new/choose
about: Please open issues relating to the Razor tooling in dotnet/razor-tooling.
url: https://github.com/dotnet/razor/issues/new/choose
about: Please open issues relating to the Razor tooling in dotnet/razor.
3 changes: 2 additions & 1 deletion src/razor/razor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
import * as l10n from '@vscode/l10n';
import * as Razor from '../../src/razor/src/extension';
import { EventStream } from '../eventStream';

Expand All @@ -23,7 +24,7 @@ export async function activateRazorExtension(
await Razor.activate(vscode, context, languageServerDir, eventStream, /* enableProposedApis: */ false);
} else {
vscode.window.showWarningMessage(
`Cannot load Razor language server because the directory was not found: '${languageServerDir}'`
l10n.t("Cannot load Razor language server because the directory was not found: '{0}'", languageServerDir)
);
}
}
17 changes: 12 additions & 5 deletions src/razor/src/blazorDebug/blazorDebugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { promises, readFileSync } from 'fs';
import { join } from 'path';
import { fileURLToPath } from 'url';
import * as vscode from 'vscode';
import * as l10n from '@vscode/l10n';
import { ChromeBrowserFinder, EdgeBrowserFinder } from 'vscode-js-debug-browsers';
import { RazorLogger } from '../razorLogger';
import { JS_DEBUG_NAME, SERVER_APP_NAME } from './constants';
Expand All @@ -15,7 +16,9 @@ import showInformationMessage from '../../../shared/observers/utils/showInformat
import showErrorMessage from '../../../observers/utils/showErrorMessage';

export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
private static readonly autoDetectUserNotice = `Run and Debug: auto-detection found {0} for a launch browser`;
private static readonly autoDetectUserNotice = l10n.t(
'Run and Debug: auto-detection found {0} for a launch browser'
);
private static readonly edgeBrowserType = 'msedge';
private static readonly chromeBrowserType = 'chrome';

Expand Down Expand Up @@ -162,9 +165,13 @@ export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurati
await this.vscodeType.debug.startDebugging(folder, browser);
} catch (error) {
this.logger.logError('[DEBUGGER] Error when launching browser debugger: ', error as Error);
const message = `There was an unexpected error while launching your debugging session. Check the console for helpful logs and visit the debugging docs for more info.`;
this.vscodeType.window.showErrorMessage(message, `View Debug Docs`, `Ignore`).then(async (result) => {
if (result === 'View Debug Docs') {
const message = l10n.t(
'There was an unexpected error while launching your debugging session. Check the console for helpful logs and visit the debugging docs for more info.'
);
const viewDebugDocs = l10n.t('View Debug Docs');
const ignore = l10n.t('Ignore');
phil-allen-msft marked this conversation as resolved.
Show resolved Hide resolved
this.vscodeType.window.showErrorMessage(message, viewDebugDocs, ignore).then(async (result) => {
if (result === viewDebugDocs) {
const debugDocsUri = 'https://aka.ms/blazorwasmcodedebug';
await this.vscodeType.commands.executeCommand(`vcode.open`, debugDocsUri);
}
Expand All @@ -189,7 +196,7 @@ export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurati
return this.edgeBrowserType;
}

showErrorMessage(vscode, 'Run and Debug: A valid browser is not installed');
showErrorMessage(vscode, l10n.t('Run and Debug: A valid browser is not installed'));
return undefined;
}
}
3 changes: 2 additions & 1 deletion src/razor/src/codeLens/razorCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as l10n from '@vscode/l10n';
import { RazorDocumentChangeKind } from '../document/razorDocumentChangeKind';
import { RazorDocumentManager } from '../document/razorDocumentManager';
import { RazorDocumentSynchronizer } from '../document/razorDocumentSynchronizer';
Expand Down Expand Up @@ -144,7 +145,7 @@ export class RazorCodeLensProvider extends RazorLanguageFeatureBase implements v
// We now have a list of references to show in the CodeLens.
const count = remappedReferences.length;
codeLens.command = {
title: count === 1 ? '1 reference' : `${count} references`,
title: count === 1 ? l10n.t('1 reference') : l10n.t('{count} references', count),
phil-allen-msft marked this conversation as resolved.
Show resolved Hide resolved
command: 'editor.action.showReferences',
arguments: [razorDocument.uri, codeLens.range.start, remappedReferences],
};
Expand Down
3 changes: 2 additions & 1 deletion src/razor/src/completion/razorCompletionItemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as l10n from '@vscode/l10n';
import { RazorDocumentManager } from '../document/razorDocumentManager';
import { RazorDocumentSynchronizer } from '../document/razorDocumentSynchronizer';
import { RazorLanguageFeatureBase } from '../razorLanguageFeatureBase';
Expand Down Expand Up @@ -289,6 +290,6 @@ function getTriggerKind(triggerKind: vscode.CompletionTriggerKind): CompletionTr
case vscode.CompletionTriggerKind.TriggerForIncompleteCompletions:
return CompletionTriggerKind.TriggerForIncompleteCompletions;
default:
throw new Error(`Unexpected completion trigger kind: ${triggerKind}`);
throw new Error(l10n.t('Unexpected completion trigger kind: {0}', triggerKind));
}
}
11 changes: 7 additions & 4 deletions src/razor/src/configurationChangeListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as l10n from '@vscode/l10n';
import { RazorLanguageServerClient } from './razorLanguageServerClient';
import { RazorLogger } from './razorLogger';

export function listenToConfigurationChanges(languageServerClient: RazorLanguageServerClient): vscode.Disposable {
return vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration('razor.trace')) {
if (event.affectsConfiguration(RazorLogger.verbositySetting)) {
razorTraceConfigurationChangeHandler(languageServerClient);
}
});
}

function razorTraceConfigurationChangeHandler(languageServerClient: RazorLanguageServerClient) {
const promptText =
'Would you like to restart the Razor Language Server to enable the Razor trace configuration change?';
const restartButtonText = 'Restart';
const promptText: string = l10n.t(
'Would you like to restart the Razor Language Server to enable the Razor trace configuration change?'
);
const restartButtonText = l10n.t('Restart');

vscode.window.showInformationMessage(promptText, restartButtonText).then(async (result) => {
if (result !== restartButtonText) {
Expand Down
19 changes: 12 additions & 7 deletions src/razor/src/csharp/csharpPreviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as l10n from '@vscode/l10n';
import { IRazorDocumentChangeEvent } from '../document/IRazorDocumentChangeEvent';
import { RazorDocumentChangeKind } from '../document/razorDocumentChangeKind';
import { RazorDocumentManager } from '../document/razorDocumentManager';
Expand All @@ -25,7 +26,7 @@ export class CSharpPreviewPanel {
} else {
this.panel = vscode.window.createWebviewPanel(
CSharpPreviewPanel.viewType,
'Razor C# Preview',
l10n.t('Razor C# Preview'),
vscode.ViewColumn.Two,
{
enableScripts: true,
Expand Down Expand Up @@ -61,7 +62,7 @@ export class CSharpPreviewPanel {

private attachToCurrentPanel() {
if (!this.panel) {
vscode.window.showErrorMessage('Unexpected error when attaching to C# preview window.');
vscode.window.showErrorMessage(l10n.t('Unexpected error when attaching to C# preview window.'));
return;
}

Expand All @@ -73,7 +74,7 @@ export class CSharpPreviewPanel {
}

await vscode.env.clipboard.writeText(this.csharpContent);
vscode.window.showInformationMessage('Razor C# copied to clipboard');
vscode.window.showInformationMessage(l10n.t('Razor C# copied to clipboard'));
return;
}
});
Expand All @@ -100,13 +101,17 @@ export class CSharpPreviewPanel {
let content = this.csharpContent ? this.csharpContent : '';
content = content.replace(/</g, '&lt;').replace(/</g, '&gt;');

const title = l10n.t('Report a Razor issue');
const hostDocumentPathLabel = l10n.t('Host document file path');
const virtualDocumentPathLabel = l10n.t('Virtual doucment file path');
phil-allen-msft marked this conversation as resolved.
Show resolved Hide resolved
const copyCSharpLabel = l10n.t('Copy C#');
this.panel.webview.html = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Report a Razor issue</title>
<title>${title}</title>
<style>
button {
background-color: #eff3f6;
Expand All @@ -133,9 +138,9 @@ export class CSharpPreviewPanel {
</script>
</head>
<body>
<p>Host document file path: <strong>${hostDocumentFilePath}</strong></p>
<p>Virtual document file path: <strong>${virtualDocumentFilePath}</strong></p
<p><button onclick="copy()">Copy C#</button></p>
<p>${hostDocumentPathLabel}: <strong>${hostDocumentFilePath}</strong></p>
<p>${virtualDocumentPathLabel}: <strong>${virtualDocumentFilePath}</strong></p
<p><button onclick="copy()">${copyCSharpLabel}</button></p>
<hr />
<pre>${content}</pre>
</body>
Expand Down
Loading