1
1
import * as fs from 'fs-extra' ;
2
2
import * as path from 'path' ;
3
- import { commands , MarkdownString , QuickInputButtons , Uri , window , workspace } from 'vscode' ;
3
+ import { commands , l10n , MarkdownString , QuickInputButtons , Uri , window , workspace } from 'vscode' ;
4
4
import { PythonProject , PythonProjectCreator , PythonProjectCreatorOptions } from '../../api' ;
5
5
import { NEW_PROJECT_TEMPLATES_FOLDER } from '../../common/constants' ;
6
6
import { showInputBoxWithButtons } from '../../common/window.apis' ;
@@ -15,10 +15,10 @@ import {
15
15
} from './creationHelpers' ;
16
16
17
17
export class NewPackageProject implements PythonProjectCreator {
18
- public readonly name = 'newPackage' ;
19
- public readonly displayName = 'Package' ;
20
- public readonly description = 'Creates a package folder in your current workspace' ;
21
- public readonly tooltip = new MarkdownString ( 'Create a new Python package' ) ;
18
+ public readonly name = l10n . t ( 'newPackage' ) ;
19
+ public readonly displayName = l10n . t ( 'Package' ) ;
20
+ public readonly description = l10n . t ( 'Creates a package folder in your current workspace' ) ;
21
+ public readonly tooltip = new MarkdownString ( l10n . t ( 'Create a new Python package' ) ) ;
22
22
23
23
constructor ( private readonly envManagers : EnvironmentManagers ) { }
24
24
@@ -38,16 +38,18 @@ export class NewPackageProject implements PythonProjectCreator {
38
38
if ( ! packageName ) {
39
39
try {
40
40
packageName = await showInputBoxWithButtons ( {
41
- prompt : 'What is the name of the package? (e.g. my_package)' ,
41
+ prompt : l10n . t ( 'What is the name of the package? (e.g. my_package)' ) ,
42
42
ignoreFocusOut : true ,
43
43
showBackButton : true ,
44
44
validateInput : ( value ) => {
45
45
// following PyPI (PEP 508) rules for package names
46
46
if ( ! / ^ ( [ a - z _ ] | [ a - z 0 - 9 _ ] [ a - z 0 - 9 . _ - ] * [ a - z 0 - 9 _ ] ) $ / i. test ( value ) ) {
47
- return 'Invalid package name. Use only letters, numbers, underscores, hyphens, or periods. Must start and end with a letter or number.' ;
47
+ return l10n . t (
48
+ 'Invalid package name. Use only letters, numbers, underscores, hyphens, or periods. Must start and end with a letter or number.' ,
49
+ ) ;
48
50
}
49
51
if ( / ^ [ - . _ 0 - 9 ] $ / i. test ( value ) ) {
50
- return 'Single-character package names cannot be a number, hyphen, or period.' ;
52
+ return l10n . t ( 'Single-character package names cannot be a number, hyphen, or period.' ) ;
51
53
}
52
54
return null ;
53
55
} ,
@@ -73,14 +75,10 @@ export class NewPackageProject implements PythonProjectCreator {
73
75
}
74
76
}
75
77
76
- window . showInformationMessage (
77
- `Creating a new Python project: ${ packageName } \nvenv: ${ createVenv } \nCopilot instructions: ${ createCopilotInstructions } ` ,
78
- ) ;
79
-
80
78
// 1. Copy template folder
81
79
const newPackageTemplateFolder = path . join ( NEW_PROJECT_TEMPLATES_FOLDER , 'newPackageTemplate' ) ;
82
80
if ( ! ( await fs . pathExists ( newPackageTemplateFolder ) ) ) {
83
- window . showErrorMessage ( 'Template folder does not exist, aborting creation.' ) ;
81
+ window . showErrorMessage ( l10n . t ( 'Template folder does not exist, aborting creation.' ) ) ;
84
82
return undefined ;
85
83
}
86
84
@@ -89,7 +87,7 @@ export class NewPackageProject implements PythonProjectCreator {
89
87
if ( ! destRoot ) {
90
88
const workspaceFolders = workspace . workspaceFolders ;
91
89
if ( ! workspaceFolders || workspaceFolders . length === 0 ) {
92
- window . showErrorMessage ( 'No workspace folder is open or provided, aborting creation.' ) ;
90
+ window . showErrorMessage ( l10n . t ( 'No workspace folder is open or provided, aborting creation.' ) ) ;
93
91
return undefined ;
94
92
}
95
93
destRoot = workspaceFolders [ 0 ] . uri . fsPath ;
@@ -99,7 +97,9 @@ export class NewPackageProject implements PythonProjectCreator {
99
97
const projectDestinationFolder = path . join ( destRoot , `${ packageName } _project` ) ;
100
98
if ( await fs . pathExists ( projectDestinationFolder ) ) {
101
99
window . showErrorMessage (
102
- 'A project folder by that name already exists, aborting creation. Please retry with a unique package name given your workspace.' ,
100
+ l10n . t (
101
+ 'A project folder by that name already exists, aborting creation. Please retry with a unique package name given your workspace.' ,
102
+ ) ,
103
103
) ;
104
104
return undefined ;
105
105
}
@@ -118,7 +118,7 @@ export class NewPackageProject implements PythonProjectCreator {
118
118
const pythonEnvironment = await this . envManagers . getEnvironment ( Uri . parse ( projectDestinationFolder ) ) ;
119
119
120
120
if ( ! pythonEnvironment ) {
121
- window . showErrorMessage ( 'Python environment not found.' ) ;
121
+ window . showErrorMessage ( l10n . t ( 'Python environment not found.' ) ) ;
122
122
return undefined ;
123
123
}
124
124
0 commit comments