Skip to content

Commit 19f2507

Browse files
committed
microsoft#45663 Use core translations asset
1 parent 0dd9617 commit 19f2507

3 files changed

Lines changed: 113 additions & 91 deletions

File tree

src/vs/platform/extensionManagement/common/extensionManagement.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export interface IGalleryExtensionAssets {
149149
icon: IGalleryExtensionAsset;
150150
license: IGalleryExtensionAsset;
151151
repository: IGalleryExtensionAsset;
152+
coreTranslations: { [languageId: string]: IGalleryExtensionAsset };
152153
}
153154

154155
export function isIExtensionIdentifier(thing: any): thing is IExtensionIdentifier {
@@ -262,6 +263,7 @@ export interface IExtensionGalleryService {
262263
getReadme(extension: IGalleryExtension): TPromise<string>;
263264
getManifest(extension: IGalleryExtension): TPromise<IExtensionManifest>;
264265
getChangelog(extension: IGalleryExtension): TPromise<string>;
266+
getCoreTranslations(extension: IGalleryExtension, languageId: string): TPromise<{}>;
265267
loadCompatibleVersion(extension: IGalleryExtension): TPromise<IGalleryExtension>;
266268
loadAllDependencies(dependencies: IExtensionIdentifier[]): TPromise<IGalleryExtension[]>;
267269
getExtensionsReport(): TPromise<IReportedExtension[]>;

src/vs/platform/extensionManagement/node/extensionGalleryService.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ function getStatistic(statistics: IRawGalleryExtensionStatistics[], name: string
201201
return result ? result.value : 0;
202202
}
203203

204+
function getCoreTranslationAssets(version: IRawGalleryExtensionVersion): { [languageId: string]: IGalleryExtensionAsset } {
205+
const coreTranslationAssetPrefix = 'Microsoft.VisualStudio.Code.Translation.';
206+
const result = version.files.filter(f => f.assetType.indexOf(coreTranslationAssetPrefix) === 0);
207+
return result.reduce((result, file) => {
208+
result[file.assetType.substring(coreTranslationAssetPrefix.length)] = getVersionAsset(version, file.assetType);
209+
return result;
210+
}, {});
211+
}
212+
204213
function getVersionAsset(version: IRawGalleryExtensionVersion, type: string): IGalleryExtensionAsset {
205214
const result = version.files.filter(f => f.assetType === type)[0];
206215

@@ -278,6 +287,7 @@ function toExtension(galleryExtension: IRawGalleryExtension, extensionsGalleryUr
278287
icon: getVersionAsset(version, AssetType.Icon),
279288
license: getVersionAsset(version, AssetType.License),
280289
repository: getVersionAsset(version, AssetType.Repository),
290+
coreTranslations: getCoreTranslationAssets(version)
281291
};
282292

283293
return {
@@ -516,6 +526,16 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
516526
.then(JSON.parse);
517527
}
518528

529+
getCoreTranslations(extension: IGalleryExtension, languageId: string): TPromise<{}> {
530+
const asset = extension.assets.coreTranslations[languageId];
531+
if (asset) {
532+
return this.getAsset(asset)
533+
.then(asText)
534+
.then(JSON.parse);
535+
}
536+
return TPromise.as(null);
537+
}
538+
519539
getChangelog(extension: IGalleryExtension): TPromise<string> {
520540
return this.getAsset(extension.assets.changelog)
521541
.then(asText);

src/vs/workbench/parts/localizations/electron-browser/localizations.contribution.ts

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,39 @@ export class LocalizationWorkbenchContribution extends Disposable implements IWo
9696
}
9797
}
9898

99+
private migrateToMarketplaceLanguagePack(language: string): void {
100+
this.isLanguageInstalled(language)
101+
.then(installed => {
102+
if (!installed) {
103+
this.getLanguagePackExtension(language)
104+
.then(extension => {
105+
if (extension) {
106+
this.notificationService.prompt(Severity.Warning, localize('install language pack', "In the near future, VS Code will only support language packs in the form of Marketplace extensions. Please install the '{0}' extension in order to continue to use the currently configured language. ", extension.displayName || extension.displayName),
107+
[
108+
{ label: localize('install', "Install"), run: () => this.installExtension(extension) },
109+
{ label: localize('more information', "More Information..."), run: () => window.open('https://go.microsoft.com/fwlink/?linkid=872941') }
110+
]);
111+
}
112+
});
113+
}
114+
});
115+
}
116+
99117
private checkAndInstall(): void {
100118
const language = platform.language;
101119
const locale = platform.locale;
120+
const languagePackSuggestionIgnoreList = <string[]>JSON.parse(this.storageService.get('extensionsAssistant/languagePackSuggestionIgnore', StorageScope.GLOBAL, '[]'));
121+
122+
if (!this.galleryService.isEnabled()) {
123+
return;
124+
}
102125
if (language !== 'en' && language !== 'en_us') {
103-
this.isLanguageInstalled(language)
104-
.then(installed => {
105-
if (!installed) {
106-
this.getLanguagePackExtension(language)
107-
.then(extension => {
108-
if (extension) {
109-
this.notificationService.prompt(Severity.Warning, localize('install language pack', "In the near future, VS Code will only support language packs in the form of Marketplace extensions. Please install the '{0}' extension in order to continue to use the currently configured language. ", extension.displayName || extension.displayName),
110-
[
111-
{ label: localize('install', "Install"), run: () => this.installExtension(extension) },
112-
{ label: localize('more information', "More Information..."), run: () => window.open('https://go.microsoft.com/fwlink/?linkid=872941') }
113-
]);
114-
}
115-
});
116-
}
117-
});
126+
this.migrateToMarketplaceLanguagePack(language);
127+
return;
128+
}
129+
if (locale === 'en' || locale === 'en_us') {
118130
return;
119131
}
120-
121-
const languagePackSuggestionIgnoreList = <string[]>JSON.parse(this.storageService.get
122-
('extensionsAssistant/languagePackSuggestionIgnore', StorageScope.GLOBAL, '[]'));
123-
124132
if (language === locale || languagePackSuggestionIgnoreList.indexOf(language) > -1) {
125133
return;
126134
}
@@ -146,86 +154,78 @@ export class LocalizationWorkbenchContribution extends Disposable implements IWo
146154
return;
147155
}
148156

149-
this.galleryService.getManifest(extensionToFetchTranslationsFrom).then(x => {
150-
if (!x.contributes || !x.contributes.localizations) {
151-
return;
152-
}
153-
const locContribution = x.contributes.localizations.filter(x => x.languageId.toLowerCase() === locale)[0];
154-
if (!locContribution) {
155-
return;
156-
}
157-
158-
const translations = {
159-
...minimumTranslatedStrings,
160-
...(locContribution.minimalTranslations || {})
161-
};
157+
this.galleryService.getCoreTranslations(extensionToFetchTranslationsFrom, locale)
158+
.then(coreTranslation => {
159+
const translations = {
160+
...minimumTranslatedStrings,
161+
...(coreTranslation ? coreTranslation['vs/platform/node/minimalTranslations'] : {})
162+
};
163+
const logUserReaction = (userReaction: string) => {
164+
/* __GDPR__
165+
"languagePackSuggestion:popup" : {
166+
"userReaction" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
167+
"language": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
168+
}
169+
*/
170+
this.telemetryService.publicLog('languagePackSuggestion:popup', { userReaction, language });
171+
};
162172

163-
const logUserReaction = (userReaction: string) => {
164-
/* __GDPR__
165-
"languagePackSuggestion:popup" : {
166-
"userReaction" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
167-
"language": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
173+
const searchAction = {
174+
label: translations['searchMarketplace'],
175+
run: () => {
176+
logUserReaction('search');
177+
this.viewletService.openViewlet(EXTENSIONS_VIEWLET_ID, true)
178+
.then(viewlet => viewlet as IExtensionsViewlet)
179+
.then(viewlet => {
180+
viewlet.search(`tag:lp-${locale}`);
181+
viewlet.focus();
182+
});
168183
}
169-
*/
170-
this.telemetryService.publicLog('languagePackSuggestion:popup', { userReaction, language });
171-
};
172-
173-
const searchAction = {
174-
label: translations['searchMarketplace'],
175-
run: () => {
176-
logUserReaction('search');
177-
this.viewletService.openViewlet(EXTENSIONS_VIEWLET_ID, true)
178-
.then(viewlet => viewlet as IExtensionsViewlet)
179-
.then(viewlet => {
180-
viewlet.search(`tag:lp-${locale}`);
181-
viewlet.focus();
182-
});
183-
}
184-
};
184+
};
185185

186-
const installAction = {
187-
label: translations['install'],
188-
run: () => {
189-
logUserReaction('install');
190-
this.installExtension(extensionToInstall);
191-
}
192-
};
186+
const installAction = {
187+
label: translations['install'],
188+
run: () => {
189+
logUserReaction('install');
190+
this.installExtension(extensionToInstall);
191+
}
192+
};
193193

194-
const installAndRestartAction = {
195-
label: translations['installAndRestart'],
196-
run: () => {
197-
logUserReaction('installAndRestart');
198-
this.installExtension(extensionToInstall).then(() => this.windowsService.relaunch({}));
199-
}
200-
};
194+
const installAndRestartAction = {
195+
label: translations['installAndRestart'],
196+
run: () => {
197+
logUserReaction('installAndRestart');
198+
this.installExtension(extensionToInstall).then(() => this.windowsService.relaunch({}));
199+
}
200+
};
201201

202-
const mainActions = extensionToInstall ? [installAndRestartAction, installAction] : [searchAction];
203-
const promptMessage = translations[extensionToInstall ? 'installAndRestartMessage' : 'showLanguagePackExtensions']
204-
.replace('{0}', locContribution.languageNameLocalized || locContribution.languageName || locale);
202+
const mainActions = extensionToInstall ? [installAndRestartAction, installAction] : [searchAction];
203+
const promptMessage = translations[extensionToInstall ? 'installAndRestartMessage' : 'showLanguagePackExtensions']
204+
.replace('{0}', locale);
205205

206-
this.notificationService.prompt(
207-
Severity.Info,
208-
promptMessage,
209-
[...mainActions,
210-
{
211-
label: localize('neverAgain', "Don't Show Again"),
212-
isSecondary: true,
213-
run: () => {
214-
languagePackSuggestionIgnoreList.push(language);
215-
this.storageService.store(
216-
'extensionsAssistant/languagePackSuggestionIgnore',
217-
JSON.stringify(languagePackSuggestionIgnoreList),
218-
StorageScope.GLOBAL
219-
);
220-
logUserReaction('neverShowAgain');
206+
this.notificationService.prompt(
207+
Severity.Info,
208+
promptMessage,
209+
[...mainActions,
210+
{
211+
label: localize('neverAgain', "Don't Show Again"),
212+
isSecondary: true,
213+
run: () => {
214+
languagePackSuggestionIgnoreList.push(language);
215+
this.storageService.store(
216+
'extensionsAssistant/languagePackSuggestionIgnore',
217+
JSON.stringify(languagePackSuggestionIgnoreList),
218+
StorageScope.GLOBAL
219+
);
220+
logUserReaction('neverShowAgain');
221+
}
222+
}],
223+
() => {
224+
logUserReaction('cancelled');
221225
}
222-
}],
223-
() => {
224-
logUserReaction('cancelled');
225-
}
226-
);
226+
);
227227

228-
});
228+
});
229229
});
230230
});
231231

0 commit comments

Comments
 (0)