Skip to content

Commit 306a01f

Browse files
authored
Localize all views and messages (#70)
1 parent d9899b4 commit 306a01f

File tree

17 files changed

+238
-117
lines changed

17 files changed

+238
-117
lines changed

src/common/errors/utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as stackTrace from 'stack-trace';
22
import { commands, LogOutputChannel, window } from 'vscode';
3+
import { Common } from '../localize';
34

45
export function parseStack(ex: Error) {
56
if (ex.stack && Array.isArray(ex.stack)) {
@@ -10,8 +11,8 @@ export function parseStack(ex: Error) {
1011
}
1112

1213
export async function showErrorMessage(message: string, log?: LogOutputChannel) {
13-
const result = await window.showErrorMessage(message, 'View Logs');
14-
if (result === 'View Logs') {
14+
const result = await window.showErrorMessage(message, Common.viewLogs);
15+
if (result === Common.viewLogs) {
1516
if (log) {
1617
log.show();
1718
} else {
@@ -21,8 +22,8 @@ export async function showErrorMessage(message: string, log?: LogOutputChannel)
2122
}
2223

2324
export async function showWarningMessage(message: string, log?: LogOutputChannel) {
24-
const result = await window.showWarningMessage(message, 'View Logs');
25-
if (result === 'View Logs') {
25+
const result = await window.showWarningMessage(message, Common.viewLogs);
26+
if (result === Common.viewLogs) {
2627
if (log) {
2728
log.show();
2829
} else {

src/common/localize.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export namespace Common {
66
export const uninstall = l10n.t('Uninstall');
77
export const openInBrowser = l10n.t('Open in Browser');
88
export const openInEditor = l10n.t('Open in Editor');
9+
export const browse = l10n.t('Browse');
10+
export const selectFolder = l10n.t('Select Folder');
11+
export const viewLogs = l10n.t('View Logs');
12+
export const yes = l10n.t('Yes');
13+
export const no = l10n.t('No');
914
}
1015

1116
export namespace Interpreter {
@@ -25,3 +30,99 @@ export namespace PackageManagement {
2530
export const enterPackagesPlaceHolder = l10n.t('Enter package names separated by space');
2631
export const editArguments = l10n.t('Edit arguments');
2732
}
33+
34+
export namespace Pickers {
35+
export namespace Environments {
36+
export const selectExecutable = l10n.t('Select Python Executable');
37+
export const selectEnvironment = l10n.t('Select a Python Environment');
38+
}
39+
40+
export namespace Packages {
41+
export const selectOption = l10n.t('Select an option');
42+
export const installPackages = l10n.t('Install packages');
43+
export const uninstallPackages = l10n.t('Uninstall packages');
44+
}
45+
46+
export namespace Managers {
47+
export const selectEnvironmentManager = l10n.t('Select an environment manager');
48+
export const selectPackageManager = l10n.t('Select a package manager');
49+
export const selectProjectCreator = l10n.t('Select a project creator');
50+
}
51+
52+
export namespace Project {
53+
export const selectProject = l10n.t('Select a project, folder or script');
54+
export const selectProjects = l10n.t('Select one or more projects, folders or scripts');
55+
}
56+
}
57+
58+
export namespace ProjectViews {
59+
export const noPackageManager = l10n.t('No package manager found');
60+
export const waitingForEnvManager = l10n.t('Waiting for environment managers to load');
61+
export const noEnvironmentManager = l10n.t('Environment manager not found');
62+
export const noEnvironmentManagerDescription = l10n.t(
63+
'Install an environment manager to get started. If you have installed then it might be loading or errored',
64+
);
65+
export const noEnvironmentProvided = l10n.t('No environment provided by:');
66+
export const noPackages = l10n.t('No packages found');
67+
}
68+
69+
export namespace VenvManagerStrings {
70+
export const venvManagerDescription = l10n.t('Manages virtual environments created using `venv`');
71+
export const venvInitialize = l10n.t('Initializing virtual environments');
72+
export const venvRefreshing = l10n.t('Refreshing virtual environments');
73+
export const venvGlobalFolder = l10n.t('Select a folder to create a global virtual environment');
74+
export const venvGlobalFoldersSetting = l10n.t('Venv Folders Setting');
75+
76+
export const venvErrorNoBasePython = l10n.t('No base Python found');
77+
export const venvErrorNoPython3 = l10n.t('Did not find any base Python 3');
78+
79+
export const venvName = l10n.t('Enter a name for the virtual environment');
80+
export const venvNameErrorEmpty = l10n.t('Name cannot be empty');
81+
export const venvNameErrorExists = l10n.t('A folder with the same name already exists');
82+
83+
export const venvCreating = l10n.t('Creating virtual environment');
84+
export const venvCreateFailed = l10n.t('Failed to create virtual environment');
85+
86+
export const venvRemoving = l10n.t('Removing virtual environment');
87+
export const venvRemoveFailed = l10n.t('Failed to remove virtual environment');
88+
89+
export const installEditable = l10n.t('Install project as editable');
90+
export const searchingDependencies = l10n.t('Searching for dependencies');
91+
}
92+
93+
export namespace SysManagerStrings {
94+
export const sysManagerDescription = l10n.t('Manages Global Python installs');
95+
export const sysManagerRefreshing = l10n.t('Refreshing Global Python interpreters');
96+
export const sysManagerDiscovering = l10n.t('Discovering Global Python interpreters');
97+
98+
export const selectInstall = l10n.t('Select packages to install');
99+
export const selectUninstall = l10n.t('Select packages to uninstall');
100+
101+
export const packageRefreshError = l10n.t('Error refreshing packages');
102+
}
103+
104+
export namespace CondaStrings {
105+
export const condaManager = l10n.t('Manages Conda environments');
106+
export const condaDiscovering = l10n.t('Discovering Conda environments');
107+
export const condaRefreshingEnvs = l10n.t('Refreshing Conda environments');
108+
109+
export const condaPackageMgr = l10n.t('Manages Conda packages');
110+
export const condaRefreshingPackages = l10n.t('Refreshing Conda packages');
111+
export const condaInstallingPackages = l10n.t('Installing Conda packages');
112+
export const condaInstallError = l10n.t('Error installing Conda packages');
113+
export const condaUninstallingPackages = l10n.t('Uninstalling Conda packages');
114+
export const condaUninstallError = l10n.t('Error uninstalling Conda packages');
115+
116+
export const condaNamed = l10n.t('Named');
117+
export const condaPrefix = l10n.t('Prefix');
118+
119+
export const condaNamedDescription = l10n.t('Create a named conda environment');
120+
export const condaPrefixDescription = l10n.t('Create environment in your workspace');
121+
export const condaSelectEnvType = l10n.t('Select the type of conda environment to create');
122+
123+
export const condaNamedInput = l10n.t('Enter the name of the conda environment to create');
124+
125+
export const condaCreateFailed = l10n.t('Failed to create conda environment');
126+
export const condaRemoveFailed = l10n.t('Failed to remove conda environment');
127+
export const condaExists = l10n.t('Environment already exists');
128+
}

src/common/pickers/environments.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Uri, ThemeIcon, QuickPickItem, QuickPickItemKind, ProgressLocation, QuickInputButtons } from 'vscode';
22
import { IconPath, PythonEnvironment, PythonProject } from '../../api';
33
import { InternalEnvironmentManager } from '../../internal.api';
4-
import { Common, Interpreter } from '../localize';
4+
import { Common, Interpreter, Pickers } from '../localize';
55
import { showQuickPickWithButtons, showQuickPick, showOpenDialog, withProgress } from '../window.apis';
66
import { isWindows } from '../../managers/common/utils';
77
import { traceError } from '../logging';
@@ -18,14 +18,10 @@ type QuickPickIcon =
1818
| undefined;
1919

2020
function getIconPath(i: IconPath | undefined): QuickPickIcon {
21-
if (i === undefined || i instanceof ThemeIcon) {
21+
if (i === undefined || i instanceof ThemeIcon || i instanceof Uri) {
2222
return i;
2323
}
2424

25-
if (i instanceof Uri) {
26-
return i.fsPath.endsWith('__icon__.py') ? undefined : i;
27-
}
28-
2925
if (typeof i === 'string') {
3026
return Uri.file(i);
3127
}
@@ -51,7 +47,7 @@ async function browseForPython(
5147
canSelectFolders: false,
5248
canSelectMany: false,
5349
filters,
54-
title: 'Select Python executable',
50+
title: Pickers.Environments.selectExecutable,
5551
});
5652
if (!uris || uris.length === 0) {
5753
return;
@@ -103,7 +99,7 @@ async function pickEnvironmentImpl(
10399
options: EnvironmentPickOptions,
104100
): Promise<PythonEnvironment | undefined> {
105101
const selected = await showQuickPickWithButtons(items, {
106-
placeHolder: `Select a Python Environment`,
102+
placeHolder: Pickers.Environments.selectEnvironment,
107103
ignoreFocusOut: true,
108104
showBackButton: options?.showBackButton,
109105
});
@@ -184,7 +180,7 @@ export async function pickEnvironmentFrom(environments: PythonEnvironment[]): Pr
184180
iconPath: getIconPath(e.iconPath),
185181
}));
186182
const selected = await showQuickPick(items, {
187-
placeHolder: 'Select Python Environment',
183+
placeHolder: Pickers.Environments.selectEnvironment,
188184
ignoreFocusOut: true,
189185
});
190186
return (selected as { e: PythonEnvironment })?.e;

src/common/pickers/managers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { QuickPickItem, QuickPickItemKind } from 'vscode';
22
import { PythonProjectCreator } from '../../api';
33
import { InternalEnvironmentManager, InternalPackageManager } from '../../internal.api';
4-
import { Common } from '../localize';
4+
import { Common, Pickers } from '../localize';
55
import { showQuickPickWithButtons, showQuickPick } from '../window.apis';
66

77
export async function pickEnvironmentManager(
@@ -44,7 +44,7 @@ export async function pickEnvironmentManager(
4444
})),
4545
);
4646
const item = await showQuickPickWithButtons(items, {
47-
placeHolder: 'Select an environment manager',
47+
placeHolder: Pickers.Managers.selectEnvironmentManager,
4848
ignoreFocusOut: true,
4949
});
5050
return (item as QuickPickItem & { id: string })?.id;
@@ -90,7 +90,7 @@ export async function pickPackageManager(
9090
})),
9191
);
9292
const item = await showQuickPickWithButtons(items, {
93-
placeHolder: 'Select an package manager',
93+
placeHolder: Pickers.Managers.selectPackageManager,
9494
ignoreFocusOut: true,
9595
});
9696
return (item as QuickPickItem & { id: string })?.id;
@@ -111,7 +111,7 @@ export async function pickCreator(creators: PythonProjectCreator[]): Promise<Pyt
111111
c: c,
112112
}));
113113
const selected = await showQuickPick(items, {
114-
placeHolder: 'Select a project creator',
114+
placeHolder: Pickers.Managers.selectProjectCreator,
115115
ignoreFocusOut: true,
116116
});
117117
return (selected as { c: PythonProjectCreator })?.c;

src/common/pickers/packages.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ import { Installable, PythonEnvironment, Package } from '../../api';
55
import { InternalPackageManager } from '../../internal.api';
66
import { EXTENSION_ROOT_DIR } from '../constants';
77
import { launchBrowser } from '../env.apis';
8-
import { Common, PackageManagement } from '../localize';
8+
import { Common, PackageManagement, Pickers } from '../localize';
99
import { traceWarn } from '../logging';
1010
import { showQuickPick, showInputBoxWithButtons, showTextDocument, showQuickPickWithButtons } from '../window.apis';
1111

1212
export async function pickPackageOptions(): Promise<string | undefined> {
1313
const items = [
1414
{
1515
label: Common.install,
16-
description: 'Install packages',
16+
description: Pickers.Packages.installPackages,
1717
},
1818
{
1919
label: Common.uninstall,
20-
description: 'Uninstall packages',
20+
description: Pickers.Packages.uninstallPackages,
2121
},
2222
];
2323
const selected = await showQuickPick(items, {
24-
placeHolder: 'Select an option',
24+
placeHolder: Pickers.Packages.selectOption,
2525
ignoreFocusOut: true,
2626
});
2727
return selected?.label;

src/common/pickers/projects.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from 'path';
22
import { QuickPickItem } from 'vscode';
33
import { PythonProject } from '../../api';
44
import { showQuickPick, showQuickPickWithButtons } from '../window.apis';
5+
import { Pickers } from '../localize';
56

67
interface ProjectQuickPickItem extends QuickPickItem {
78
project: PythonProject;
@@ -15,7 +16,7 @@ export async function pickProject(projects: ReadonlyArray<PythonProject>): Promi
1516
project: pw,
1617
}));
1718
const item = await showQuickPick(items, {
18-
placeHolder: 'Select a project, folder or script',
19+
placeHolder: Pickers.Project.selectProject,
1920
ignoreFocusOut: true,
2021
});
2122
if (item) {
@@ -38,7 +39,7 @@ export async function pickProjectMany(
3839
project: pw,
3940
}));
4041
const item = await showQuickPickWithButtons(items, {
41-
placeHolder: 'Select a project, folder or script',
42+
placeHolder: Pickers.Project.selectProjects,
4243
ignoreFocusOut: true,
4344
canPickMany: true,
4445
showBackButton: showBackButton,

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
registerAutoProjectProvider,
3636
registerExistingProjectProvider,
3737
} from './features/projectCreators';
38-
import { WorkspaceView } from './features/views/projectView';
38+
import { ProjectView } from './features/views/projectView';
3939
import { registerCompletionProvider } from './features/settings/settingCompletions';
4040
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
4141
import {
@@ -93,7 +93,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
9393
const managerView = new EnvManagerView(envManagers);
9494
context.subscriptions.push(managerView);
9595

96-
const workspaceView = new WorkspaceView(envManagers, projectManager);
96+
const workspaceView = new ProjectView(envManagers, projectManager);
9797
context.subscriptions.push(workspaceView);
9898

9999
workspaceView.initialize();

src/features/views/envManagersView.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
PackageRootInfoTreeItem,
2222
} from './treeViewItems';
2323
import { createSimpleDebounce } from '../../common/utils/debounce';
24+
import { ProjectViews } from '../../common/localize';
2425

2526
export class EnvManagerView implements TreeDataProvider<EnvTreeItem>, Disposable {
2627
private treeView: TreeView<EnvTreeItem>;
@@ -120,7 +121,7 @@ export class EnvManagerView implements TreeDataProvider<EnvTreeItem>, Disposable
120121
this.packageRoots.set(environment.envId.id, item);
121122
views.push(item);
122123
} else {
123-
views.push(new EnvInfoTreeItem(parent, 'No package manager found'));
124+
views.push(new EnvInfoTreeItem(parent, ProjectViews.noPackageManager));
124125
}
125126

126127
return views;
@@ -137,7 +138,7 @@ export class EnvManagerView implements TreeDataProvider<EnvTreeItem>, Disposable
137138
if (packages) {
138139
views.push(...packages.map((p) => new PackageTreeItem(p, root, manager)));
139140
} else {
140-
views.push(new PackageRootInfoTreeItem(root, 'No packages found'));
141+
views.push(new PackageRootInfoTreeItem(root, ProjectViews.noPackages));
141142
}
142143

143144
return views;

src/features/views/projectView.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import {
2525
} from './treeViewItems';
2626
import { onDidChangeConfiguration } from '../../common/workspace.apis';
2727
import { createSimpleDebounce } from '../../common/utils/debounce';
28+
import { ProjectViews } from '../../common/localize';
2829

29-
export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
30+
export class ProjectView implements TreeDataProvider<ProjectTreeItem> {
3031
private treeView: TreeView<ProjectTreeItem>;
3132
private _treeDataChanged: EventEmitter<ProjectTreeItem | ProjectTreeItem[] | null | undefined> = new EventEmitter<
3233
ProjectTreeItem | ProjectTreeItem[] | null | undefined
@@ -149,7 +150,7 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
149150
new NoProjectEnvironment(
150151
projectItem.project,
151152
projectItem,
152-
'Waiting for environment managers to load',
153+
ProjectViews.waitingForEnvManager,
153154
undefined,
154155
undefined,
155156
'$(loading~spin)',
@@ -164,8 +165,8 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
164165
new NoProjectEnvironment(
165166
projectItem.project,
166167
projectItem,
167-
'Environment manager not found',
168-
'Install an environment manager to get started. If you have installed then it might be loading.',
168+
ProjectViews.noEnvironmentManager,
169+
ProjectViews.noEnvironmentManagerDescription,
169170
),
170171
];
171172
}
@@ -176,7 +177,7 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
176177
new NoProjectEnvironment(
177178
projectItem.project,
178179
projectItem,
179-
`No environment provided by ${manager.displayName}`,
180+
`${ProjectViews.noEnvironmentProvided} ${manager.displayName}`,
180181
),
181182
];
182183
}
@@ -199,7 +200,7 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
199200
this.packageRoots.set(uri ? uri.fsPath : 'global', item);
200201
views.push(item);
201202
} else {
202-
views.push(new ProjectEnvironmentInfo(environmentItem, 'No package manager found'));
203+
views.push(new ProjectEnvironmentInfo(environmentItem, ProjectViews.noPackageManager));
203204
}
204205
return views;
205206
}
@@ -214,7 +215,7 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
214215
if (packages) {
215216
return packages.map((p) => new ProjectPackage(root, p, manager));
216217
} else {
217-
views.push(new ProjectPackageRootInfoTreeItem(root, 'No packages found'));
218+
views.push(new ProjectPackageRootInfoTreeItem(root, ProjectViews.noPackages));
218219
}
219220
}
220221

0 commit comments

Comments
 (0)