cluster deploy extension: Add localization support and fix " to ' strings (#4332)

* Add localization support and fix " to ' strings

* Fix ${ usage
This commit is contained in:
Kevin Cunnane
2019-03-07 14:26:31 -08:00
committed by GitHub
parent 029c69ecd3
commit a4d99b78d5
10 changed files with 62 additions and 41 deletions

View File

@@ -3,14 +3,17 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from "vscode";
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export interface ISqlServerBigDataClusterChannel {
showOutput(message: any, title?: string): void;
}
const outputChannelName = localize('bigDataClusterOutputChannel', 'SQL Server big data cluster');
class SqlServerBigDataCluster implements ISqlServerBigDataClusterChannel {
private readonly channel: vscode.OutputChannel = vscode.window.createOutputChannel("SQL Server big data cluster");
private readonly channel: vscode.OutputChannel = vscode.window.createOutputChannel(outputChannelName);
showOutput(message: any, title?: string): void {
if (title) {

View File

@@ -3,6 +3,9 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { Shell } from '../utility/shell';
import { Host } from './host';
import { FS } from '../utility/fs';
@@ -53,17 +56,18 @@ export function execPath(shell: Shell, basePath: string): string {
}
type CheckPresentFailureReason = 'inferFailed' | 'configuredFileMissing';
const installDependenciesAction = localize('installDependenciesAction','Install dependencies');
const learnMoreAction = localize('learnMoreAction','Learn more');
function alertNoBin(host: Host, binName: string, failureReason: CheckPresentFailureReason, message: string, installDependencies: () => void): void {
switch (failureReason) {
case 'inferFailed':
host.showErrorMessage(message, 'Install dependencies', 'Learn more').then(
host.showErrorMessage(message, installDependenciesAction, learnMoreAction).then(
(str) => {
switch (str) {
case 'Learn more':
host.showInformationMessage(`Add ${binName} directory to path, or set "mssql-bdc.${binName}-path" config to ${binName} binary.`);
case learnMoreAction:
host.showInformationMessage(localize('moreInfoMsg', 'Add {0} directory to path, or set "mssql-bdc.{0}-path" config to {0} binary.', binName));
break;
case 'Install dependencies':
case installDependenciesAction:
installDependencies();
break;
}
@@ -72,9 +76,9 @@ function alertNoBin(host: Host, binName: string, failureReason: CheckPresentFail
);
break;
case 'configuredFileMissing':
host.showErrorMessage(message, 'Install dependencies').then(
host.showErrorMessage(message, installDependenciesAction).then(
(str) => {
if (str === 'Install dependencies') {
if (str === installDependenciesAction) {
installDependencies();
}
}

View File

@@ -3,6 +3,9 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { Host } from './host';
import { FS } from '../utility/fs';
import { Shell, ShellResult } from '../utility/shell';
@@ -72,17 +75,17 @@ async function checkForKubectlInternal(context: Context, errorMessageMode: Check
const bin = getToolPath(context.host, context.shell, binName);
const contextMessage = getCheckKubectlContextMessage(errorMessageMode);
const inferFailedMessage = `Could not find "${binName}" binary.${contextMessage}`;
const configuredFileMissingMessage = `${bin} is not installed. ${contextMessage}`;
const inferFailedMessage = localize('binaryNotFound', 'Could not find {0} binary. {1}', binName, contextMessage);
const configuredFileMissingMessage = localize('binaryNotInstalled', '{0} is not installed. {1}', bin, contextMessage);
return await binutil.checkForBinary(context, bin, binName, inferFailedMessage, configuredFileMissingMessage, errorMessageMode !== CheckPresentMessageMode.Silent);
}
function getCheckKubectlContextMessage(errorMessageMode: CheckPresentMessageMode): string {
if (errorMessageMode === CheckPresentMessageMode.Activation) {
return ' SQL Server Big data cluster requires kubernetes.';
return localize('kubernetesRequired',' SQL Server Big data cluster requires kubernetes.');
} else if (errorMessageMode === CheckPresentMessageMode.Command) {
return ' Cannot execute command.';
return localize('cannotExecuteCmd', ' Cannot execute command.');
}
return '';
}
@@ -111,7 +114,7 @@ async function checkPossibleIncompatibility(context: Context): Promise<void> {
checkedCompatibility = true;
const compat = await compatibility.check((cmd) => asJson<compatibility.Version>(context, cmd));
if (!compatibility.isGuaranteedCompatible(compat) && compat.didCheck) {
const versionAlert = `kubectl version ${compat.clientVersion} may be incompatible with cluster Kubernetes version ${compat.serverVersion}`;
const versionAlert = localize('kubectlVersionIncompatible', 'kubectl version ${0} may be incompatible with cluster Kubernetes version {1}', compat.clientVersion, compat.serverVersion);
context.host.showWarningMessage(versionAlert);
}
}
@@ -128,7 +131,7 @@ export function baseKubectlPath(context: Context): string {
async function asJson<T>(context: Context, command: string): Promise<Errorable<T>> {
const shellResult = await invokeAsync(context, command);
if (!shellResult) {
return { succeeded: false, error: [`Unable to run command (${command})`] };
return { succeeded: false, error: [localize('cannotRunCommand', 'Unable to run command ({0})', command)] };
}
if (shellResult.code === 0) {

View File

@@ -3,9 +3,12 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from "vscode";
import { Kubectl } from "./kubectl";
import { failed, ClusterType } from "../interfaces";
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { Kubectl } from './kubectl';
import { failed, ClusterType } from '../interfaces';
export interface KubectlContext {
readonly clusterName: string;
@@ -47,7 +50,7 @@ export interface ClusterConfig {
async function getKubeconfig(kubectl: Kubectl): Promise<Kubeconfig | null> {
const shellResult = await kubectl.asJson<any>("config view -o json");
const shellResult = await kubectl.asJson<any>('config view -o json');
if (failed(shellResult)) {
vscode.window.showErrorMessage(shellResult.error[0]);
return null;
@@ -60,11 +63,11 @@ export async function getCurrentClusterConfig(kubectl: Kubectl): Promise<Cluster
if (!kubeConfig || !kubeConfig.clusters || !kubeConfig.contexts) {
return undefined;
}
const contextConfig = kubeConfig.contexts.find((context) => context.name === kubeConfig["current-context"])!;
const contextConfig = kubeConfig.contexts.find((context) => context.name === kubeConfig['current-context'])!;
const clusterConfig = kubeConfig.clusters.find((cluster) => cluster.name === contextConfig.context.cluster)!;
return {
server: clusterConfig.cluster.server,
certificateAuthority: clusterConfig.cluster["certificate-authority"]
certificateAuthority: clusterConfig.cluster['certificate-authority']
};
}
@@ -73,7 +76,7 @@ export async function getContexts(kubectl: Kubectl): Promise<KubectlContext[]> {
if (!kubectlConfig) {
return [];
}
const currentContext = kubectlConfig["current-context"];
const currentContext = kubectlConfig['current-context'];
const contexts = kubectlConfig.contexts || [];
return contexts.map((c) => {
return {
@@ -87,14 +90,15 @@ export async function getContexts(kubectl: Kubectl): Promise<KubectlContext[]> {
export async function setContext(kubectl: Kubectl, targetContext: string): Promise<void> {
const shellResult = await kubectl.invokeAsync(`config use-context ${targetContext}`);
if (!shellResult || shellResult.code != 0) {
if (!shellResult || shellResult.code !== 0) {
// TODO: Update error handling for now.
vscode.window.showErrorMessage(`Failed to set '${targetContext}' as current cluster: ${shellResult ? shellResult.stderr : "Unable to run kubectl"}`);
let errMsg = shellResult ? shellResult.stderr : localize('runKubectlFailed', 'Unable to run kubectl');
vscode.window.showErrorMessage(localize('setClusterFailed', 'Failed to set \'{0}\' as current cluster: {1}', targetContext, errMsg));
}
}
export async function inferCurrentClusterType(kubectl: Kubectl): Promise<ClusterType> {
let latestContextName = "";
let latestContextName = '';
const ctxsr = await kubectl.invokeAsync('config current-context');
if (ctxsr && ctxsr.code === 0) {