From ae6fdfe726c6ff4a9458b3dbdc1b8a05f9bbc74f Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Mon, 2 Jun 2025 15:45:16 +0000 Subject: [PATCH] chore: add language name to config in manifest as well --- src/utils/manifest.test.ts | 12 ++++++------ src/utils/manifest.ts | 11 +++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/utils/manifest.test.ts b/src/utils/manifest.test.ts index afe2b96..c0ab4f3 100644 --- a/src/utils/manifest.test.ts +++ b/src/utils/manifest.test.ts @@ -21,9 +21,9 @@ describe('buildManifest', () => { const manifest = buildManifest(handlers, {}); expect(manifest.config).toStrictEqual([ - { key: 'de', type: 'checkbox', title: '🇩🇪 (KinoKiste, MeineCloud)' }, - { key: 'es', type: 'checkbox', title: '🇪🇸 (VerHdLink)' }, - { key: 'mx', type: 'checkbox', title: '🇲🇽 (VerHdLink)' }, + { key: 'de', type: 'checkbox', title: 'German 🇩🇪 (KinoKiste, MeineCloud)' }, + { key: 'es', type: 'checkbox', title: 'Castilian Spanish 🇪🇸 (VerHdLink)' }, + { key: 'mx', type: 'checkbox', title: 'Latin American Spanish 🇲🇽 (VerHdLink)' }, { key: 'excludeExternalUrls', type: 'checkbox', title: 'Exclude external URLs from results' }, ]); }); @@ -38,9 +38,9 @@ describe('buildManifest', () => { const manifest = buildManifest(handlers, { de: 'on' }); expect(manifest.config).toStrictEqual([ - { key: 'de', type: 'checkbox', title: '🇩🇪 (KinoKiste, MeineCloud)', default: 'checked' }, - { key: 'es', type: 'checkbox', title: '🇪🇸 (VerHdLink)' }, - { key: 'mx', type: 'checkbox', title: '🇲🇽 (VerHdLink)' }, + { key: 'de', type: 'checkbox', title: 'German 🇩🇪 (KinoKiste, MeineCloud)', default: 'checked' }, + { key: 'es', type: 'checkbox', title: 'Castilian Spanish 🇪🇸 (VerHdLink)' }, + { key: 'mx', type: 'checkbox', title: 'Latin American Spanish 🇲🇽 (VerHdLink)' }, { key: 'excludeExternalUrls', type: 'checkbox', title: 'Exclude external URLs from results' }, ]); }); diff --git a/src/utils/manifest.ts b/src/utils/manifest.ts index 57fac2c..cd18293 100644 --- a/src/utils/manifest.ts +++ b/src/utils/manifest.ts @@ -1,6 +1,9 @@ import { flag } from 'country-emoji'; import { Handler } from '../handler'; -import { Config, ManifestWithConfig } from '../types'; +import { Config, CountryCode, ManifestWithConfig } from '../types'; +import { languageFromCountryCode } from './languageFromCountryCode'; + +const typedEntries = (obj: T): [keyof T, T[keyof T]][] => (Object.entries(obj) as [keyof T, T[keyof T]][]); export const buildManifest = (handlers: Handler[], config: Config): ManifestWithConfig => { const manifest: ManifestWithConfig = { @@ -30,19 +33,19 @@ export const buildManifest = (handlers: Handler[], config: Config): ManifestWith }, }; - const countryCodeHandlers: Record = {}; + const countryCodeHandlers: Partial> = {}; handlers.forEach((handler) => { handler.countryCodes.forEach(countryCode => countryCodeHandlers[countryCode] = [...(countryCodeHandlers[countryCode] ?? []), handler]); }); - const sortedLanguageHandlers = Object.entries(countryCodeHandlers) + const sortedLanguageHandlers = typedEntries(countryCodeHandlers) .sort(([countryCodeA], [countryCodeB]) => countryCodeA.localeCompare(countryCodeB)); for (const [countryCode, handlers] of sortedLanguageHandlers) { manifest.config.push({ key: countryCode, type: 'checkbox', - title: `${flag(countryCode)} (${handlers.map(handler => handler.label).join(', ')})`, + title: `${languageFromCountryCode(countryCode)} ${flag(countryCode)} (${(handlers as Handler[]).map(handler => handler.label).join(', ')})`, ...(countryCode in config && { default: 'checked' }), }); }