提交 19f2507f 编写于 作者: S Sandeep Somavarapu

#45663 Use core translations asset

上级 0dd96174
......@@ -149,6 +149,7 @@ export interface IGalleryExtensionAssets {
icon: IGalleryExtensionAsset;
license: IGalleryExtensionAsset;
repository: IGalleryExtensionAsset;
coreTranslations: { [languageId: string]: IGalleryExtensionAsset };
}
export function isIExtensionIdentifier(thing: any): thing is IExtensionIdentifier {
......@@ -262,6 +263,7 @@ export interface IExtensionGalleryService {
getReadme(extension: IGalleryExtension): TPromise<string>;
getManifest(extension: IGalleryExtension): TPromise<IExtensionManifest>;
getChangelog(extension: IGalleryExtension): TPromise<string>;
getCoreTranslations(extension: IGalleryExtension, languageId: string): TPromise<{}>;
loadCompatibleVersion(extension: IGalleryExtension): TPromise<IGalleryExtension>;
loadAllDependencies(dependencies: IExtensionIdentifier[]): TPromise<IGalleryExtension[]>;
getExtensionsReport(): TPromise<IReportedExtension[]>;
......
......@@ -201,6 +201,15 @@ function getStatistic(statistics: IRawGalleryExtensionStatistics[], name: string
return result ? result.value : 0;
}
function getCoreTranslationAssets(version: IRawGalleryExtensionVersion): { [languageId: string]: IGalleryExtensionAsset } {
const coreTranslationAssetPrefix = 'Microsoft.VisualStudio.Code.Translation.';
const result = version.files.filter(f => f.assetType.indexOf(coreTranslationAssetPrefix) === 0);
return result.reduce((result, file) => {
result[file.assetType.substring(coreTranslationAssetPrefix.length)] = getVersionAsset(version, file.assetType);
return result;
}, {});
}
function getVersionAsset(version: IRawGalleryExtensionVersion, type: string): IGalleryExtensionAsset {
const result = version.files.filter(f => f.assetType === type)[0];
......@@ -278,6 +287,7 @@ function toExtension(galleryExtension: IRawGalleryExtension, extensionsGalleryUr
icon: getVersionAsset(version, AssetType.Icon),
license: getVersionAsset(version, AssetType.License),
repository: getVersionAsset(version, AssetType.Repository),
coreTranslations: getCoreTranslationAssets(version)
};
return {
......@@ -516,6 +526,16 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
.then(JSON.parse);
}
getCoreTranslations(extension: IGalleryExtension, languageId: string): TPromise<{}> {
const asset = extension.assets.coreTranslations[languageId];
if (asset) {
return this.getAsset(asset)
.then(asText)
.then(JSON.parse);
}
return TPromise.as(null);
}
getChangelog(extension: IGalleryExtension): TPromise<string> {
return this.getAsset(extension.assets.changelog)
.then(asText);
......
......@@ -96,31 +96,39 @@ export class LocalizationWorkbenchContribution extends Disposable implements IWo
}
}
private migrateToMarketplaceLanguagePack(language: string): void {
this.isLanguageInstalled(language)
.then(installed => {
if (!installed) {
this.getLanguagePackExtension(language)
.then(extension => {
if (extension) {
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),
[
{ label: localize('install', "Install"), run: () => this.installExtension(extension) },
{ label: localize('more information', "More Information..."), run: () => window.open('https://go.microsoft.com/fwlink/?linkid=872941') }
]);
}
});
}
});
}
private checkAndInstall(): void {
const language = platform.language;
const locale = platform.locale;
const languagePackSuggestionIgnoreList = <string[]>JSON.parse(this.storageService.get('extensionsAssistant/languagePackSuggestionIgnore', StorageScope.GLOBAL, '[]'));
if (!this.galleryService.isEnabled()) {
return;
}
if (language !== 'en' && language !== 'en_us') {
this.isLanguageInstalled(language)
.then(installed => {
if (!installed) {
this.getLanguagePackExtension(language)
.then(extension => {
if (extension) {
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),
[
{ label: localize('install', "Install"), run: () => this.installExtension(extension) },
{ label: localize('more information', "More Information..."), run: () => window.open('https://go.microsoft.com/fwlink/?linkid=872941') }
]);
}
});
}
});
this.migrateToMarketplaceLanguagePack(language);
return;
}
if (locale === 'en' || locale === 'en_us') {
return;
}
const languagePackSuggestionIgnoreList = <string[]>JSON.parse(this.storageService.get
('extensionsAssistant/languagePackSuggestionIgnore', StorageScope.GLOBAL, '[]'));
if (language === locale || languagePackSuggestionIgnoreList.indexOf(language) > -1) {
return;
}
......@@ -146,86 +154,78 @@ export class LocalizationWorkbenchContribution extends Disposable implements IWo
return;
}
this.galleryService.getManifest(extensionToFetchTranslationsFrom).then(x => {
if (!x.contributes || !x.contributes.localizations) {
return;
}
const locContribution = x.contributes.localizations.filter(x => x.languageId.toLowerCase() === locale)[0];
if (!locContribution) {
return;
}
const translations = {
...minimumTranslatedStrings,
...(locContribution.minimalTranslations || {})
};
this.galleryService.getCoreTranslations(extensionToFetchTranslationsFrom, locale)
.then(coreTranslation => {
const translations = {
...minimumTranslatedStrings,
...(coreTranslation ? coreTranslation['vs/platform/node/minimalTranslations'] : {})
};
const logUserReaction = (userReaction: string) => {
/* __GDPR__
"languagePackSuggestion:popup" : {
"userReaction" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"language": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryService.publicLog('languagePackSuggestion:popup', { userReaction, language });
};
const logUserReaction = (userReaction: string) => {
/* __GDPR__
"languagePackSuggestion:popup" : {
"userReaction" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"language": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
const searchAction = {
label: translations['searchMarketplace'],
run: () => {
logUserReaction('search');
this.viewletService.openViewlet(EXTENSIONS_VIEWLET_ID, true)
.then(viewlet => viewlet as IExtensionsViewlet)
.then(viewlet => {
viewlet.search(`tag:lp-${locale}`);
viewlet.focus();
});
}
*/
this.telemetryService.publicLog('languagePackSuggestion:popup', { userReaction, language });
};
const searchAction = {
label: translations['searchMarketplace'],
run: () => {
logUserReaction('search');
this.viewletService.openViewlet(EXTENSIONS_VIEWLET_ID, true)
.then(viewlet => viewlet as IExtensionsViewlet)
.then(viewlet => {
viewlet.search(`tag:lp-${locale}`);
viewlet.focus();
});
}
};
};
const installAction = {
label: translations['install'],
run: () => {
logUserReaction('install');
this.installExtension(extensionToInstall);
}
};
const installAction = {
label: translations['install'],
run: () => {
logUserReaction('install');
this.installExtension(extensionToInstall);
}
};
const installAndRestartAction = {
label: translations['installAndRestart'],
run: () => {
logUserReaction('installAndRestart');
this.installExtension(extensionToInstall).then(() => this.windowsService.relaunch({}));
}
};
const installAndRestartAction = {
label: translations['installAndRestart'],
run: () => {
logUserReaction('installAndRestart');
this.installExtension(extensionToInstall).then(() => this.windowsService.relaunch({}));
}
};
const mainActions = extensionToInstall ? [installAndRestartAction, installAction] : [searchAction];
const promptMessage = translations[extensionToInstall ? 'installAndRestartMessage' : 'showLanguagePackExtensions']
.replace('{0}', locContribution.languageNameLocalized || locContribution.languageName || locale);
const mainActions = extensionToInstall ? [installAndRestartAction, installAction] : [searchAction];
const promptMessage = translations[extensionToInstall ? 'installAndRestartMessage' : 'showLanguagePackExtensions']
.replace('{0}', locale);
this.notificationService.prompt(
Severity.Info,
promptMessage,
[...mainActions,
{
label: localize('neverAgain', "Don't Show Again"),
isSecondary: true,
run: () => {
languagePackSuggestionIgnoreList.push(language);
this.storageService.store(
'extensionsAssistant/languagePackSuggestionIgnore',
JSON.stringify(languagePackSuggestionIgnoreList),
StorageScope.GLOBAL
);
logUserReaction('neverShowAgain');
this.notificationService.prompt(
Severity.Info,
promptMessage,
[...mainActions,
{
label: localize('neverAgain', "Don't Show Again"),
isSecondary: true,
run: () => {
languagePackSuggestionIgnoreList.push(language);
this.storageService.store(
'extensionsAssistant/languagePackSuggestionIgnore',
JSON.stringify(languagePackSuggestionIgnoreList),
StorageScope.GLOBAL
);
logUserReaction('neverShowAgain');
}
}],
() => {
logUserReaction('cancelled');
}
}],
() => {
logUserReaction('cancelled');
}
);
);
});
});
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册