Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/localization/common/localization.contribution.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Disposable } from '../../../../base/common/lifecycle.js';
7
import { localize } from '../../../../nls.js';
8
import { registerAction2 } from '../../../../platform/actions/common/actions.js';
9
import { IExtensionManifest } from '../../../../platform/extensions/common/extensions.js';
10
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
11
import { Registry } from '../../../../platform/registry/common/platform.js';
12
import { IWorkbenchContribution } from '../../../common/contributions.js';
13
import { ClearDisplayLanguageAction, ConfigureDisplayLanguageAction } from './localizationsActions.js';
14
import { IExtensionFeatureTableRenderer, IRenderedData, ITableData, IRowData, IExtensionFeaturesRegistry, Extensions } from '../../../services/extensionManagement/common/extensionFeatures.js';
15
import { ExtensionsRegistry } from '../../../services/extensions/common/extensionsRegistry.js';
16
17
export class BaseLocalizationWorkbenchContribution extends Disposable implements IWorkbenchContribution {
18
constructor() {
19
super();
20
21
// Register action to configure locale and related settings
22
registerAction2(ConfigureDisplayLanguageAction);
23
registerAction2(ClearDisplayLanguageAction);
24
25
ExtensionsRegistry.registerExtensionPoint({
26
extensionPoint: 'localizations',
27
defaultExtensionKind: ['ui', 'workspace'],
28
jsonSchema: {
29
description: localize('vscode.extension.contributes.localizations', "Contributes localizations to the editor"),
30
type: 'array',
31
default: [],
32
items: {
33
type: 'object',
34
required: ['languageId', 'translations'],
35
defaultSnippets: [{ body: { languageId: '', languageName: '', localizedLanguageName: '', translations: [{ id: 'vscode', path: '' }] } }],
36
properties: {
37
languageId: {
38
description: localize('vscode.extension.contributes.localizations.languageId', 'Id of the language into which the display strings are translated.'),
39
type: 'string'
40
},
41
languageName: {
42
description: localize('vscode.extension.contributes.localizations.languageName', 'Name of the language in English.'),
43
type: 'string'
44
},
45
localizedLanguageName: {
46
description: localize('vscode.extension.contributes.localizations.languageNameLocalized', 'Name of the language in contributed language.'),
47
type: 'string'
48
},
49
translations: {
50
description: localize('vscode.extension.contributes.localizations.translations', 'List of translations associated to the language.'),
51
type: 'array',
52
default: [{ id: 'vscode', path: '' }],
53
items: {
54
type: 'object',
55
required: ['id', 'path'],
56
properties: {
57
id: {
58
type: 'string',
59
description: localize('vscode.extension.contributes.localizations.translations.id', "Id of VS Code or Extension for which this translation is contributed to. Id of VS Code is always `vscode` and of extension should be in format `publisherId.extensionName`."),
60
pattern: '^((vscode)|([a-z0-9A-Z][a-z0-9A-Z-]*)\\.([a-z0-9A-Z][a-z0-9A-Z-]*))$',
61
patternErrorMessage: localize('vscode.extension.contributes.localizations.translations.id.pattern', "Id should be `vscode` or in format `publisherId.extensionName` for translating VS code or an extension respectively.")
62
},
63
path: {
64
type: 'string',
65
description: localize('vscode.extension.contributes.localizations.translations.path', "A relative path to a file containing translations for the language.")
66
}
67
},
68
defaultSnippets: [{ body: { id: '', path: '' } }],
69
},
70
}
71
}
72
}
73
}
74
});
75
}
76
}
77
78
class LocalizationsDataRenderer extends Disposable implements IExtensionFeatureTableRenderer {
79
80
readonly type = 'table';
81
82
shouldRender(manifest: IExtensionManifest): boolean {
83
return !!manifest.contributes?.localizations;
84
}
85
86
render(manifest: IExtensionManifest): IRenderedData<ITableData> {
87
const localizations = manifest.contributes?.localizations || [];
88
if (!localizations.length) {
89
return { data: { headers: [], rows: [] }, dispose: () => { } };
90
}
91
92
const headers = [
93
localize('language id', "Language ID"),
94
localize('localizations language name', "Language Name"),
95
localize('localizations localized language name', "Language Name (Localized)"),
96
];
97
98
const rows: IRowData[][] = localizations
99
.sort((a, b) => a.languageId.localeCompare(b.languageId))
100
.map(localization => {
101
return [
102
localization.languageId,
103
localization.languageName ?? '',
104
localization.localizedLanguageName ?? ''
105
];
106
});
107
108
return {
109
data: {
110
headers,
111
rows
112
},
113
dispose: () => { }
114
};
115
}
116
}
117
118
Registry.as<IExtensionFeaturesRegistry>(Extensions.ExtensionFeaturesRegistry).registerExtensionFeature({
119
id: 'localizations',
120
label: localize('localizations', "Langauage Packs"),
121
access: {
122
canToggle: false
123
},
124
renderer: new SyncDescriptor(LocalizationsDataRenderer),
125
});
126
127