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 {
1919 loaderConfigPaths : Record < string , string > ;
2020 codiconUrl : string ;
2121 monacoTypesUrl : string | undefined ;
22+ language ?: string ;
2223}
2324
2425let loading = false ;
@@ -57,7 +58,18 @@ async function _loadMonaco(setup: IMonacoSetup): Promise<typeof monaco> {
5758
5859 /** @type {any } */
5960 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 ) ;
6173
6274 return new Promise ( ( res ) => {
6375 // 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(
97109 "node_modules/monaco-editor/min/vs"
98110) ;
99111
100- export function getMonacoSetup ( corePath : string ) : IMonacoSetup {
112+ export function getMonacoSetup (
113+ corePath : string ,
114+ language ?: string
115+ ) : IMonacoSetup {
101116 const loaderConfigPaths = {
102117 vs : `${ corePath } ` ,
103118 } ;
@@ -107,5 +122,6 @@ export function getMonacoSetup(corePath: string): IMonacoSetup {
107122 loaderConfigPaths,
108123 codiconUrl : `${ corePath } /base/browser/ui/codicons/codicon/codicon.ttf` ,
109124 monacoTypesUrl : undefined ,
125+ language,
110126 } ;
111127}
Original file line number Diff line number Diff line change 11import * as React from "react" ;
22import { PlaygroundModel } from "./PlaygroundModel" ;
33import { observer } from "mobx-react" ;
4- import { autorun , observable , reaction } from "mobx" ;
4+ import { observable , reaction } from "mobx" ;
55import {
66 IMessageFromRunner ,
77 IMessageToRunner ,
Original file line number Diff line number Diff line change @@ -390,6 +390,72 @@ export class SettingsDialog extends React.Component<{
390390 </ Vertical >
391391 </ div >
392392 </ 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 >
393459 </ ListGroup >
394460 </ Modal . Body >
395461 < Modal . Footer >
Original file line number Diff line number Diff line change @@ -88,6 +88,8 @@ export interface Settings {
8888
8989 previewFullScreen : boolean ;
9090 autoReload : boolean | undefined ;
91+
92+ language ?: string ;
9193}
9294
9395export type JsonString < T > = string ;
@@ -97,14 +99,18 @@ export function toLoaderConfig(settings: Settings): IMonacoSetup {
9799 case "latest" :
98100 return {
99101 ...getMonacoSetup (
100- `node_modules/monaco-editor/${ settings . latestStability } /vs`
102+ `node_modules/monaco-editor/${ settings . latestStability } /vs` ,
103+ settings . language
101104 ) ,
102105 monacoTypesUrl : "node_modules/monaco-editor/monaco.d.ts" ,
103106 } ;
104107 case "npm" :
105108 const url = `https://cdn.jsdelivr.net/npm/monaco-editor@${ settings . npmVersion } ` ;
106109 return {
107- ...getMonacoSetup ( `${ url } /${ settings . npmStability } /vs` ) ,
110+ ...getMonacoSetup (
111+ `${ url } /${ settings . npmStability } /vs` ,
112+ settings . language
113+ ) ,
108114 monacoTypesUrl : `${ url } /monaco.d.ts` ,
109115 } ;
110116 case "custom" :
@@ -143,7 +149,7 @@ export function toLoaderConfig(settings: Settings): IMonacoSetup {
143149 break ;
144150 }
145151
146- const setup = { ...getMonacoSetup ( coreUrl ) } ;
152+ const setup = { ...getMonacoSetup ( coreUrl , settings . language ) } ;
147153 if (
148154 ! setup . monacoTypesUrl &&
149155 setup . loaderConfigPaths [ "vs" ] &&
@@ -186,6 +192,7 @@ export function getDefaultSettings(): Settings {
186192 } ) ,
187193 previewFullScreen : false ,
188194 autoReload : true ,
195+ language : undefined ,
189196 } ;
190197 return defaultSettings ;
191198}
You can’t perform that action at this time.
0 commit comments