@@ -5,18 +5,63 @@ const options = getOptions()
55// TODO: Add proper types.
66/* eslint-disable @typescript-eslint/no-explicit-any */
77
8- let nlsConfig : any
8+ // NOTE@jsjoeio
9+ // This lives here ../../../lib/vscode/src/vs/base/common/platform.ts#L106
10+ export const nlsConfigElementId = "vscode-remote-nls-configuration"
11+
12+ type NlsConfiguration = {
13+ locale : string
14+ availableLanguages : { [ key : string ] : string } | { }
15+ _languagePackId ?: string
16+ _translationsConfigFile ?: string
17+ _cacheRoot ?: string
18+ _resolvedLanguagePackCoreLocation ?: string
19+ _corruptedFile ?: string
20+ _languagePackSupport ?: boolean
21+ loadBundle ?: any
22+ }
23+
24+ /**
25+ * A helper function to get the NLS Configuration settings.
26+ *
27+ * This is used by VSCode for localizations (i.e. changing
28+ * the display language).
29+ *
30+ * Make sure to wrap this in a try/catch block when you call it.
31+ **/
32+ export function getNlsConfiguration ( document : Document ) {
33+ const errorMsgPrefix = "[vscode]"
34+ const nlsConfigElement = document ?. getElementById ( nlsConfigElementId )
35+ const nlsConfig = nlsConfigElement ?. getAttribute ( "data-settings" )
36+
37+ if ( ! document ) {
38+ throw new Error ( `${ errorMsgPrefix } Could not parse NLS configuration. document is undefined.` )
39+ }
40+
41+ if ( ! nlsConfigElement ) {
42+ throw new Error (
43+ `${ errorMsgPrefix } Could not parse NLS configuration. Could not find nlsConfigElement with id: ${ nlsConfigElementId } ` ,
44+ )
45+ }
46+
47+ if ( ! nlsConfig ) {
48+ return undefined
49+ }
50+
51+ return JSON . parse ( nlsConfig ) as NlsConfiguration
52+ }
53+
954try {
10- nlsConfig = JSON . parse ( document . getElementById ( "vscode-remote-nls-configuration" ) ! . getAttribute ( "data-settings" ) ! )
11- if ( nlsConfig . _resolvedLanguagePackCoreLocation ) {
55+ const nlsConfig = getNlsConfiguration ( document )
56+ if ( nlsConfig ? ._resolvedLanguagePackCoreLocation ) {
1257 const bundles = Object . create ( null )
1358 nlsConfig . loadBundle = ( bundle : any , _language : any , cb : any ) : void => {
1459 const result = bundles [ bundle ]
1560 if ( result ) {
1661 return cb ( undefined , result )
1762 }
1863 // FIXME: Only works if path separators are /.
19- const path = nlsConfig . _resolvedLanguagePackCoreLocation + "/" + bundle . replace ( / \/ / g, "!" ) + ".nls.json"
64+ const path = nlsConfig ? ._resolvedLanguagePackCoreLocation + "/" + bundle . replace ( / \/ / g, "!" ) + ".nls.json"
2065 fetch ( `${ options . base } /vscode/resource/?path=${ encodeURIComponent ( path ) } ` )
2166 . then ( ( response ) => response . json ( ) )
2267 . then ( ( json ) => {
@@ -26,26 +71,25 @@ try {
2671 . catch ( cb )
2772 }
2873 }
74+ ; ( self . require as any ) = {
75+ // Without the full URL VS Code will try to load file://.
76+ baseUrl : `${ window . location . origin } ${ options . csStaticBase } /lib/vscode/out` ,
77+ recordStats : true ,
78+ paths : {
79+ "vscode-textmate" : `../node_modules/vscode-textmate/release/main` ,
80+ "vscode-oniguruma" : `../node_modules/vscode-oniguruma/release/main` ,
81+ xterm : `../node_modules/xterm/lib/xterm.js` ,
82+ "xterm-addon-search" : `../node_modules/xterm-addon-search/lib/xterm-addon-search.js` ,
83+ "xterm-addon-unicode11" : `../node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js` ,
84+ "xterm-addon-webgl" : `../node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js` ,
85+ "tas-client-umd" : `../node_modules/tas-client-umd/lib/tas-client-umd.js` ,
86+ "iconv-lite-umd" : `../node_modules/iconv-lite-umd/lib/iconv-lite-umd.js` ,
87+ jschardet : `../node_modules/jschardet/dist/jschardet.min.js` ,
88+ } ,
89+ "vs/nls" : nlsConfig ,
90+ }
2991} catch ( error ) {
30- /* Probably fine. */
31- }
32-
33- ; ( self . require as any ) = {
34- // Without the full URL VS Code will try to load file://.
35- baseUrl : `${ window . location . origin } ${ options . csStaticBase } /lib/vscode/out` ,
36- recordStats : true ,
37- paths : {
38- "vscode-textmate" : `../node_modules/vscode-textmate/release/main` ,
39- "vscode-oniguruma" : `../node_modules/vscode-oniguruma/release/main` ,
40- xterm : `../node_modules/xterm/lib/xterm.js` ,
41- "xterm-addon-search" : `../node_modules/xterm-addon-search/lib/xterm-addon-search.js` ,
42- "xterm-addon-unicode11" : `../node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js` ,
43- "xterm-addon-webgl" : `../node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js` ,
44- "tas-client-umd" : `../node_modules/tas-client-umd/lib/tas-client-umd.js` ,
45- "iconv-lite-umd" : `../node_modules/iconv-lite-umd/lib/iconv-lite-umd.js` ,
46- jschardet : `../node_modules/jschardet/dist/jschardet.min.js` ,
47- } ,
48- "vs/nls" : nlsConfig ,
92+ console . error ( error )
4993}
5094
5195try {
0 commit comments