Skip to content

Commit cf6884c

Browse files
committed
refactgor bootstrap-amd
1 parent cf1e93a commit cf6884c

2 files changed

Lines changed: 47 additions & 45 deletions

File tree

src/bootstrap-amd.js

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,10 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
var path = require('path');
7+
var fs = require('fs');
8+
var app = require('electron').app;
79
var loader = require('./vs/loader');
810

9-
// Duplicated in ../index.html for the renderes.
10-
function getNLSConfiguration() {
11-
if (process.env['VSCODE_NLS_CONFIG']) {
12-
return JSON.parse(process.env['VSCODE_NLS_CONFIG']);
13-
}
14-
15-
var locale = undefined;
16-
var localeOpts = '--locale';
17-
for (var i = 0; i < process.argv.length; i++) {
18-
var arg = process.argv[i];
19-
if (arg.slice(0, localeOpts.length) == localeOpts) {
20-
var segments = arg.split('=');
21-
locale = segments[1];
22-
break;
23-
}
24-
}
25-
26-
if (locale === 'pseudo') {
27-
return { availableLanguages: {}, pseudo: true }
28-
}
29-
if (process.env.VSCODE_DEV) {
30-
return { availableLanguages: {} };
31-
}
32-
// We have a built version so we have extracted nls file. Try to find
33-
// the right file to use.
34-
locale = locale || app.getLocale();
35-
while (locale) {
36-
var candidate = path.join(__dirname, 'main.nls.') + locale + '.js';
37-
if (fs.existsSync(candidate)) {
38-
return { availableLanguages: { '*': locale } };
39-
} else {
40-
var index = locale.lastIndexOf('-');
41-
if (index > 0) {
42-
locale = locale.substring(0, index);
43-
} else {
44-
locale = null;
45-
}
46-
}
47-
}
48-
49-
return { availableLanguages: {} };
50-
}
51-
5211
function uriFromPath(_path) {
5312
var pathName = path.resolve(_path).replace(/\\/g, '/');
5413

@@ -59,8 +18,8 @@ function uriFromPath(_path) {
5918
return encodeURI('file://' + pathName);
6019
}
6120

62-
var nlsConfig = getNLSConfiguration();
63-
process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig);
21+
var rawNlsConfig = process.env['VSCODE_NLS_CONFIG'];
22+
var nlsConfig = rawNlsConfig ? JSON.parse(rawNlsConfig) : { availableLanguages:{} };
6423

6524
loader.config({
6625
baseUrl: uriFromPath(path.join(__dirname)),

src/main.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,48 @@
77
global.vscodeStart = Date.now();
88

99
var app = require('electron').app;
10+
var fs = require('fs');
1011
var path = require('path');
1112

13+
// Duplicated in ../index.html for the renderes.
14+
function getNLSConfiguration() {
15+
var locale = undefined;
16+
var localeOpts = '--locale';
17+
for (var i = 0; i < process.argv.length; i++) {
18+
var arg = process.argv[i];
19+
if (arg.slice(0, localeOpts.length) == localeOpts) {
20+
var segments = arg.split('=');
21+
locale = segments[1];
22+
break;
23+
}
24+
}
25+
26+
if (locale === 'pseudo') {
27+
return { availableLanguages: {}, pseudo: true }
28+
}
29+
if (process.env.VSCODE_DEV) {
30+
return { availableLanguages: {} };
31+
}
32+
// We have a built version so we have extracted nls file. Try to find
33+
// the right file to use.
34+
locale = locale || app.getLocale();
35+
while (locale) {
36+
var candidate = path.join(__dirname, 'main.nls.') + locale + '.js';
37+
if (fs.existsSync(candidate)) {
38+
return { availableLanguages: { '*': locale } };
39+
} else {
40+
var index = locale.lastIndexOf('-');
41+
if (index > 0) {
42+
locale = locale.substring(0, index);
43+
} else {
44+
locale = null;
45+
}
46+
}
47+
}
48+
49+
return { availableLanguages: {} };
50+
}
51+
1252
// Change cwd if given via env variable
1353
try {
1454
if (process.env.VSCODE_CWD) {
@@ -31,6 +71,9 @@ app.on('open-file', function(event, path) {
3171
global.macOpenFiles.push(path);
3272
});
3373

74+
var nlsConfig = getNLSConfiguration();
75+
process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig);
76+
3477
// Load our code once ready
3578
app.once('ready', function() {
3679
process.env['AMD_ENTRYPOINT'] = 'vs/workbench/electron-main/main';

0 commit comments

Comments
 (0)