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

all: Switch to l10n API #1399

Merged
merged 10 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion appservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion appservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"p-retry": "^3.0.1",
"pretty-bytes": "^5.3.0",
"simple-git": "^3.5.0",
"vscode-nls": "^5.0.1",
"ws": "^8.5.0",
"yazl": "^2.5.1"
},
Expand Down
13 changes: 6 additions & 7 deletions appservice/src/TunnelProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import { RestError, createPipelineRequest } from "@azure/core-rest-pipeline";
import { AzExtPipelineResponse, addBasicAuthenticationCredentialsToClient, createGenericClient } from '@microsoft/vscode-azext-azureutils';
import { IActionContext, IParsedError, UserCancelledError, nonNullProp, parseError } from '@microsoft/vscode-azext-utils';
import { Server, Socket, createServer } from 'net';
import { CancellationToken, Disposable } from 'vscode';
import { CancellationToken, Disposable, l10n } from 'vscode';
import * as ws from 'ws';
import { ParsedSite } from './SiteClient';
import { ext } from './extensionVariables';
import { localize } from './localize';
import { delay } from './utils/delay';

/**
Expand Down Expand Up @@ -112,7 +111,7 @@ export class TunnelProxy {
} catch (error) {
const parsedError: IParsedError = parseError(error);
ext.outputChannel.appendLog(`[Tunnel] Checking status, error: ${parsedError.message}`);
throw new Error(localize('tunnelStatusError', 'Error getting tunnel status: {0}', parsedError.errorType));
throw new Error(l10n.t('Error getting tunnel status: {0}', parsedError.errorType));
}

if (tunnelStatus.state === AppState.STARTED) {
Expand All @@ -122,15 +121,15 @@ export class TunnelProxy {
} else if (tunnelStatus.canReachPort) {
return;
} else {
throw new Error(localize('tunnelUnreachable', 'App is started, but port is unreachable'));
throw new Error(l10n.t('App is started, but port is unreachable'));
}
} else if (tunnelStatus.state === AppState.STARTING) {
throw new RetryableTunnelStatusError();
} else if (tunnelStatus.state === AppState.STOPPED) {
await this.pingApp(context);
throw new RetryableTunnelStatusError();
} else {
throw new Error(localize('tunnelStatusError', 'Unexpected app state: {0}', tunnelStatus.state));
throw new Error(l10n.t('Unexpected app state: {0}', tunnelStatus.state));
}
}

Expand All @@ -151,13 +150,13 @@ export class TunnelProxy {
return;
} catch (error) {
if (!(error instanceof RetryableTunnelStatusError)) {
throw new Error(localize('tunnelFailed', 'Unable to establish connection to application: {0}', parseError(error).message));
throw new Error(l10n.t('Unable to establish connection to application: {0}', parseError(error).message));
} // else allow retry
}

await delay(pollingIntervalMs);
}
throw new Error(localize('tunnelTimedOut', 'Unable to establish connection to application: Timed out'));
throw new Error(l10n.t('Unable to establish connection to application: Timed out'));
}

private async setupTunnelServer(token: CancellationToken): Promise<void> {
Expand Down
19 changes: 9 additions & 10 deletions appservice/src/confirmOverwriteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
*--------------------------------------------------------------------------------------------*/

import { DialogResponses, IActionContext } from '@microsoft/vscode-azext-utils';
import { MessageItem } from 'vscode';
import { l10n, MessageItem } from 'vscode';
import { ext } from './extensionVariables';
import { localize } from './localize';

export async function confirmOverwriteSettings(context: IActionContext, sourceSettings: { [key: string]: string }, destinationSettings: { [key: string]: string }, destinationName: string): Promise<void> {
let suppressPrompt: boolean = false;
Expand All @@ -28,9 +27,9 @@ export async function confirmOverwriteSettings(context: IActionContext, sourceSe
matchingKeys.push(destKey);
} else if (sourceSettings[srcKey]) { // ignore empty settings
if (!suppressPrompt) {
const yesToAll: MessageItem = { title: localize('yesToAll', 'Yes to all') };
const noToAll: MessageItem = { title: localize('noToAll', 'No to all') };
const message: string = localize('overwriteSetting', 'Setting "{0}" already exists in "{1}". Overwrite?', destKey, destinationName);
const yesToAll: MessageItem = { title: l10n.t('Yes to all') };
const noToAll: MessageItem = { title: l10n.t('No to all') };
const message: string = l10n.t('Setting "{0}" already exists in "{1}". Overwrite?', destKey, destinationName);
const result: MessageItem = await context.ui.showWarningMessage(message, { modal: true, stepName: 'confirmOverwriteSetting' }, DialogResponses.yes, yesToAll, DialogResponses.no, noToAll);
if (result === DialogResponses.yes) {
overwriteSetting = true;
Expand All @@ -55,27 +54,27 @@ export async function confirmOverwriteSettings(context: IActionContext, sourceSe
}

if (addedKeys.length > 0) {
ext.outputChannel.appendLog(localize('addedKeys', 'Added the following settings:'));
ext.outputChannel.appendLog(l10n.t('Added the following settings:'));
addedKeys.forEach(logKey);
}

if (updatedKeys.length > 0) {
ext.outputChannel.appendLog(localize('updatedKeys', 'Updated the following settings:'));
ext.outputChannel.appendLog(l10n.t('Updated the following settings:'));
updatedKeys.forEach(logKey);
}

if (matchingKeys.length > 0) {
ext.outputChannel.appendLog(localize('matchingKeys', 'Ignored the following settings that were already the same:'));
ext.outputChannel.appendLog(l10n.t('Ignored the following settings that were already the same:'));
matchingKeys.forEach(logKey);
}

if (userIgnoredKeys.length > 0) {
ext.outputChannel.appendLog(localize('userIgnoredKeys', 'Ignored the following settings based on user input:'));
ext.outputChannel.appendLog(l10n.t('Ignored the following settings based on user input:'));
userIgnoredKeys.forEach(logKey);
}

if (Object.keys(destinationSettings).length > Object.keys(sourceSettings).length) {
ext.outputChannel.appendLog(localize('noDeleteKey', 'WARNING: This operation will not delete any settings in "{0}". You must manually delete settings if desired.', destinationName));
ext.outputChannel.appendLog(l10n.t('WARNING: This operation will not delete any settings in "{0}". You must manually delete settings if desired.', destinationName));
}
}

Expand Down
21 changes: 10 additions & 11 deletions appservice/src/createAppService/AppInsightsCreateStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import type { ApplicationInsightsManagementClient } from '@azure/arm-appinsights
import type { ResourceGroup } from '@azure/arm-resources';
import { AzExtLocation, LocationListStep } from '@microsoft/vscode-azext-azureutils';
import { AzureWizardExecuteStep, IParsedError, nonNullProp, parseError } from '@microsoft/vscode-azext-utils';
import { MessageItem, Progress } from 'vscode';
import { l10n, MessageItem, Progress } from 'vscode';
import { ext } from '../extensionVariables';
import { localize } from '../localize';
import { createAppInsightsClient } from '../utils/azureClients';
import { AppInsightsListStep } from './AppInsightsListStep';
import { getAppInsightsSupportedLocation } from './getAppInsightsSupportedLocation';
Expand All @@ -19,7 +18,7 @@ export class AppInsightsCreateStep extends AzureWizardExecuteStep<IAppServiceWiz
public priority: number = 135;

public async execute(context: IAppServiceWizardContext, progress: Progress<{ message?: string; increment?: number }>): Promise<void> {
const verifyingAppInsightsAvailable: string = localize('verifyingAppInsightsAvailable', 'Verifying that Application Insights is available for this location...');
const verifyingAppInsightsAvailable: string = l10n.t('Verifying that Application Insights is available for this location...');
ext.outputChannel.appendLog(verifyingAppInsightsAvailable);
const resourceLocation: AzExtLocation = await LocationListStep.getLocation(context);
const appInsightsLocation = await getAppInsightsSupportedLocation(context, resourceLocation);
Expand All @@ -31,12 +30,12 @@ export class AppInsightsCreateStep extends AzureWizardExecuteStep<IAppServiceWiz

try {
context.appInsightsComponent = await client.components.get(rgName, aiName);
ext.outputChannel.appendLog(localize('existingNewAppInsights', 'Using existing Application Insights resource "{0}".', aiName));
ext.outputChannel.appendLog(l10n.t('Using existing Application Insights resource "{0}".', aiName));
} catch (error) {
const pError: IParsedError = parseError(error);
// Only expecting a resource not found error if this is a new component
if (pError.errorType === 'ResourceNotFound') {
const creatingNewAppInsights: string = localize('creatingNewAppInsightsInsights', 'Creating Application Insights resource "{0}"...', aiName);
const creatingNewAppInsights: string = l10n.t('Creating Application Insights resource "{0}"...', aiName);
ext.outputChannel.appendLog(creatingNewAppInsights);
progress.report({ message: creatingNewAppInsights });

Expand All @@ -49,11 +48,11 @@ export class AppInsightsCreateStep extends AzureWizardExecuteStep<IAppServiceWiz
location: appInsightsLocation,
workspaceResourceId: context.logAnalyticsWorkspace?.id
});
const createdNewAppInsights: string = localize('createdNewAppInsights', 'Successfully created Application Insights resource "{0}".', aiName);
const createdNewAppInsights: string = l10n.t('Successfully created Application Insights resource "{0}".', aiName);
ext.outputChannel.appendLog(createdNewAppInsights);
} else if (pError.errorType === 'AuthorizationFailed') {
if (!context.advancedCreation) {
const appInsightsNotAuthorized: string = localize('appInsightsNotAuthorized', 'Skipping Application Insights resource because you do not have permission to create one in this subscription.');
const appInsightsNotAuthorized: string = l10n.t('Skipping Application Insights resource because you do not have permission to create one in this subscription.');
ext.outputChannel.appendLog(appInsightsNotAuthorized);
} else {
await this.selectExistingPrompt(context);
Expand All @@ -63,15 +62,15 @@ export class AppInsightsCreateStep extends AzureWizardExecuteStep<IAppServiceWiz
}
}
} else {
const appInsightsNotAvailable: string = localize('appInsightsNotAvailable', 'Skipping Application Insights resource because it isn\'t compatible with this location.');
const appInsightsNotAvailable: string = l10n.t('Skipping Application Insights resource because it isn\'t compatible with this location.');
ext.outputChannel.appendLog(appInsightsNotAvailable);
}
}

public async selectExistingPrompt(context: IAppServiceWizardContext): Promise<void> {
const message: string = localize('aiForbidden', 'You do not have permission to create an app insights resource in subscription "{0}".', context.subscriptionDisplayName);
const selectExisting: MessageItem = { title: localize('selectExisting', 'Select Existing') };
const skipForNow: MessageItem = { title: localize('skipForNow', 'Skip for Now') };
const message: string = l10n.t('You do not have permission to create an app insights resource in subscription "{0}".', context.subscriptionDisplayName);
const selectExisting: MessageItem = { title: l10n.t('Select Existing') };
const skipForNow: MessageItem = { title: l10n.t('Skip for Now') };
const result = await context.ui.showWarningMessage(message, { modal: true, stepName: 'AppInsightsNoPermissions' }, selectExisting, skipForNow);
if (result === skipForNow) {
context.telemetry.properties.aiSkipForNow = 'true';
Expand Down
9 changes: 4 additions & 5 deletions appservice/src/createAppService/AppInsightsListStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { ApplicationInsightsManagementClient } from "@azure/arm-appinsights";
import type { ApplicationInsightsComponent } from "@azure/arm-appinsights";
import type { ApplicationInsightsComponent, ApplicationInsightsManagementClient } from "@azure/arm-appinsights";
import { LocationListStep, uiUtils } from "@microsoft/vscode-azext-azureutils";
import { AzureWizardPromptStep, IAzureNamingRules, IAzureQuickPickItem, IAzureQuickPickOptions, IWizardOptions, nonNullProp } from "@microsoft/vscode-azext-utils";
import { localize } from "../localize";
import * as vscode from 'vscode';
import { createAppInsightsClient } from "../utils/azureClients";
import { AppInsightsCreateStep } from "./AppInsightsCreateStep";
import { AppInsightsNameStep } from "./AppInsightsNameStep";
Expand Down Expand Up @@ -75,12 +74,12 @@ export class AppInsightsListStep extends AzureWizardPromptStep<IAppServiceWizard
private async getQuickPicks(context: IAppServiceWizardContext): Promise<IAzureQuickPickItem<ApplicationInsightsComponent | undefined>[]> {

const picks: IAzureQuickPickItem<ApplicationInsightsComponent | undefined>[] = !this._suppressCreate ? [{
label: localize('newApplicationInsight', '$(plus) Create new Application Insights resource'),
label: vscode.l10n.t('$(plus) Create new Application Insights resource'),
data: undefined
}] : [];

picks.push({
label: localize('skipForNow', skipForNowLabel),
label: vscode.l10n.t(skipForNowLabel),
data: undefined
});

Expand Down
10 changes: 5 additions & 5 deletions appservice/src/createAppService/AppInsightsNameStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import type { ApplicationInsightsComponent } from '@azure/arm-appinsights';
import { AzureWizardPromptStep } from '@microsoft/vscode-azext-utils';
import { localize } from '../localize';
import * as vscode from 'vscode';
import { AppInsightsListStep, appInsightsNamingRules } from './AppInsightsListStep';
import { IAppServiceWizardContext } from './IAppServiceWizardContext';

Expand Down Expand Up @@ -34,13 +34,13 @@ export class AppInsightsNameStep extends AzureWizardPromptStep<IAppServiceWizard
name = name.trim();

if (name.length < appInsightsNamingRules.minLength || name.length > appInsightsNamingRules.maxLength) {
return localize('invalidLength', 'The name must be between {0} and {1} characters.', appInsightsNamingRules.minLength, appInsightsNamingRules.maxLength);
return vscode.l10n.t('The name must be between {0} and {1} characters.', appInsightsNamingRules.minLength, appInsightsNamingRules.maxLength);
} else if (appInsightsNamingRules.invalidCharsRegExp.test(name)) {
return localize('invalidChars', "The name can only contain alphanumeric characters or the symbols ._-()");
return vscode.l10n.t("The name can only contain alphanumeric characters or the symbols ._-()");
} else if (name.endsWith('.')) {
return localize('invalidEndingChar', "The name cannot end in a period.");
return vscode.l10n.t("The name cannot end in a period.");
} else if (!await this.isNameAvailable(context, name)) {
return localize('nameAlreadyExists', 'Application Insights resource "{0}" already exists in subscription "{1}".', name, context.subscriptionDisplayName);
return vscode.l10n.t('Application Insights resource "{0}" already exists in subscription "{1}".', name, context.subscriptionDisplayName);
} else {
return undefined;
}
Expand Down
15 changes: 7 additions & 8 deletions appservice/src/createAppService/AppServicePlanCreateStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import { AppServicePlan, WebSiteManagementClient } from '@azure/arm-appservice';
import { AzExtLocation, LocationListStep } from '@microsoft/vscode-azext-azureutils';
import { AzureWizardExecuteStep, nonNullProp, nonNullValue, parseError } from '@microsoft/vscode-azext-utils';
import { MessageItem, Progress } from 'vscode';
import { l10n, MessageItem, Progress } from 'vscode';
import { webProvider } from '../constants';
import { ext } from '../extensionVariables';
import { localize } from '../localize';
import { tryGetAppServicePlan } from '../tryGetSiteResource';
import { createWebSiteClient } from '../utils/azureClients';
import { AppKind, WebsiteOS } from './AppKind';
Expand All @@ -23,10 +22,10 @@ export class AppServicePlanCreateStep extends AzureWizardExecuteStep<IAppService
const newPlanName: string = nonNullProp(context, 'newPlanName');
const rgName: string = nonNullProp(nonNullValue(context.resourceGroup, 'name'), 'name');

const findingAppServicePlan: string = localize('FindingAppServicePlan', 'Ensuring App Service plan "{0}" exists...', newPlanName);
const creatingAppServicePlan: string = localize('CreatingAppServicePlan', 'Creating App Service plan "{0}"...', newPlanName);
const foundAppServicePlan: string = localize('FoundAppServicePlan', 'Successfully found App Service plan "{0}".', newPlanName);
const createdAppServicePlan: string = localize('CreatedAppServicePlan', 'Successfully created App Service plan "{0}".', newPlanName);
const findingAppServicePlan: string = l10n.t('Ensuring App Service plan "{0}" exists...', newPlanName);
const creatingAppServicePlan: string = l10n.t('Creating App Service plan "{0}"...', newPlanName);
const foundAppServicePlan: string = l10n.t('Successfully found App Service plan "{0}".', newPlanName);
const createdAppServicePlan: string = l10n.t('Successfully created App Service plan "{0}".', newPlanName);
ext.outputChannel.appendLog(findingAppServicePlan);

try {
Expand All @@ -53,8 +52,8 @@ export class AppServicePlanCreateStep extends AzureWizardExecuteStep<IAppService
}

public async selectExistingPrompt(context: IAppServiceWizardContext): Promise<void> {
const message: string = localize('planForbidden', 'You do not have permission to create an app service plan in subscription "{0}".', context.subscriptionDisplayName);
const selectExisting: MessageItem = { title: localize('selectExisting', 'Select Existing') };
const message: string = l10n.t('You do not have permission to create an app service plan in subscription "{0}".', context.subscriptionDisplayName);
const selectExisting: MessageItem = { title: l10n.t('Select Existing') };
await context.ui.showWarningMessage(message, { modal: true, stepName: 'AspNoPermissions' }, selectExisting);

context.telemetry.properties.forbiddenResponse = 'SelectExistingAsp';
Expand Down
Loading