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

Engineering - adopt l10n for git-base/git/github extesions #164566

Merged
merged 8 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
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==
3 changes: 1 addition & 2 deletions extensions/github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@
},
"dependencies": {
"@octokit/rest": "19.0.4",
"tunnel": "^0.0.6",
"vscode-nls": "^5.2.0"
"tunnel": "^0.0.6"
},
"devDependencies": {
"@types/node": "16.x"
Expand Down
19 changes: 8 additions & 11 deletions extensions/github/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { API as GitAPI, Repository } from './typings/git';
import { getOctokit } from './auth';
import { TextEncoder } from 'util';
import { basename } from 'path';
import { Octokit } from '@octokit/rest';
import { isInCodespaces } from './pushErrorHandler';

const localize = nls.loadMessageBundle();

function sanitizeRepositoryName(value: string): string {
return value.trim().replace(/[^a-z0-9_.]/ig, '-');
}
Expand Down Expand Up @@ -41,7 +38,7 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
folder = vscode.workspace.workspaceFolders[0].uri;
} else {
const picks = vscode.workspace.workspaceFolders.map(folder => ({ label: folder.name, folder }));
const placeHolder = localize('pick folder', "Pick a folder to publish to GitHub");
const placeHolder = vscode.l10n.t('Pick a folder to publish to GitHub');
const pick = await vscode.window.showQuickPick(picks, { placeHolder });

if (!pick) {
Expand Down Expand Up @@ -130,7 +127,7 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)

if (shouldGenerateGitignore) {
quickpick = vscode.window.createQuickPick();
quickpick.placeholder = localize('ignore', "Select which files should be included in the repository.");
quickpick.placeholder = vscode.l10n.t('Select which files should be included in the repository.');
quickpick.canSelectMany = true;
quickpick.show();

Expand Down Expand Up @@ -171,8 +168,8 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
const githubRepository = await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, cancellable: false, title: 'Publish to GitHub' }, async progress => {
progress.report({
message: isPrivate
? localize('publishing_private', "Publishing to a private GitHub repository")
: localize('publishing_public', "Publishing to a public GitHub repository"),
? vscode.l10n.t('Publishing to a private GitHub repository')
: vscode.l10n.t('Publishing to a public GitHub repository'),
increment: 25
});

Expand All @@ -190,7 +187,7 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
}

if (createdGithubRepository) {
progress.report({ message: localize('publishing_firstcommit', "Creating first commit"), increment: 25 });
progress.report({ message: vscode.l10n.t('Creating first commit'), increment: 25 });

if (!repository) {
repository = await gitAPI.init(folder) || undefined;
Expand All @@ -202,7 +199,7 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
await repository.commit('first commit', { all: true, postCommitCommand: null });
}

progress.report({ message: localize('publishing_uploading', "Uploading files"), increment: 25 });
progress.report({ message: vscode.l10n.t('Uploading files'), increment: 25 });

const branch = await repository.getBranch('HEAD');
const protocol = vscode.workspace.getConfiguration('github').get<'https' | 'ssh'>('gitProtocol');
Expand All @@ -218,8 +215,8 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
return;
}

const openOnGitHub = localize('openingithub', "Open on GitHub");
vscode.window.showInformationMessage(localize('publishing_done', "Successfully published the '{0}' repository to GitHub.", `${owner}/${repo}`), openOnGitHub).then(action => {
const openOnGitHub = vscode.l10n.t('Open on GitHub');
vscode.window.showInformationMessage(vscode.l10n.t('Successfully published the "{0}" repository to GitHub.', `${owner}/${repo}`), openOnGitHub).then(action => {
if (action === openOnGitHub) {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(githubRepository.html_url));
}
Expand Down
33 changes: 15 additions & 18 deletions extensions/github/src/pushErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@
*--------------------------------------------------------------------------------------------*/

import { TextDecoder } from 'util';
import { commands, env, ProgressLocation, Uri, window, workspace, QuickPickOptions, FileType } from 'vscode';
import * as nls from 'vscode-nls';
import { commands, env, ProgressLocation, Uri, window, workspace, QuickPickOptions, FileType, l10n } from 'vscode';
import { getOctokit } from './auth';
import { GitErrorCodes, PushErrorHandler, Remote, Repository } from './typings/git';
import path = require('path');

const localize = nls.loadMessageBundle();

type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T;

export function isInCodespaces(): boolean {
return env.remoteName === 'codespaces';
}

async function handlePushError(repository: Repository, remote: Remote, refspec: string, owner: string, repo: string): Promise<void> {
const yes = localize('create a fork', "Create Fork");
const no = localize('no', "No");
const askFork = localize('fork', "You don't have permissions to push to '{0}/{1}' on GitHub. Would you like to create a fork and push to it instead?", owner, repo);
const yes = l10n.t('Create Fork');
const no = l10n.t('No');
const askFork = l10n.t('You don\'t have permissions to push to "{0}/{1}" on GitHub.Would you like to create a fork and push to it instead ?', owner, repo);
lszomoru marked this conversation as resolved.
Show resolved Hide resolved

const answer = await window.showInformationMessage(askFork, yes, no);
if (answer !== yes) {
Expand All @@ -32,8 +29,8 @@ async function handlePushError(repository: Repository, remote: Remote, refspec:
const localName = match ? match[1] : refspec;
let remoteName = match ? match[2] : refspec;

const [octokit, ghRepository] = await window.withProgress({ location: ProgressLocation.Notification, cancellable: false, title: localize('create fork', 'Create GitHub fork') }, async progress => {
progress.report({ message: localize('forking', "Forking '{0}/{1}'...", owner, repo), increment: 33 });
const [octokit, ghRepository] = await window.withProgress({ location: ProgressLocation.Notification, cancellable: false, title: l10n.t('Create GitHub fork') }, async progress => {
progress.report({ message: l10n.t('Forking "{0}/{1}"...', owner, repo), increment: 33 });

const octokit = await getOctokit();

Expand Down Expand Up @@ -68,7 +65,7 @@ async function handlePushError(repository: Repository, remote: Remote, refspec:
throw ex;
}

progress.report({ message: localize('forking_pushing', "Pushing changes..."), increment: 33 });
progress.report({ message: l10n.t('Pushing changes...'), increment: 33 });

// Issue: what if there's already an `upstream` repo?
await repository.renameRemote(remote.name, 'upstream');
Expand All @@ -92,14 +89,14 @@ async function handlePushError(repository: Repository, remote: Remote, refspec:

// yield
(async () => {
const openOnGitHub = localize('openingithub', "Open on GitHub");
const createPR = localize('createpr', "Create PR");
const action = await window.showInformationMessage(localize('forking_done', "The fork '{0}' was successfully created on GitHub.", ghRepository.full_name), openOnGitHub, createPR);
const openOnGitHub = l10n.t('Open on GitHub');
const createPR = l10n.t('Create PR');
const action = await window.showInformationMessage(l10n.t('The fork "{0}" was successfully created on GitHub.', ghRepository.full_name), openOnGitHub, createPR);

if (action === openOnGitHub) {
await commands.executeCommand('vscode.open', Uri.parse(ghRepository.html_url));
} else if (action === createPR) {
const pr = await window.withProgress({ location: ProgressLocation.Notification, cancellable: false, title: localize('createghpr', "Creating GitHub Pull Request...") }, async _ => {
const pr = await window.withProgress({ location: ProgressLocation.Notification, cancellable: false, title: l10n.t('Creating GitHub Pull Request...') }, async _ => {
let title = `Update ${remoteName}`;
const head = repository.state.HEAD?.name;

Expand Down Expand Up @@ -138,8 +135,8 @@ async function handlePushError(repository: Repository, remote: Remote, refspec:
return pr;
});

const openPR = localize('openpr', "Open PR");
const action = await window.showInformationMessage(localize('donepr', "The PR '{0}/{1}#{2}' was successfully created on GitHub.", owner, repo, pr.number), openPR);
const openPR = l10n.t('Open PR');
const action = await window.showInformationMessage(l10n.t('The PR "{0}/{1}#{2}" was successfully created on GitHub.', owner, repo, pr.number), openPR);

if (action === openPR) {
await commands.executeCommand('vscode.open', Uri.parse(pr.html_url));
Expand Down Expand Up @@ -196,14 +193,14 @@ export async function pickPullRequestTemplate(repositoryRootUri: Uri, templates:
const quickPickItemFromUri = (x: Uri) => ({ label: path.relative(repositoryRootUri.path, x.path), template: x });
const quickPickItems = [
{
label: localize('no pr template', "No template"),
label: l10n.t('No template'),
picked: true,
template: undefined,
},
...templates.map(quickPickItemFromUri)
];
const quickPickOptions: QuickPickOptions = {
placeHolder: localize('select pr template', "Select the Pull Request template"),
placeHolder: l10n.t('Select the Pull Request template'),
ignoreFocusOut: true
};
const pickedTemplate = await window.showQuickPick(quickPickItems, quickPickOptions);
Expand Down
5 changes: 0 additions & 5 deletions extensions/github/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ universal-user-agent@^6.0.0:
resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee"
integrity sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==

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==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
Expand Down