diff --git a/src/bootstrap-amd.js b/src/bootstrap-amd.js index bcbb467b436..91aa1e9fad8 100644 --- a/src/bootstrap-amd.js +++ b/src/bootstrap-amd.js @@ -4,51 +4,10 @@ *--------------------------------------------------------------------------------------------*/ var path = require('path'); +var fs = require('fs'); +var app = require('electron').app; var loader = require('./vs/loader'); -// Duplicated in ../index.html for the renderes. -function getNLSConfiguration() { - if (process.env['VSCODE_NLS_CONFIG']) { - return JSON.parse(process.env['VSCODE_NLS_CONFIG']); - } - - var locale = undefined; - var localeOpts = '--locale'; - for (var i = 0; i < process.argv.length; i++) { - var arg = process.argv[i]; - if (arg.slice(0, localeOpts.length) == localeOpts) { - var segments = arg.split('='); - locale = segments[1]; - break; - } - } - - if (locale === 'pseudo') { - return { availableLanguages: {}, pseudo: true } - } - if (process.env.VSCODE_DEV) { - return { availableLanguages: {} }; - } - // We have a built version so we have extracted nls file. Try to find - // the right file to use. - locale = locale || app.getLocale(); - while (locale) { - var candidate = path.join(__dirname, 'main.nls.') + locale + '.js'; - if (fs.existsSync(candidate)) { - return { availableLanguages: { '*': locale } }; - } else { - var index = locale.lastIndexOf('-'); - if (index > 0) { - locale = locale.substring(0, index); - } else { - locale = null; - } - } - } - - return { availableLanguages: {} }; -} - function uriFromPath(_path) { var pathName = path.resolve(_path).replace(/\\/g, '/'); @@ -59,8 +18,8 @@ function uriFromPath(_path) { return encodeURI('file://' + pathName); } -var nlsConfig = getNLSConfiguration(); -process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig); +var rawNlsConfig = process.env['VSCODE_NLS_CONFIG']; +var nlsConfig = rawNlsConfig ? JSON.parse(rawNlsConfig) : { availableLanguages:{} }; loader.config({ baseUrl: uriFromPath(path.join(__dirname)), diff --git a/src/main.js b/src/main.js index 0a438771d46..c4cc3ae1f00 100644 --- a/src/main.js +++ b/src/main.js @@ -7,8 +7,48 @@ global.vscodeStart = Date.now(); var app = require('electron').app; +var fs = require('fs'); var path = require('path'); +// Duplicated in ../index.html for the renderes. +function getNLSConfiguration() { + var locale = undefined; + var localeOpts = '--locale'; + for (var i = 0; i < process.argv.length; i++) { + var arg = process.argv[i]; + if (arg.slice(0, localeOpts.length) == localeOpts) { + var segments = arg.split('='); + locale = segments[1]; + break; + } + } + + if (locale === 'pseudo') { + return { availableLanguages: {}, pseudo: true } + } + if (process.env.VSCODE_DEV) { + return { availableLanguages: {} }; + } + // We have a built version so we have extracted nls file. Try to find + // the right file to use. + locale = locale || app.getLocale(); + while (locale) { + var candidate = path.join(__dirname, 'main.nls.') + locale + '.js'; + if (fs.existsSync(candidate)) { + return { availableLanguages: { '*': locale } }; + } else { + var index = locale.lastIndexOf('-'); + if (index > 0) { + locale = locale.substring(0, index); + } else { + locale = null; + } + } + } + + return { availableLanguages: {} }; +} + // Change cwd if given via env variable try { if (process.env.VSCODE_CWD) { @@ -31,6 +71,9 @@ app.on('open-file', function(event, path) { global.macOpenFiles.push(path); }); +var nlsConfig = getNLSConfiguration(); +process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig); + // Load our code once ready app.once('ready', function() { process.env['AMD_ENTRYPOINT'] = 'vs/workbench/electron-main/main';