@theia/plugin-ext 1.37.0-next.16 → 1.37.0-next.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/language-pack-service.d.ts +16 -0
- package/lib/common/language-pack-service.d.ts.map +1 -0
- package/lib/common/language-pack-service.js +21 -0
- package/lib/common/language-pack-service.js.map +1 -0
- package/lib/common/plugin-api-rpc.d.ts +16 -0
- package/lib/common/plugin-api-rpc.d.ts.map +1 -1
- package/lib/common/plugin-api-rpc.js +2 -1
- package/lib/common/plugin-api-rpc.js.map +1 -1
- package/lib/common/plugin-protocol.d.ts +2 -0
- package/lib/common/plugin-protocol.d.ts.map +1 -1
- package/lib/common/plugin-protocol.js.map +1 -1
- package/lib/hosted/browser/hosted-plugin.js +1 -1
- package/lib/hosted/browser/hosted-plugin.js.map +1 -1
- package/lib/hosted/browser/worker/worker-main.js +4 -2
- package/lib/hosted/browser/worker/worker-main.js.map +1 -1
- package/lib/hosted/node/hosted-plugin-deployer-handler.js +2 -2
- package/lib/hosted/node/hosted-plugin-deployer-handler.js.map +1 -1
- package/lib/hosted/node/hosted-plugin-localization-service.d.ts +13 -1
- package/lib/hosted/node/hosted-plugin-localization-service.d.ts.map +1 -1
- package/lib/hosted/node/hosted-plugin-localization-service.js +122 -10
- package/lib/hosted/node/hosted-plugin-localization-service.js.map +1 -1
- package/lib/hosted/node/plugin-ext-hosted-backend-module.d.ts.map +1 -1
- package/lib/hosted/node/plugin-ext-hosted-backend-module.js +7 -0
- package/lib/hosted/node/plugin-ext-hosted-backend-module.js.map +1 -1
- package/lib/hosted/node/plugin-host-rpc.d.ts +2 -2
- package/lib/hosted/node/plugin-host-rpc.d.ts.map +1 -1
- package/lib/hosted/node/plugin-host-rpc.js +6 -4
- package/lib/hosted/node/plugin-host-rpc.js.map +1 -1
- package/lib/hosted/node/plugin-language-pack-service.d.ts +8 -0
- package/lib/hosted/node/plugin-language-pack-service.d.ts.map +1 -0
- package/lib/hosted/node/plugin-language-pack-service.js +54 -0
- package/lib/hosted/node/plugin-language-pack-service.js.map +1 -0
- package/lib/hosted/node/scanners/scanner-theia.d.ts.map +1 -1
- package/lib/hosted/node/scanners/scanner-theia.js +1 -0
- package/lib/hosted/node/scanners/scanner-theia.js.map +1 -1
- package/lib/main/browser/localization-main.d.ts +9 -0
- package/lib/main/browser/localization-main.d.ts.map +1 -0
- package/lib/main/browser/localization-main.js +32 -0
- package/lib/main/browser/localization-main.js.map +1 -0
- package/lib/main/browser/main-context.d.ts.map +1 -1
- package/lib/main/browser/main-context.js +3 -0
- package/lib/main/browser/main-context.js.map +1 -1
- package/lib/main/browser/plugin-ext-frontend-module.d.ts.map +1 -1
- package/lib/main/browser/plugin-ext-frontend-module.js +5 -0
- package/lib/main/browser/plugin-ext-frontend-module.js.map +1 -1
- package/lib/main/electron-browser/webview/electron-webview-widget-factory.d.ts +1 -0
- package/lib/main/electron-browser/webview/electron-webview-widget-factory.d.ts.map +1 -1
- package/lib/main/electron-browser/webview/electron-webview-widget-factory.js +4 -15
- package/lib/main/electron-browser/webview/electron-webview-widget-factory.js.map +1 -1
- package/lib/main/node/plugins-key-value-storage.js +1 -1
- package/lib/main/node/plugins-key-value-storage.js.map +1 -1
- package/lib/plugin/localization-ext.d.ts +17 -0
- package/lib/plugin/localization-ext.d.ts.map +1 -0
- package/lib/plugin/localization-ext.js +74 -0
- package/lib/plugin/localization-ext.js.map +1 -0
- package/lib/plugin/plugin-context.d.ts +2 -1
- package/lib/plugin/plugin-context.d.ts.map +1 -1
- package/lib/plugin/plugin-context.js +21 -1
- package/lib/plugin/plugin-context.js.map +1 -1
- package/lib/plugin/plugin-manager.d.ts +3 -2
- package/lib/plugin/plugin-manager.d.ts.map +1 -1
- package/lib/plugin/plugin-manager.js +3 -1
- package/lib/plugin/plugin-manager.js.map +1 -1
- package/package.json +26 -26
- package/src/common/language-pack-service.ts +34 -0
- package/src/common/plugin-api-rpc.ts +20 -1
- package/src/common/plugin-protocol.ts +2 -0
- package/src/hosted/browser/hosted-plugin.ts +1 -1
- package/src/hosted/browser/worker/worker-main.ts +5 -2
- package/src/hosted/node/hosted-plugin-deployer-handler.ts +2 -2
- package/src/hosted/node/hosted-plugin-localization-service.ts +132 -11
- package/src/hosted/node/plugin-ext-hosted-backend-module.ts +12 -0
- package/src/hosted/node/plugin-host-rpc.ts +8 -5
- package/src/hosted/node/plugin-language-pack-service.ts +43 -0
- package/src/hosted/node/scanners/scanner-theia.ts +1 -0
- package/src/main/browser/localization-main.ts +34 -0
- package/src/main/browser/main-context.ts +4 -0
- package/src/main/browser/plugin-ext-frontend-module.ts +6 -0
- package/src/main/electron-browser/webview/electron-webview-widget-factory.ts +4 -15
- package/src/main/node/plugins-key-value-storage.ts +1 -1
- package/src/plugin/localization-ext.ts +84 -0
- package/src/plugin/plugin-context.ts +25 -1
- package/src/plugin/plugin-manager.ts +4 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2023 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
|
+
|
|
19
|
+
import { nls } from '@theia/core';
|
|
20
|
+
import { Localization } from '@theia/core/lib/common/i18n/localization';
|
|
21
|
+
import { LocalizationExt, LocalizationMain, Plugin, PLUGIN_RPC_CONTEXT, StringDetails } from '../common';
|
|
22
|
+
import { LanguagePackBundle } from '../common/language-pack-service';
|
|
23
|
+
import { RPCProtocol } from '../common/rpc-protocol';
|
|
24
|
+
import { URI } from './types-impl';
|
|
25
|
+
|
|
26
|
+
export class LocalizationExtImpl implements LocalizationExt {
|
|
27
|
+
|
|
28
|
+
private readonly _proxy: LocalizationMain;
|
|
29
|
+
private currentLanguage?: string;
|
|
30
|
+
private isDefaultLanguage = true;
|
|
31
|
+
private readonly bundleCache = new Map<string, LanguagePackBundle | undefined>();
|
|
32
|
+
|
|
33
|
+
constructor(rpc: RPCProtocol) {
|
|
34
|
+
this._proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.LOCALIZATION_MAIN);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
translateMessage(pluginId: string, details: StringDetails): string {
|
|
38
|
+
const { message, args, comment } = details;
|
|
39
|
+
if (this.isDefaultLanguage) {
|
|
40
|
+
return Localization.format(message, (args ?? {}));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let key = message;
|
|
44
|
+
if (comment && comment.length > 0) {
|
|
45
|
+
key += `/${Array.isArray(comment) ? comment.join() : comment}`;
|
|
46
|
+
}
|
|
47
|
+
const str = this.bundleCache.get(pluginId)?.contents[key];
|
|
48
|
+
return Localization.format(str ?? message, (args ?? {}));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getBundle(pluginId: string): { [key: string]: string } | undefined {
|
|
52
|
+
return this.bundleCache.get(pluginId)?.contents;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getBundleUri(pluginId: string): URI | undefined {
|
|
56
|
+
const uri = this.bundleCache.get(pluginId)?.uri;
|
|
57
|
+
return uri ? URI.parse(uri) : undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async initializeLocalizedMessages(plugin: Plugin, currentLanguage: string): Promise<void> {
|
|
61
|
+
this.currentLanguage ??= currentLanguage;
|
|
62
|
+
this.isDefaultLanguage = this.currentLanguage === nls.defaultLocale;
|
|
63
|
+
|
|
64
|
+
if (this.isDefaultLanguage) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (this.bundleCache.has(plugin.model.id)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let bundle: LanguagePackBundle | undefined;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
bundle = await this._proxy.$fetchBundle(plugin.model.id);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.error(`Failed to load translations for ${plugin.model.id}: ${e.message}`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.bundleCache.set(plugin.model.id, bundle);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
@@ -234,6 +234,7 @@ import { PluginPackage } from '../common';
|
|
|
234
234
|
import { Endpoint } from '@theia/core/lib/browser/endpoint';
|
|
235
235
|
import { FilePermission } from '@theia/filesystem/lib/common/files';
|
|
236
236
|
import { TabsExtImpl } from './tabs';
|
|
237
|
+
import { LocalizationExtImpl } from './localization-ext';
|
|
237
238
|
|
|
238
239
|
export function createAPIFactory(
|
|
239
240
|
rpc: RPCProtocol,
|
|
@@ -245,7 +246,8 @@ export function createAPIFactory(
|
|
|
245
246
|
workspaceExt: WorkspaceExtImpl,
|
|
246
247
|
messageRegistryExt: MessageRegistryExt,
|
|
247
248
|
clipboard: ClipboardExt,
|
|
248
|
-
webviewExt: WebviewsExtImpl
|
|
249
|
+
webviewExt: WebviewsExtImpl,
|
|
250
|
+
localizationExt: LocalizationExtImpl
|
|
249
251
|
): PluginAPIFactory {
|
|
250
252
|
|
|
251
253
|
const authenticationExt = rpc.set(MAIN_RPC_CONTEXT.AUTHENTICATION_EXT, new AuthenticationExtImpl(rpc));
|
|
@@ -1073,6 +1075,27 @@ export function createAPIFactory(
|
|
|
1073
1075
|
}
|
|
1074
1076
|
};
|
|
1075
1077
|
|
|
1078
|
+
const l10n: typeof theia.l10n = {
|
|
1079
|
+
// eslint-disable-next-line max-len
|
|
1080
|
+
t(...params: [message: string, ...args: Array<string | number | boolean>] | [message: string, args: Record<string, any>] | [{ message: string; args?: Array<string | number | boolean> | Record<string, any>; comment: string | string[] }]): string {
|
|
1081
|
+
if (typeof params[0] === 'string') {
|
|
1082
|
+
const key = params.shift() as string;
|
|
1083
|
+
|
|
1084
|
+
// We have either rest args which are Array<string | number | boolean> or an array with a single Record<string, any>.
|
|
1085
|
+
// This ensures we get a Record<string | number, any> which will be formatted correctly.
|
|
1086
|
+
const argsFormatted = !params || typeof params[0] !== 'object' ? params : params[0];
|
|
1087
|
+
return localizationExt.translateMessage(plugin.model.id, { message: key, args: argsFormatted as Record<string | number, any> | undefined });
|
|
1088
|
+
}
|
|
1089
|
+
return localizationExt.translateMessage(plugin.model.id, params[0]);
|
|
1090
|
+
},
|
|
1091
|
+
get bundle() {
|
|
1092
|
+
return localizationExt.getBundle(plugin.model.id);
|
|
1093
|
+
},
|
|
1094
|
+
get uri() {
|
|
1095
|
+
return localizationExt.getBundleUri(plugin.model.id);
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
|
|
1076
1099
|
// notebooks API (@stubbed)
|
|
1077
1100
|
// The following implementation is temporarily `@stubbed` and marked as such under `theia.d.ts`
|
|
1078
1101
|
const notebooks: typeof theia.notebooks = {
|
|
@@ -1148,6 +1171,7 @@ export function createAPIFactory(
|
|
|
1148
1171
|
tasks,
|
|
1149
1172
|
scm,
|
|
1150
1173
|
notebooks,
|
|
1174
|
+
l10n,
|
|
1151
1175
|
tests,
|
|
1152
1176
|
// Types
|
|
1153
1177
|
StatusBarAlignment: StatusBarAlignment,
|
|
@@ -26,7 +26,8 @@ import {
|
|
|
26
26
|
ConfigStorage,
|
|
27
27
|
PluginManagerInitializeParams,
|
|
28
28
|
PluginManagerStartParams,
|
|
29
|
-
TerminalServiceExt
|
|
29
|
+
TerminalServiceExt,
|
|
30
|
+
LocalizationExt
|
|
30
31
|
} from '../common/plugin-api-rpc';
|
|
31
32
|
import { PluginMetadata, PluginJsonValidationContribution } from '../common/plugin-protocol';
|
|
32
33
|
import * as theia from '@theia/plugin';
|
|
@@ -122,6 +123,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
|
|
|
122
123
|
private readonly secrets: SecretsExtImpl,
|
|
123
124
|
private readonly preferencesManager: PreferenceRegistryExtImpl,
|
|
124
125
|
private readonly webview: WebviewsExtImpl,
|
|
126
|
+
private readonly localization: LocalizationExt,
|
|
125
127
|
private readonly rpc: RPCProtocol
|
|
126
128
|
) {
|
|
127
129
|
this.messageRegistryProxy = this.rpc.getProxy(PLUGIN_RPC_CONTEXT.MESSAGE_REGISTRY_MAIN);
|
|
@@ -398,6 +400,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
|
|
|
398
400
|
}
|
|
399
401
|
const id = plugin.model.displayName || plugin.model.id;
|
|
400
402
|
if (typeof pluginMain[plugin.lifecycle.startMethod] === 'function') {
|
|
403
|
+
await this.localization.initializeLocalizedMessages(plugin, this.envExt.language);
|
|
401
404
|
const pluginExport = await pluginMain[plugin.lifecycle.startMethod].apply(getGlobal(), [pluginContext]);
|
|
402
405
|
this.activatedPlugins.set(plugin.model.id, new ActivatedPlugin(pluginContext, pluginExport, stopFn));
|
|
403
406
|
} else {
|