File tree Expand file tree Collapse file tree 3 files changed +26
-7
lines changed
Expand file tree Collapse file tree 3 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,12 @@ export async function reloadVue(store: Store) {
131131 }
132132}
133133
134+ export interface WorkerMessage {
135+ event : 'init'
136+ tsVersion : string
137+ tsLocale ?: string
138+ }
139+
134140export function loadMonacoEnv ( store : Store ) {
135141 ; ( self as any ) . MonacoEnvironment = {
136142 async getWorker ( _ : any , label : string ) {
@@ -142,7 +148,11 @@ export function loadMonacoEnv(store: Store) {
142148 resolve ( )
143149 }
144150 } )
145- worker . postMessage ( { event : 'init' , tsVersion : store . state . typescriptVersion } )
151+ worker . postMessage ( {
152+ event : 'init' ,
153+ tsVersion : store . state . typescriptVersion ,
154+ tsLocale : store . state . typescriptLocale ,
155+ } satisfies WorkerMessage )
146156 } )
147157 await init
148158 return worker
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
1212 createLanguageHost ,
1313 createServiceEnvironment ,
1414} from '@volar/monaco/worker'
15- import type { WorkerHost } from './env'
15+ import type { WorkerHost , WorkerMessage } from './env'
1616
1717export interface CreateData {
1818 tsconfig : {
@@ -22,22 +22,28 @@ export interface CreateData {
2222 dependencies : { }
2323}
2424
25- const locale = navigator . language . toLowerCase ( )
25+ let locale : string
2626
2727let ts : typeof import ( 'typescript' )
2828let tsLocalized : any
2929
30- self . onmessage = async ( msg ) => {
30+ self . onmessage = async ( msg : MessageEvent < WorkerMessage > ) => {
3131 if ( msg . data ?. event === 'init' ) {
32+ if ( msg . data . tsLocale ) {
33+ locale = msg . data . tsLocale
34+ }
35+
3236 ; [ ts , tsLocalized ] = await Promise . all ( [
3337 importTsFromCdn ( msg . data . tsVersion ) ,
34- fetchJson (
35- `https://cdn.jsdelivr.net/npm/typescript@${ msg . data . tsVersion } /lib/${ locale } /diagnosticMessages.generated.json`
36- ) ,
38+ locale &&
39+ fetchJson (
40+ `https://cdn.jsdelivr.net/npm/typescript@${ msg . data . tsVersion } /lib/${ locale } /diagnosticMessages.generated.json`
41+ ) ,
3742 ] )
3843 self . postMessage ( 'inited' )
3944 return
4045 }
46+
4147 worker . initialize (
4248 (
4349 ctx : monaco . worker . IWorkerContext < WorkerHost > ,
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ export interface StoreState {
8686 vueRuntimeURL : string
8787 vueServerRendererURL : string
8888 typescriptVersion : string
89+ typescriptLocale : string | undefined
8990 // used to force reset the sandbox
9091 resetFlip : boolean
9192}
@@ -168,6 +169,7 @@ export class ReplStore implements Store {
168169 vueRuntimeURL : this . defaultVueRuntimeURL ,
169170 vueServerRendererURL : this . defaultVueServerRendererURL ,
170171 typescriptVersion : 'latest' ,
172+ typescriptLocale : undefined ,
171173 resetFlip : true ,
172174 } )
173175
@@ -187,6 +189,7 @@ export class ReplStore implements Store {
187189 ( ) => [
188190 this . state . files [ tsconfigFile ] ?. code ,
189191 this . state . typescriptVersion ,
192+ this . state . typescriptLocale ,
190193 ] ,
191194 ( ) => reloadVue ( this )
192195 )
You can’t perform that action at this time.
0 commit comments