2022-03-22 21:07:14 +01:00
|
|
|
Add display language support
|
|
|
|
|
2022-06-21 23:51:46 +02:00
|
|
|
We can remove this once upstream supports all language packs.
|
|
|
|
|
|
|
|
1. Proxies language packs to the service on the backend.
|
|
|
|
2. NLS configuration is embedded into the HTML for the browser to pick up. This
|
|
|
|
code to generate this configuration is copied from the native portion.
|
|
|
|
3. Remove navigator.language default since that will prevent the argv file from
|
|
|
|
being created if you are changing the language to whatever your browser
|
|
|
|
default happens to be.
|
|
|
|
4. Move the argv.json file to the server instead of in-browser storage. This is
|
|
|
|
where the current locale is stored and currently the server needs to be able
|
|
|
|
to read it.
|
|
|
|
5. Add the locale flag.
|
2022-03-22 21:07:14 +01:00
|
|
|
|
|
|
|
Index: code-server/lib/vscode/src/vs/server/node/serverServices.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/server/node/serverServices.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/server/node/serverServices.ts
|
2022-06-21 23:51:46 +02:00
|
|
|
@@ -202,6 +202,9 @@ export async function setupServerService
|
2022-03-22 21:07:14 +01:00
|
|
|
const channel = new ExtensionManagementChannel(extensionManagementService, (ctx: RemoteAgentConnectionContext) => getUriTransformer(ctx.remoteAuthority));
|
|
|
|
socketServer.registerChannel('extensions', channel);
|
|
|
|
|
2022-06-21 23:51:46 +02:00
|
|
|
+ const languagePackChannel = ProxyChannel.fromService<RemoteAgentConnectionContext>(accessor.get(ILanguagePackService));
|
|
|
|
+ socketServer.registerChannel('languagePacks', languagePackChannel);
|
2022-03-22 21:07:14 +01:00
|
|
|
+
|
|
|
|
const encryptionChannel = ProxyChannel.fromService<RemoteAgentConnectionContext>(accessor.get(IEncryptionMainService));
|
|
|
|
socketServer.registerChannel('encryption', encryptionChannel);
|
|
|
|
|
|
|
|
Index: code-server/lib/vscode/src/vs/base/common/platform.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/base/common/platform.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/base/common/platform.ts
|
2022-06-21 23:51:46 +02:00
|
|
|
@@ -80,8 +80,19 @@ if (typeof navigator === 'object' && !is
|
|
|
|
_isIOS = (_userAgent.indexOf('Macintosh') >= 0 || _userAgent.indexOf('iPad') >= 0 || _userAgent.indexOf('iPhone') >= 0) && !!navigator.maxTouchPoints && navigator.maxTouchPoints > 0;
|
|
|
|
_isLinux = _userAgent.indexOf('Linux') >= 0;
|
2022-03-22 21:07:14 +01:00
|
|
|
_isWeb = true;
|
2022-06-21 23:51:46 +02:00
|
|
|
- _locale = navigator.language;
|
|
|
|
+ _locale = LANGUAGE_DEFAULT;
|
2022-03-22 21:07:14 +01:00
|
|
|
_language = _locale;
|
|
|
|
+
|
|
|
|
+ const el = typeof document !== 'undefined' && document.getElementById('vscode-remote-nls-configuration');
|
|
|
|
+ const rawNlsConfig = el && el.getAttribute('data-settings');
|
|
|
|
+ if (rawNlsConfig) {
|
|
|
|
+ try {
|
|
|
|
+ const nlsConfig: NLSConfig = JSON.parse(rawNlsConfig);
|
|
|
|
+ _locale = nlsConfig.locale;
|
|
|
|
+ _translationsConfigFile = nlsConfig._translationsConfigFile;
|
|
|
|
+ _language = nlsConfig.availableLanguages['*'] || LANGUAGE_DEFAULT;
|
|
|
|
+ } catch (error) { /* Oh well. */ }
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Native environment
|
|
|
|
Index: code-server/lib/vscode/src/vs/code/browser/workbench/workbench.html
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/code/browser/workbench/workbench.html
|
|
|
|
+++ code-server/lib/vscode/src/vs/code/browser/workbench/workbench.html
|
|
|
|
@@ -23,6 +23,9 @@
|
|
|
|
<!-- Workbench Auth Session -->
|
|
|
|
<meta id="vscode-workbench-auth-session" data-settings="{{WORKBENCH_AUTH_SESSION}}">
|
|
|
|
|
|
|
|
+ <!-- NLS Configuration -->
|
|
|
|
+ <meta id="vscode-remote-nls-configuration" data-settings="{{NLS_CONFIGURATION}}">
|
|
|
|
+
|
|
|
|
<!-- Workbench Icon/Manifest/CSS -->
|
|
|
|
<link rel="icon" href="{{BASE}}/_static/src/browser/media/favicon-dark-support.svg" />
|
2022-06-21 23:51:46 +02:00
|
|
|
<link rel="alternate icon" href="{{BASE}}/_static/src/browser/media/favicon.ico" type="image/x-icon" />
|
|
|
|
@@ -43,17 +46,27 @@
|
|
|
|
self.webPackagePaths[key] = `${baseUrl}/node_modules/${key}/${self.webPackagePaths[key]}`;
|
|
|
|
});
|
|
|
|
|
|
|
|
- // Set up nls if the user is not using the default language (English)
|
|
|
|
const nlsConfig = {};
|
|
|
|
- const locale = navigator.language;
|
|
|
|
- if (!locale.startsWith('en')) {
|
|
|
|
- nlsConfig['vs/nls'] = {
|
|
|
|
- availableLanguages: {
|
|
|
|
- '*': locale
|
|
|
|
- },
|
|
|
|
- baseUrl: '{{WORKBENCH_NLS_BASE_URL}}'
|
|
|
|
- };
|
|
|
|
- }
|
2022-03-22 21:07:14 +01:00
|
|
|
+ try {
|
2022-06-21 23:51:46 +02:00
|
|
|
+ nlsConfig['vs/nls'] = JSON.parse(document.getElementById("vscode-remote-nls-configuration").getAttribute("data-settings"))
|
|
|
|
+ if (nlsConfig['vs/nls']._resolvedLanguagePackCoreLocation) {
|
2022-03-22 21:07:14 +01:00
|
|
|
+ const bundles = Object.create(null)
|
2022-06-21 23:51:46 +02:00
|
|
|
+ nlsConfig['vs/nls'].loadBundle = (bundle, _language, cb) => {
|
2022-03-22 21:07:14 +01:00
|
|
|
+ const result = bundles[bundle]
|
|
|
|
+ if (result) {
|
|
|
|
+ return cb(undefined, result)
|
|
|
|
+ }
|
2022-06-21 23:51:46 +02:00
|
|
|
+ const path = nlsConfig['vs/nls']._resolvedLanguagePackCoreLocation + "/" + bundle.replace(/\//g, "!") + ".nls.json"
|
2022-07-15 20:00:05 +02:00
|
|
|
+ fetch(`{{WORKBENCH_WEB_BASE_URL}}/../vscode-remote-resource?path=${encodeURIComponent(path)}`)
|
2022-03-22 21:07:14 +01:00
|
|
|
+ .then((response) => response.json())
|
|
|
|
+ .then((json) => {
|
|
|
|
+ bundles[bundle] = json
|
|
|
|
+ cb(undefined, json)
|
|
|
|
+ })
|
|
|
|
+ .catch(cb)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (error) { /* Probably fine. */ }
|
2022-06-21 23:51:46 +02:00
|
|
|
|
|
|
|
require.config({
|
|
|
|
baseUrl: `${baseUrl}/out`,
|
2022-03-22 21:07:14 +01:00
|
|
|
Index: code-server/lib/vscode/src/vs/platform/environment/common/environmentService.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/platform/environment/common/environmentService.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/platform/environment/common/environmentService.ts
|
2022-05-04 23:58:49 +02:00
|
|
|
@@ -108,7 +108,7 @@ export abstract class AbstractNativeEnvi
|
2022-03-22 21:07:14 +01:00
|
|
|
return URI.file(join(vscodePortable, 'argv.json'));
|
|
|
|
}
|
|
|
|
|
|
|
|
- return joinPath(this.userHome, this.productService.dataFolderName, 'argv.json');
|
|
|
|
+ return joinPath(this.appSettingsHome, 'argv.json');
|
|
|
|
}
|
|
|
|
|
|
|
|
@memoize
|
|
|
|
Index: code-server/lib/vscode/src/vs/server/node/remoteLanguagePacks.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/server/node/remoteLanguagePacks.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/server/node/remoteLanguagePacks.ts
|
|
|
|
@@ -30,6 +30,12 @@ export function getNLSConfiguration(lang
|
|
|
|
if (InternalNLSConfiguration.is(value)) {
|
|
|
|
value._languagePackSupport = true;
|
|
|
|
}
|
|
|
|
+ // If the configuration has no results keep trying since code-server
|
|
|
|
+ // doesn't restart when a language is installed so this result would
|
|
|
|
+ // persist (the plugin might not be installed yet for example).
|
|
|
|
+ if (value.locale !== 'en' && value.locale !== 'en-us' && Object.keys(value.availableLanguages).length === 0) {
|
|
|
|
+ _cache.delete(key);
|
|
|
|
+ }
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
_cache.set(key, result);
|
|
|
|
@@ -44,3 +50,43 @@ export namespace InternalNLSConfiguratio
|
|
|
|
return candidate && typeof candidate._languagePackId === 'string';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * The code below is copied from from src/main.js.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+export const getLocaleFromConfig = async (argvResource: string): Promise<string> => {
|
|
|
|
+ try {
|
|
|
|
+ const content = stripComments(await fs.promises.readFile(argvResource, 'utf8'));
|
|
|
|
+ return JSON.parse(content).locale;
|
|
|
|
+ } catch (error) {
|
|
|
|
+ if (error.code !== "ENOENT") {
|
|
|
|
+ console.warn(error)
|
|
|
|
+ }
|
|
|
|
+ return 'en';
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+const stripComments = (content: string): string => {
|
|
|
|
+ const regexp = /('(?:[^\\']*(?:\\.)?)*')|('(?:[^\\']*(?:\\.)?)*')|(\/\*(?:\r?\n|.)*?\*\/)|(\/{2,}.*?(?:(?:\r?\n)|$))/g;
|
|
|
|
+
|
|
|
|
+ return content.replace(regexp, (match, _m1, _m2, m3, m4) => {
|
|
|
|
+ // Only one of m1, m2, m3, m4 matches
|
|
|
|
+ if (m3) {
|
|
|
|
+ // A block comment. Replace with nothing
|
|
|
|
+ return '';
|
|
|
|
+ } else if (m4) {
|
|
|
|
+ // A line comment. If it ends in \r?\n then keep it.
|
|
|
|
+ const length_1 = m4.length;
|
|
|
|
+ if (length_1 > 2 && m4[length_1 - 1] === '\n') {
|
|
|
|
+ return m4[length_1 - 2] === '\r' ? '\r\n' : '\n';
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return '';
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // We match a string
|
|
|
|
+ return match;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/server/node/webClientServer.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/server/node/webClientServer.ts
|
2022-06-21 23:51:46 +02:00
|
|
|
@@ -26,6 +26,7 @@ import { URI } from 'vs/base/common/uri'
|
2022-03-22 21:07:14 +01:00
|
|
|
import { streamToBuffer } from 'vs/base/common/buffer';
|
|
|
|
import { IProductConfiguration } from 'vs/base/common/product';
|
|
|
|
import { isString } from 'vs/base/common/types';
|
|
|
|
+import { getLocaleFromConfig, getNLSConfiguration } from 'vs/server/node/remoteLanguagePacks';
|
2022-06-21 23:51:46 +02:00
|
|
|
import { CharCode } from 'vs/base/common/charCode';
|
|
|
|
import { getRemoteServerRootPath } from 'vs/platform/remote/common/remoteHosts';
|
|
|
|
|
|
|
|
@@ -295,6 +296,8 @@ export class WebClientServer {
|
2022-03-22 21:07:14 +01:00
|
|
|
|
|
|
|
const base = relativeRoot(getOriginalUrl(req))
|
|
|
|
const vscodeBase = relativePath(getOriginalUrl(req))
|
|
|
|
+ const locale = this._environmentService.args.locale || await getLocaleFromConfig(this._environmentService.argvResource.fsPath);
|
|
|
|
+ const nlsConfiguration = await getNLSConfiguration(locale, this._environmentService.userDataPath)
|
|
|
|
|
2022-06-21 23:51:46 +02:00
|
|
|
const workbenchWebConfiguration = {
|
|
|
|
remoteAuthority,
|
|
|
|
@@ -338,6 +341,7 @@ export class WebClientServer {
|
|
|
|
WORKBENCH_NLS_BASE_URL: vscodeBase + (nlsBaseUrl ? `${nlsBaseUrl}${this._productService.commit}/${this._productService.version}/` : ''),
|
|
|
|
BASE: base,
|
|
|
|
VS_BASE: vscodeBase,
|
|
|
|
+ NLS_CONFIGURATION: asJSON(nlsConfiguration),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-03-22 21:07:14 +01:00
|
|
|
Index: code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
|
2022-06-21 23:51:46 +02:00
|
|
|
@@ -15,6 +15,7 @@ export const serverOptions: OptionDescri
|
2022-03-22 21:07:14 +01:00
|
|
|
'disable-update-check': { type: 'boolean' },
|
|
|
|
'auth': { type: 'string' },
|
2022-06-21 23:51:46 +02:00
|
|
|
'disable-file-downloads': { type: 'boolean' },
|
2022-03-22 21:07:14 +01:00
|
|
|
+ 'locale': { type: 'string' },
|
|
|
|
|
|
|
|
/* ----- server setup ----- */
|
|
|
|
|
2022-06-21 23:51:46 +02:00
|
|
|
@@ -96,6 +97,7 @@ export interface ServerParsedArgs {
|
2022-03-22 21:07:14 +01:00
|
|
|
'disable-update-check'?: boolean;
|
|
|
|
'auth'?: string
|
2022-06-21 23:51:46 +02:00
|
|
|
'disable-file-downloads'?: boolean;
|
2022-03-22 21:07:14 +01:00
|
|
|
+ 'locale'?: string
|
|
|
|
|
|
|
|
/* ----- server setup ----- */
|
|
|
|
|
2022-06-21 23:51:46 +02:00
|
|
|
Index: code-server/lib/vscode/src/vs/workbench/workbench.web.main.ts
|
2022-03-22 21:07:14 +01:00
|
|
|
===================================================================
|
2022-06-21 23:51:46 +02:00
|
|
|
--- code-server.orig/lib/vscode/src/vs/workbench/workbench.web.main.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/workbench/workbench.web.main.ts
|
|
|
|
@@ -109,6 +109,12 @@ registerSingleton(IDiagnosticsService, N
|
|
|
|
|
|
|
|
//#region --- workbench contributions
|
|
|
|
|
|
|
|
+// Localization. These do not actually import anything specific to Electron so
|
|
|
|
+// they should be safe.
|
|
|
|
+import 'vs/workbench/services/localization/electron-sandbox/localeService';
|
|
|
|
+import 'vs/workbench/contrib/localization/electron-sandbox/localization.contribution';
|
|
|
|
+import 'vs/platform/languagePacks/browser/languagePacks';
|
2022-03-22 21:07:14 +01:00
|
|
|
+
|
2022-06-21 23:51:46 +02:00
|
|
|
// Output
|
|
|
|
import 'vs/workbench/contrib/output/common/outputChannelModelService';
|
|
|
|
|
|
|
|
Index: code-server/lib/vscode/src/vs/platform/languagePacks/browser/languagePacks.ts
|
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
|
|
|
+++ code-server/lib/vscode/src/vs/platform/languagePacks/browser/languagePacks.ts
|
|
|
|
@@ -0,0 +1,18 @@
|
2022-03-22 21:07:14 +01:00
|
|
|
+import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc';
|
|
|
|
+import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
2022-06-21 23:51:46 +02:00
|
|
|
+import { ILanguagePackService } from 'vs/platform/languagePacks/common/languagePacks';
|
2022-03-22 21:07:14 +01:00
|
|
|
+import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
|
|
|
|
+
|
|
|
|
+// @ts-ignore: interface is implemented via proxy
|
2022-06-21 23:51:46 +02:00
|
|
|
+export class LanguagePackService implements ILanguagePackService {
|
2022-03-22 21:07:14 +01:00
|
|
|
+
|
|
|
|
+ declare readonly _serviceBrand: undefined;
|
|
|
|
+
|
|
|
|
+ constructor(
|
|
|
|
+ @IRemoteAgentService remoteAgentService: IRemoteAgentService,
|
|
|
|
+ ) {
|
2022-06-21 23:51:46 +02:00
|
|
|
+ return ProxyChannel.toService<ILanguagePackService>(remoteAgentService.getConnection()!.getChannel('languagePacks'));
|
2022-03-22 21:07:14 +01:00
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
2022-06-21 23:51:46 +02:00
|
|
|
+registerSingleton(ILanguagePackService, LanguagePackService, true);
|