Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nls in the base worker #152887

Merged
merged 2 commits into from Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions build/gulpfile.editor.js
Expand Up @@ -38,8 +38,11 @@ const editorEntryPoints = [
name: 'vs/base/common/worker/simpleWorker',
include: ['vs/editor/common/services/editorSimpleWorker'],
exclude: ['vs/nls'],
prepend: [{ path: 'vs/loader.js' }],
append: [{ path: 'vs/base/worker/workerMain' }],
prepend: [
{ path: 'vs/loader.js' },
{ path: 'vs/nls.js', amdModuleId: 'vs/nls' },
{ path: 'vs/base/worker/workerMain.js' }
],
dest: 'vs/base/worker/workerMain.js'
}
];
Expand Down
4 changes: 2 additions & 2 deletions src/buildfile.js
Expand Up @@ -35,9 +35,9 @@ exports.base = [
exclude: ['vs/nls'],
prepend: [
{ path: 'vs/loader.js' },
{ path: 'vs/nls.js', amdModuleId: 'vs/nls' }
{ path: 'vs/nls.js', amdModuleId: 'vs/nls' },
{ path: 'vs/base/worker/workerMain.js' }
],
append: [{ path: 'vs/base/worker/workerMain' }],
dest: 'vs/base/worker/workerMain.js'
},
{
Expand Down
10 changes: 10 additions & 0 deletions src/vs/base/common/platform.ts
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';

const LANGUAGE_DEFAULT = 'en';

Expand Down Expand Up @@ -90,6 +91,15 @@ if (typeof navigator === 'object' && !isElectronRenderer) {
// Get the configuration from requirejs
loaderConfiguration = globals.requirejs.s.contexts._.config;
}

// TODO @TylerLeonhardt pull availableLanguages from vs/nls
// DO NOT REMOVE.
nls.localize({
// Prevents the string from being localized.
comment: ['{Locked}'],
key: 'ensureLoaderPluginIsLoaded'
}, 'this ensures the nls loader plugin is loaded before resolving the true locale');

const configuredLocale = loaderConfiguration?.['vs/nls']?.['availableLanguages']?.['*'] as string | undefined;
_locale = configuredLocale || navigator.language;

Expand Down
27 changes: 19 additions & 8 deletions src/vs/base/worker/workerMain.ts
Expand Up @@ -76,14 +76,18 @@
});
}

const loadCode = function (moduleId: string) {
function configureAMDLoader() {
require.config({
baseUrl: monacoBaseUrl,
catchError: true,
trustedTypesPolicy,
amdModulesPattern: /^vs\//
});
}

function loadCode(moduleId: string) {
loadAMDLoader().then(() => {
require.config({
baseUrl: monacoBaseUrl,
catchError: true,
trustedTypesPolicy,
amdModulesPattern: /^vs\//
});
configureAMDLoader();
require([moduleId], function (ws) {
setTimeout(function () {
const messageHandler = ws.create((msg: any, transfer?: Transferable[]) => {
Expand All @@ -97,7 +101,14 @@
}, 0);
});
});
};
}

// If the loader is already defined, configure it immediately
// This helps in the bundled case, where we must load nls files
// and they need a correct baseUrl to be loaded.
if (typeof (<any>self).define === 'function' && (<any>self).define.amd) {
configureAMDLoader();
}

let isFirstMessage = true;
const beforeReadyMessages: MessageEvent[] = [];
Expand Down