Skip to content

Commit

Permalink
Engineering - adopt l10n for git-base/git/github extesions (#164566)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler James Leonhardt <[email protected]>
  • Loading branch information
lszomoru and TylerLeonhardt authored Oct 28, 2022
1 parent 8cc0246 commit f09c412
Show file tree
Hide file tree
Showing 21 changed files with 366 additions and 432 deletions.
3 changes: 0 additions & 3 deletions extensions/git-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@
}
]
},
"dependencies": {
"vscode-nls": "^5.2.0"
},
"devDependencies": {
"@types/node": "16.x"
},
Expand Down
27 changes: 12 additions & 15 deletions extensions/git-base/src/remoteSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { QuickPickItem, window, QuickPick, QuickPickItemKind } from 'vscode';
import * as nls from 'vscode-nls';
import { QuickPickItem, window, QuickPick, QuickPickItemKind, l10n } from 'vscode';
import { RemoteSourceProvider, RemoteSource, PickRemoteSourceOptions, PickRemoteSourceResult } from './api/git-base';
import { Model } from './model';
import { throttle, debounce } from './decorators';

const localize = nls.loadMessageBundle();

async function getQuickPickResult<T extends QuickPickItem>(quickpick: QuickPick<T>): Promise<T | undefined> {
const result = await new Promise<T | undefined>(c => {
quickpick.onDidAccept(() => c(quickpick.selectedItems[0]));
Expand All @@ -33,10 +30,10 @@ class RemoteSourceProviderQuickPick {
this.quickpick = window.createQuickPick();
this.quickpick.ignoreFocusOut = true;
if (this.provider.supportsQuery) {
this.quickpick.placeholder = this.provider.placeholder ?? localize('type to search', "Repository name (type to search)");
this.quickpick.placeholder = this.provider.placeholder ?? l10n.t('Repository name (type to search)');
this.quickpick.onDidChangeValue(this.onDidChangeValue, this);
} else {
this.quickpick.placeholder = this.provider.placeholder ?? localize('type to filter', "Repository name");
this.quickpick.placeholder = this.provider.placeholder ?? l10n.t('Repository name');
}
}
}
Expand All @@ -57,7 +54,7 @@ class RemoteSourceProviderQuickPick {

if (remoteSources.length === 0) {
this.quickpick!.items = [{
label: localize('none found', "No remote repositories found."),
label: l10n.t('No remote repositories found.'),
alwaysShow: true
}];
} else {
Expand All @@ -70,7 +67,7 @@ class RemoteSourceProviderQuickPick {
}));
}
} catch (err) {
this.quickpick!.items = [{ label: localize('error', "{0} Error: {1}", '$(error)', err.message), alwaysShow: true }];
this.quickpick!.items = [{ label: l10n.t('{0} Error: {1}', '$(error)', err.message), alwaysShow: true }];
console.error(err);
} finally {
this.quickpick!.busy = false;
Expand Down Expand Up @@ -118,19 +115,19 @@ export async function pickRemoteSource(model: Model, options: PickRemoteSourceOp
}

const items = [
{ kind: QuickPickItemKind.Separator, label: localize('remote sources', 'remote sources') },
{ kind: QuickPickItemKind.Separator, label: l10n.t('remote sources') },
...remoteProviders,
{ kind: QuickPickItemKind.Separator, label: localize('recently opened', 'recently opened') },
{ kind: QuickPickItemKind.Separator, label: l10n.t('recently opened') },
...recentSources.sort((a, b) => b.timestamp - a.timestamp)
];

quickpick.placeholder = options.placeholder ?? (remoteProviders.length === 0
? localize('provide url', "Provide repository URL")
: localize('provide url or pick', "Provide repository URL or pick a repository source."));
? l10n.t('Provide repository URL')
: l10n.t('Provide repository URL or pick a repository source.'));

const updatePicks = (value?: string) => {
if (value) {
const label = (typeof options.urlLabel === 'string' ? options.urlLabel : options.urlLabel?.(value)) ?? localize('url', "URL");
const label = (typeof options.urlLabel === 'string' ? options.urlLabel : options.urlLabel?.(value)) ?? l10n.t('URL');
quickpick.items = [{
label: label,
description: value,
Expand Down Expand Up @@ -170,7 +167,7 @@ async function pickProviderSource(provider: RemoteSourceProvider, options: PickR
if (typeof remote.url === 'string') {
url = remote.url;
} else if (remote.url.length > 0) {
url = await window.showQuickPick(remote.url, { ignoreFocusOut: true, placeHolder: localize('pick url', "Choose a URL to clone from.") });
url = await window.showQuickPick(remote.url, { ignoreFocusOut: true, placeHolder: l10n.t('Choose a URL to clone from.') });
}
}

Expand All @@ -189,7 +186,7 @@ async function pickProviderSource(provider: RemoteSourceProvider, options: PickR
}

const branch = await window.showQuickPick(branches, {
placeHolder: localize('branch name', "Branch name")
placeHolder: l10n.t('Branch name')
});

if (!branch) {
Expand Down
5 changes: 0 additions & 5 deletions extensions/git-base/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@
version "16.11.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.21.tgz#474d7589a30afcf5291f59bd49cca9ad171ffde4"
integrity sha512-Pf8M1XD9i1ksZEcCP8vuSNwooJ/bZapNmIzpmsMaL+jMI+8mEYU3PKvs+xDNuQcJWF/x24WzY4qxLtB0zNow9A==

vscode-nls@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.2.0.tgz#3cb6893dd9bd695244d8a024bdf746eea665cc3f"
integrity sha512-RAaHx7B14ZU04EU31pT+rKz2/zSl7xMsfIZuo8pd+KZO6PXtQmpevpq3vxvWNcrGbdmhM/rr5Uw5Mz+NBfhVng==
1 change: 0 additions & 1 deletion extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2737,7 +2737,6 @@
"file-type": "16.5.4",
"jschardet": "3.0.0",
"picomatch": "2.3.1",
"vscode-nls": "^5.2.0",
"vscode-uri": "^2.0.0",
"which": "^1.3.0"
},
Expand Down
19 changes: 8 additions & 11 deletions extensions/git/src/actionButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vscode-nls';
import { Command, Disposable, Event, EventEmitter, SourceControlActionButton, Uri, workspace } from 'vscode';
import { Command, Disposable, Event, EventEmitter, SourceControlActionButton, Uri, workspace, l10n } from 'vscode';
import { Branch, Status } from './api/git';
import { CommitCommandsCenter } from './postCommitCommands';
import { Repository, Operation } from './repository';
import { dispose } from './util';

const localize = nls.loadMessageBundle();

interface ActionButtonState {
readonly HEAD: Branch | undefined;
readonly isCommitInProgress: boolean;
Expand Down Expand Up @@ -106,8 +103,8 @@ export class ActionButtonCommand {
if (this.state.isRebaseInProgress) {
return {
command: 'git.commit',
title: localize('scm button continue title', "{0} Continue", '$(check)'),
tooltip: this.state.isCommitInProgress ? localize('scm button continuing tooltip', "Continuing Rebase...") : localize('scm button continue tooltip', "Continue Rebase"),
title: l10n.t('{0} Continue', '$(check)'),
tooltip: this.state.isCommitInProgress ? l10n.t('Continuing Rebase...') : l10n.t('Continue Rebase'),
arguments: [this.repository.sourceControl, '']
};
}
Expand Down Expand Up @@ -143,10 +140,10 @@ export class ActionButtonCommand {
return {
command: {
command: 'git.publish',
title: localize({ key: 'scm publish branch action button title', comment: ['{Locked="Branch"}', 'Do not translate "Branch" as it is a git term'] }, "{0} Publish Branch", '$(cloud-upload)'),
title: l10n.t({ message: '{0} Publish Branch', args: ['$(cloud-upload)'], comment: ['{Locked="Branch"}', 'Do not translate "Branch" as it is a git term'] }),
tooltip: this.state.isSyncInProgress ?
localize({ key: 'scm button publish branch running', comment: ['{Locked="Branch"}', 'Do not translate "Branch" as it is a git term'] }, "Publishing Branch...") :
localize({ key: 'scm button publish branch', comment: ['{Locked="Branch"}', 'Do not translate "Branch" as it is a git term'] }, "Publish Branch"),
l10n.t({ message: 'Publishing Branch...', comment: ['{Locked="Branch"}', 'Do not translate "Branch" as it is a git term'] }) :
l10n.t({ message: 'Publish Branch', comment: ['{Locked="Branch"}', 'Do not translate "Branch" as it is a git term'] }),
arguments: [this.repository.sourceControl],
},
enabled: !this.state.isSyncInProgress
Expand All @@ -170,11 +167,11 @@ export class ActionButtonCommand {
command: 'git.sync',
title: `${icon}${behind}${ahead}`,
tooltip: this.state.isSyncInProgress ?
localize('syncing changes', "Synchronizing Changes...")
l10n.t('Synchronizing Changes...')
: this.repository.syncTooltip,
arguments: [this.repository.sourceControl],
},
description: localize('scm button sync description', "{0} Sync Changes{1}{2}", icon, behind, ahead),
description: l10n.t('{0} Sync Changes{1}{2}', icon, behind, ahead),
enabled: !this.state.isSyncInProgress
};
}
Expand Down
6 changes: 2 additions & 4 deletions extensions/git/src/askpass-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
*--------------------------------------------------------------------------------------------*/

import * as fs from 'fs';
import * as nls from 'vscode-nls';
import { l10n } from 'vscode';
import { IPCClient } from './ipc/ipcClient';

const localize = nls.loadMessageBundle();

function fatal(err: any): void {
console.error(localize('missOrInvalid', "Missing or invalid credentials."));
console.error(l10n.t('Missing or invalid credentials.'));
console.error(err);
process.exit(1);
}
Expand Down
16 changes: 5 additions & 11 deletions extensions/git/src/askpass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vscode-nls';
import { window, InputBoxOptions, Uri, Disposable, workspace, QuickPickOptions } from 'vscode';
import { window, InputBoxOptions, Uri, Disposable, workspace, QuickPickOptions, l10n } from 'vscode';
import { IDisposable, EmptyDisposable, toDisposable } from './util';
import * as path from 'path';
import { IIPCHandler, IIPCServer } from './ipc/ipcServer';
import { CredentialsProvider, Credentials } from './api/git';
import { ITerminalEnvironmentProvider } from './terminal';

const localize = nls.loadMessageBundle();

export class Askpass implements IIPCHandler, ITerminalEnvironmentProvider {

private env: { [key: string]: string };
Expand Down Expand Up @@ -102,7 +99,7 @@ export class Askpass implements IIPCHandler, ITerminalEnvironmentProvider {
if (/passphrase/i.test(request)) {
const options: InputBoxOptions = {
password: true,
placeHolder: localize('ssh passphrase', "Passphrase"),
placeHolder: l10n.t('Passphrase'),
prompt: `SSH Key: ${file}`,
ignoreFocusOut: true
};
Expand All @@ -114,13 +111,10 @@ export class Askpass implements IIPCHandler, ITerminalEnvironmentProvider {
const options: QuickPickOptions = {
canPickMany: false,
ignoreFocusOut: true,
placeHolder: localize('ssh authenticity prompt', "Are you sure you want to continue connecting?"),
title: localize('ssh authenticity title', "\"{0}\" has fingerprint \"{1}\"", host, fingerprint)
placeHolder: l10n.t('Are you sure you want to continue connecting?'),
title: l10n.t('"{0}" has fingerprint "{1}"', host ?? '', fingerprint ?? '')
};
const items = [
localize('ssh authenticity prompt yes', "yes"),
localize('ssh authenticity prompt no', "no")
];
const items = [l10n.t('yes'), l10n.t('no')];
return await window.showQuickPick(items, options) ?? '';
}

Expand Down
13 changes: 5 additions & 8 deletions extensions/git/src/autofetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { workspace, Disposable, EventEmitter, Memento, window, MessageItem, ConfigurationTarget, Uri, ConfigurationChangeEvent } from 'vscode';
import { workspace, Disposable, EventEmitter, Memento, window, MessageItem, ConfigurationTarget, Uri, ConfigurationChangeEvent, l10n } from 'vscode';
import { Repository, Operation } from './repository';
import { eventToPromise, filterEvent, onceEvent } from './util';
import * as nls from 'vscode-nls';
import { GitErrorCodes } from './api/git';

const localize = nls.loadMessageBundle();

function isRemoteOperation(operation: Operation): boolean {
return operation === Operation.Pull || operation === Operation.Push || operation === Operation.Sync || operation === Operation.Fetch;
}
Expand Down Expand Up @@ -51,10 +48,10 @@ export class AutoFetcher {
return;
}

const yes: MessageItem = { title: localize('yes', "Yes") };
const no: MessageItem = { isCloseAffordance: true, title: localize('no', "No") };
const askLater: MessageItem = { title: localize('not now', "Ask Me Later") };
const result = await window.showInformationMessage(localize('suggest auto fetch', "Would you like Code to [periodically run 'git fetch']({0})?", 'https://go.microsoft.com/fwlink/?linkid=865294'), yes, no, askLater);
const yes: MessageItem = { title: l10n.t('Yes') };
const no: MessageItem = { isCloseAffordance: true, title: l10n.t('No') };
const askLater: MessageItem = { title: l10n.t('Ask Me Later') };
const result = await window.showInformationMessage(l10n.t('Would you like Code to [periodically run "git fetch"]({0})?', 'https://go.microsoft.com/fwlink/?linkid=865294'), yes, no, askLater);

if (result === askLater) {
return;
Expand Down
Loading

0 comments on commit f09c412

Please sign in to comment.