3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { language } from 'vs/base/common/platform' ;
6
+ import { Language } from 'vs/base/common/platform' ;
7
7
import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
8
8
import { INotificationService , Severity } from 'vs/platform/notification/common/notification' ;
9
9
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing' ;
@@ -19,6 +19,9 @@ import { toAction } from 'vs/base/common/actions';
19
19
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles' ;
20
20
import { stripComments } from 'vs/base/common/stripComments' ;
21
21
import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
22
+ import { IHostService } from 'vs/workbench/services/host/browser/host' ;
23
+ import { IDialogService } from 'vs/platform/dialogs/common/dialogs' ;
24
+ import { IProductService } from 'vs/platform/product/common/productService' ;
22
25
23
26
export class NativeLocaleService implements ILocaleService {
24
27
_serviceBrand : undefined ;
@@ -32,7 +35,10 @@ export class NativeLocaleService implements ILocaleService {
32
35
@IExtensionManagementService private readonly extensionManagementService : IExtensionManagementService ,
33
36
@IProgressService private readonly progressService : IProgressService ,
34
37
@ITextFileService private readonly textFileService : ITextFileService ,
35
- @IEditorService private readonly editorService : IEditorService
38
+ @IEditorService private readonly editorService : IEditorService ,
39
+ @IDialogService private readonly dialogService : IDialogService ,
40
+ @IHostService private readonly hostService : IHostService ,
41
+ @IProductService private readonly productService : IProductService
36
42
) { }
37
43
38
44
private async validateLocaleFile ( ) : Promise < boolean > {
@@ -69,10 +75,10 @@ export class NativeLocaleService implements ILocaleService {
69
75
return true ;
70
76
}
71
77
72
- async setLocale ( languagePackItem : ILanguagePackItem ) : Promise < boolean > {
78
+ async setLocale ( languagePackItem : ILanguagePackItem ) : Promise < void > {
73
79
const locale = languagePackItem . id ;
74
- if ( locale === language || ( ! locale && language === 'en' ) ) {
75
- return false ;
80
+ if ( locale === Language . value ( ) || ( ! locale && Language . isDefaultVariant ( ) ) ) {
81
+ return ;
76
82
}
77
83
const installedLanguages = await this . languagePackService . getInstalledLanguages ( ) ;
78
84
try {
@@ -87,7 +93,7 @@ export class NativeLocaleService implements ILocaleService {
87
93
// as of now, there are no 3rd party language packs available on the Marketplace.
88
94
const viewlet = await this . paneCompositePartService . openPaneComposite ( EXTENSIONS_VIEWLET_ID , ViewContainerLocation . Sidebar ) ;
89
95
( viewlet ?. getViewPaneContainer ( ) as IExtensionsViewPaneContainer ) . search ( `@id:${ languagePackItem . extensionId } ` ) ;
90
- return false ;
96
+ return ;
91
97
}
92
98
93
99
await this . progressService . withProgress (
@@ -102,22 +108,40 @@ export class NativeLocaleService implements ILocaleService {
102
108
) ;
103
109
}
104
110
105
- return await this . writeLocaleValue ( locale ) ;
111
+ if ( await this . writeLocaleValue ( locale ) ) {
112
+ await this . showRestartDialog ( languagePackItem . label ) ;
113
+ }
106
114
} catch ( err ) {
107
115
this . notificationService . error ( err ) ;
108
- return false ;
109
116
}
110
117
}
111
118
112
- async clearLocalePreference ( ) : Promise < boolean > {
113
- if ( language === 'en' ) {
114
- return false ;
115
- }
119
+ async clearLocalePreference ( ) : Promise < void > {
116
120
try {
117
- return await this . writeLocaleValue ( undefined ) ;
121
+ await this . writeLocaleValue ( undefined ) ;
122
+ if ( ! Language . isDefaultVariant ( ) ) {
123
+ await this . showRestartDialog ( 'English' ) ;
124
+ }
118
125
} catch ( err ) {
119
126
this . notificationService . error ( err ) ;
120
- return false ;
127
+ }
128
+ }
129
+
130
+ private async showRestartDialog ( languageName : string ) {
131
+ const restartDialog = await this . dialogService . confirm ( {
132
+ type : 'info' ,
133
+ message : localize ( 'restartDisplayLanguageMessage' , "{0} needs to restart to change the display language" , this . productService . nameLong ) ,
134
+ detail : localize (
135
+ 'restartDisplayLanguageDetail' ,
136
+ "Press the restart button to restart {0} and set the display language to {1}." ,
137
+ this . productService . nameLong ,
138
+ languageName
139
+ ) ,
140
+ primaryButton : localize ( { key : 'restart' , comment : [ '&& denotes a mnemonic character' ] } , "&&Restart" ) ,
141
+ } ) ;
142
+
143
+ if ( restartDialog . confirmed ) {
144
+ this . hostService . restart ( ) ;
121
145
}
122
146
}
123
147
}
0 commit comments