File tree 3 files changed +26
-7
lines changed
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) {
131
131
}
132
132
}
133
133
134
+ export interface WorkerMessage {
135
+ event : 'init'
136
+ tsVersion : string
137
+ tsLocale ?: string
138
+ }
139
+
134
140
export function loadMonacoEnv ( store : Store ) {
135
141
; ( self as any ) . MonacoEnvironment = {
136
142
async getWorker ( _ : any , label : string ) {
@@ -142,7 +148,11 @@ export function loadMonacoEnv(store: Store) {
142
148
resolve ( )
143
149
}
144
150
} )
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 )
146
156
} )
147
157
await init
148
158
return worker
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
12
12
createLanguageHost ,
13
13
createServiceEnvironment ,
14
14
} from '@volar/monaco/worker'
15
- import type { WorkerHost } from './env'
15
+ import type { WorkerHost , WorkerMessage } from './env'
16
16
17
17
export interface CreateData {
18
18
tsconfig : {
@@ -22,22 +22,28 @@ export interface CreateData {
22
22
dependencies : { }
23
23
}
24
24
25
- const locale = navigator . language . toLowerCase ( )
25
+ let locale : string
26
26
27
27
let ts : typeof import ( 'typescript' )
28
28
let tsLocalized : any
29
29
30
- self . onmessage = async ( msg ) => {
30
+ self . onmessage = async ( msg : MessageEvent < WorkerMessage > ) => {
31
31
if ( msg . data ?. event === 'init' ) {
32
+ if ( msg . data . tsLocale ) {
33
+ locale = msg . data . tsLocale
34
+ }
35
+
32
36
; [ ts , tsLocalized ] = await Promise . all ( [
33
37
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
+ ) ,
37
42
] )
38
43
self . postMessage ( 'inited' )
39
44
return
40
45
}
46
+
41
47
worker . initialize (
42
48
(
43
49
ctx : monaco . worker . IWorkerContext < WorkerHost > ,
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ export interface StoreState {
86
86
vueRuntimeURL : string
87
87
vueServerRendererURL : string
88
88
typescriptVersion : string
89
+ typescriptLocale : string | undefined
89
90
// used to force reset the sandbox
90
91
resetFlip : boolean
91
92
}
@@ -168,6 +169,7 @@ export class ReplStore implements Store {
168
169
vueRuntimeURL : this . defaultVueRuntimeURL ,
169
170
vueServerRendererURL : this . defaultVueServerRendererURL ,
170
171
typescriptVersion : 'latest' ,
172
+ typescriptLocale : undefined ,
171
173
resetFlip : true ,
172
174
} )
173
175
@@ -187,6 +189,7 @@ export class ReplStore implements Store {
187
189
( ) => [
188
190
this . state . files [ tsconfigFile ] ?. code ,
189
191
this . state . typescriptVersion ,
192
+ this . state . typescriptLocale ,
190
193
] ,
191
194
( ) => reloadVue ( this )
192
195
)
You can’t perform that action at this time.
0 commit comments