File tree Expand file tree Collapse file tree 4 files changed +95
-6
lines changed Expand file tree Collapse file tree 4 files changed +95
-6
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ export interface IMonacoSetup {
19
19
loaderConfigPaths : Record < string , string > ;
20
20
codiconUrl : string ;
21
21
monacoTypesUrl : string | undefined ;
22
+ language ?: string ;
22
23
}
23
24
24
25
let loading = false ;
@@ -57,7 +58,18 @@ async function _loadMonaco(setup: IMonacoSetup): Promise<typeof monaco> {
57
58
58
59
/** @type {any } */
59
60
const req = global . require as any ;
60
- req . config ( { paths : setup . loaderConfigPaths } ) ;
61
+
62
+ // Configure language if specified
63
+ const config : any = { paths : setup . loaderConfigPaths } ;
64
+ if ( setup . language ) {
65
+ config [ "vs/nls" ] = {
66
+ availableLanguages : {
67
+ "*" : setup . language ,
68
+ } ,
69
+ } ;
70
+ }
71
+
72
+ req . config ( config ) ;
61
73
62
74
return new Promise ( ( res ) => {
63
75
// First load editor.main. If it inlines the plugins, we don't want to try to load them from the server.
@@ -97,7 +109,10 @@ export const prodMonacoSetup = getMonacoSetup(
97
109
"node_modules/monaco-editor/min/vs"
98
110
) ;
99
111
100
- export function getMonacoSetup ( corePath : string ) : IMonacoSetup {
112
+ export function getMonacoSetup (
113
+ corePath : string ,
114
+ language ?: string
115
+ ) : IMonacoSetup {
101
116
const loaderConfigPaths = {
102
117
vs : `${ corePath } ` ,
103
118
} ;
@@ -107,5 +122,6 @@ export function getMonacoSetup(corePath: string): IMonacoSetup {
107
122
loaderConfigPaths,
108
123
codiconUrl : `${ corePath } /base/browser/ui/codicons/codicon/codicon.ttf` ,
109
124
monacoTypesUrl : undefined ,
125
+ language,
110
126
} ;
111
127
}
Original file line number Diff line number Diff line change 1
1
import * as React from "react" ;
2
2
import { PlaygroundModel } from "./PlaygroundModel" ;
3
3
import { observer } from "mobx-react" ;
4
- import { autorun , observable , reaction } from "mobx" ;
4
+ import { observable , reaction } from "mobx" ;
5
5
import {
6
6
IMessageFromRunner ,
7
7
IMessageToRunner ,
Original file line number Diff line number Diff line change @@ -390,6 +390,72 @@ export class SettingsDialog extends React.Component<{
390
390
</ Vertical >
391
391
</ div >
392
392
</ ListGroup . Item >
393
+
394
+ < ListGroup . Item >
395
+ < div className = "d-flex gap-2" >
396
+ < label className = "d-flex gap-2" >
397
+ < span >
398
+ Language/Localization
399
+ < small className = "d-block text-muted" >
400
+ Configure the Monaco Editor language
401
+ for UI elements. Leave unconfigured
402
+ to use default English.
403
+ </ small >
404
+ </ span >
405
+ </ label >
406
+ < Select
407
+ value = { ref (
408
+ modelSettings . settings ,
409
+ "language"
410
+ ) }
411
+ values = { [
412
+ undefined ,
413
+ "de" ,
414
+ "es" ,
415
+ "fr" ,
416
+ "it" ,
417
+ "ja" ,
418
+ "ko" ,
419
+ "ru" ,
420
+ "zh-cn" ,
421
+ "zh-tw" ,
422
+ ] }
423
+ getLabel = { ( v ) => {
424
+ switch ( v ) {
425
+ case undefined :
426
+ return "Unconfigured (English)" ;
427
+ case "de" :
428
+ return "German (Deutsch)" ;
429
+ case "es" :
430
+ return "Spanish (Español)" ;
431
+ case "fr" :
432
+ return "French (Français)" ;
433
+ case "it" :
434
+ return "Italian (Italiano)" ;
435
+ case "ja" :
436
+ return "Japanese (日本語)" ;
437
+ case "ko" :
438
+ return "Korean (한국어)" ;
439
+ case "ru" :
440
+ return "Russian (Русский)" ;
441
+ case "zh-cn" :
442
+ return "Chinese Simplified (简体中文)" ;
443
+ case "zh-tw" :
444
+ return "Chinese Traditional (繁體中文)" ;
445
+ default :
446
+ return (
447
+ v ||
448
+ "Unconfigured (English)"
449
+ ) ;
450
+ }
451
+ } }
452
+ style = { {
453
+ width : 250 ,
454
+ marginLeft : "auto" ,
455
+ } }
456
+ />
457
+ </ div >
458
+ </ ListGroup . Item >
393
459
</ ListGroup >
394
460
</ Modal . Body >
395
461
< Modal . Footer >
Original file line number Diff line number Diff line change @@ -88,6 +88,8 @@ export interface Settings {
88
88
89
89
previewFullScreen : boolean ;
90
90
autoReload : boolean | undefined ;
91
+
92
+ language ?: string ;
91
93
}
92
94
93
95
export type JsonString < T > = string ;
@@ -97,14 +99,18 @@ export function toLoaderConfig(settings: Settings): IMonacoSetup {
97
99
case "latest" :
98
100
return {
99
101
...getMonacoSetup (
100
- `node_modules/monaco-editor/${ settings . latestStability } /vs`
102
+ `node_modules/monaco-editor/${ settings . latestStability } /vs` ,
103
+ settings . language
101
104
) ,
102
105
monacoTypesUrl : "node_modules/monaco-editor/monaco.d.ts" ,
103
106
} ;
104
107
case "npm" :
105
108
const url = `https://cdn.jsdelivr.net/npm/monaco-editor@${ settings . npmVersion } ` ;
106
109
return {
107
- ...getMonacoSetup ( `${ url } /${ settings . npmStability } /vs` ) ,
110
+ ...getMonacoSetup (
111
+ `${ url } /${ settings . npmStability } /vs` ,
112
+ settings . language
113
+ ) ,
108
114
monacoTypesUrl : `${ url } /monaco.d.ts` ,
109
115
} ;
110
116
case "custom" :
@@ -143,7 +149,7 @@ export function toLoaderConfig(settings: Settings): IMonacoSetup {
143
149
break ;
144
150
}
145
151
146
- const setup = { ...getMonacoSetup ( coreUrl ) } ;
152
+ const setup = { ...getMonacoSetup ( coreUrl , settings . language ) } ;
147
153
if (
148
154
! setup . monacoTypesUrl &&
149
155
setup . loaderConfigPaths [ "vs" ] &&
@@ -186,6 +192,7 @@ export function getDefaultSettings(): Settings {
186
192
} ) ,
187
193
previewFullScreen : false ,
188
194
autoReload : true ,
195
+ language : undefined ,
189
196
} ;
190
197
return defaultSettings ;
191
198
}
You can’t perform that action at this time.
0 commit comments