Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove locale and include download count #156823

Merged
merged 2 commits into from Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 28 additions & 10 deletions src/vs/platform/languagePacks/common/languagePacks.ts
Expand Up @@ -53,7 +53,7 @@ export abstract class LanguagePackBaseService extends Disposable implements ILan
const allFromMarketplace: ILanguagePackItem[] = languagePackExtensions.map(lp => {
const languageName = lp.properties.localizedLanguages?.[0];
const locale = this.getLocale(lp)!;
const baseQuickPick = this.createQuickPickItem({ locale, label: languageName });
const baseQuickPick = this.createQuickPickItem(locale, languageName, lp);
return {
...baseQuickPick,
extensionId: lp.identifier.id,
Expand All @@ -62,7 +62,7 @@ export abstract class LanguagePackBaseService extends Disposable implements ILan
});

allFromMarketplace.push({
...this.createQuickPickItem({ locale: 'en', label: 'English' }),
...this.createQuickPickItem('en', 'English'),
extensionId: 'default',
});

Expand All @@ -73,17 +73,35 @@ export abstract class LanguagePackBaseService extends Disposable implements ILan
return extension.tags.find(t => t.startsWith('lp-'))?.split('lp-')[1];
}

protected createQuickPickItem(languageItem: { locale: string; label?: string | undefined }): IQuickPickItem {
const label = languageItem.label ?? languageItem.locale;
let description: string | undefined = languageItem.locale !== languageItem.label ? languageItem.locale : undefined;
if (languageItem.locale.toLowerCase() === language.toLowerCase()) {
if (!description) {
description = '';
}
protected createQuickPickItem(locale: string, languageName?: string, languagePack?: IGalleryExtension): IQuickPickItem {
const label = languageName ?? locale;
let description: string | undefined;
if (label !== locale) {
description = `(${locale})`;
}

if (locale.toLowerCase() === language.toLowerCase()) {
description ??= '';
description += localize('currentDisplayLanguage', " (Current)");
}

if (languagePack?.installCount) {
description ??= '';

const count = languagePack.installCount;
let countLabel: string;
if (count > 1000000) {
countLabel = `${Math.floor(count / 100000) / 10}M`;
} else if (count > 1000) {
countLabel = `${Math.floor(count / 1000)}K`;
} else {
countLabel = String(count);
}
description += ` $(cloud-download) ${countLabel}`;
}

return {
id: languageItem.locale,
id: locale,
label,
description
};
Expand Down
5 changes: 3 additions & 2 deletions src/vs/platform/languagePacks/node/languagePacks.ts
Expand Up @@ -52,16 +52,17 @@ export class NativeLanguagePackService extends LanguagePackBaseService {
const languagePacks = await this.cache.getLanguagePacks();
const languages = Object.keys(languagePacks).map(locale => {
const languagePack = languagePacks[locale];
const baseQuickPick = this.createQuickPickItem({ locale, label: languagePack.label });
const baseQuickPick = this.createQuickPickItem(locale, languagePack.label);
return {
...baseQuickPick,
extensionId: languagePack.extensions[0].extensionIdentifier.id,
};
});
languages.push({
...this.createQuickPickItem({ locale: 'en', label: 'English' }),
...this.createQuickPickItem('en', 'English'),
extensionId: 'default',
});
languages.sort((a, b) => a.label.localeCompare(b.label));
return languages;
}

Expand Down