Skip to content

Commit

Permalink
Remove locale and include download count (#156823)
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerLeonhardt authored Aug 1, 2022
1 parent f0434c0 commit 6f8b946
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
38 changes: 28 additions & 10 deletions src/vs/platform/languagePacks/common/languagePacks.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 6f8b946

Please sign in to comment.