{"version":3,"file":"pluginLocales.mjs","names":[],"sources":["../../../src/web/lib/pluginLocales.ts"],"sourcesContent":["import { canonicalLocale, type LocaleContribution, type WebPluginDefinition } from '@agimon-ai/po-core/web';\n\nimport type { InstallDiagnostic } from './pluginRegistry';\n\n/** A language a host plugin contributes, validated, with its canonical tag. */\nexport interface InstalledPluginLocale {\n  pluginId: string;\n  locale: LocaleContribution;\n}\n\nfunction isMessages(value: unknown): value is Record<string, string> {\n  return (\n    typeof value === 'object' &&\n    value !== null &&\n    !Array.isArray(value) &&\n    Object.values(value).every((message) => typeof message === 'string')\n  );\n}\n\n/**\n * The languages the host plugins contribute. A pack that fails validation is reported, never thrown:\n * one bad catalog must not keep the cockpit from starting. Two packs for one tag both stay; their\n * messages merge, later keys winning, so a pack can extend another.\n */\nexport function collectPluginLocales(plugins: readonly WebPluginDefinition[]): {\n  locales: InstalledPluginLocale[];\n  diagnostics: InstallDiagnostic[];\n} {\n  const locales: InstalledPluginLocale[] = [];\n  const diagnostics: InstallDiagnostic[] = [];\n  for (const plugin of plugins) {\n    for (const contribution of plugin.host?.locales ?? []) {\n      const name = canonicalLocale(contribution.name);\n      if (\n        name === undefined ||\n        typeof contribution.label !== 'string' ||\n        typeof contribution.nativeLabel !== 'string' ||\n        !isMessages(contribution.messages)\n      ) {\n        diagnostics.push({\n          pluginId: plugin.id,\n          kind: 'rejected-locale',\n          message: `Web plugin '${plugin.id}' locale '${String(contribution.name)}' is not a valid language pack; it is left out.`,\n        });\n        continue;\n      }\n      locales.push({ pluginId: plugin.id, locale: { ...contribution, name } });\n    }\n  }\n  return { locales, diagnostics };\n}\n"],"mappings":";;AAUA,SAAS,WAAW,OAAiD;CACnE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,QAAQ,KAAK,KACpB,OAAO,OAAO,KAAK,CAAC,CAAC,OAAO,YAAY,OAAO,YAAY,QAAQ;AAEvE;;;;;;AAOA,SAAgB,qBAAqB,SAGnC;CACA,MAAM,UAAmC,CAAC;CAC1C,MAAM,cAAmC,CAAC;CAC1C,KAAK,MAAM,UAAU,SACnB,KAAK,MAAM,gBAAgB,OAAO,MAAM,WAAW,CAAC,GAAG;EACrD,MAAM,OAAO,gBAAgB,aAAa,IAAI;EAC9C,IACE,SAAS,KAAA,KACT,OAAO,aAAa,UAAU,YAC9B,OAAO,aAAa,gBAAgB,YACpC,CAAC,WAAW,aAAa,QAAQ,GACjC;GACA,YAAY,KAAK;IACf,UAAU,OAAO;IACjB,MAAM;IACN,SAAS,eAAe,OAAO,GAAG,YAAY,OAAO,aAAa,IAAI,EAAE;GAC1E,CAAC;GACD;EACF;EACA,QAAQ,KAAK;GAAE,UAAU,OAAO;GAAI,QAAQ;IAAE,GAAG;IAAc;GAAK;EAAE,CAAC;CACzE;CAEF,OAAO;EAAE;EAAS;CAAY;AAChC"}