* feat: add plugin system * fix db docker build * fix hammerhead readme, add strava subscription news to docs * fixes and sdk improvements * fix: reduce Meilisearch load, debounce federation sync (#1012) * optimize meili trail index * several fixes --------- Co-authored-by: Flomp <Flomp@users.noreply.github.com> * Bump svelte from 5.55.5 to 5.56.0 in /docs (#1032) Bumps [svelte](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte) from 5.55.5 to 5.56.0. - [Release notes](https://github.com/sveltejs/svelte/releases) - [Changelog](https://github.com/sveltejs/svelte/blob/main/packages/svelte/CHANGELOG.md) - [Commits](https://github.com/sveltejs/svelte/commits/svelte@5.56.0/packages/svelte) --- updated-dependencies: - dependency-name: svelte dependency-version: 5.56.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Flomp <Flomp@users.noreply.github.com> * Release v0.19.2 (#1035) * chore: release v0.19.2 * add changelog --------- Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com> Co-authored-by: Christian Beutel <> * speed up plugin sync and several small fixes * concepts for security improvements and process stability * improve concept * security concept implemented * remove insecure TLS * worker concept implemented * fixes and cleanup * fixes * docu * mermaid, namings * WASM plugin host improvements, plugin logging * fix db migration * Improve plugin config and category mapping UI * fixes * further fixes * remove manual test sync * fix db migration and strava mapping * type added, UI improvements * fix plugin card toggle clickable area * optimize synch status card layout * plugin type 'trails' instead of 'integration' * session auth validation in UI * fix komoot date and waypoints * improve category mapping * fix send to hammerhead: trail name * plugin setup error handling improved * fix review findings * re-mapping added * rename remote_category --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Flomp <Flomp@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com>
87 lines
2.8 KiB
TypeScript
87 lines
2.8 KiB
TypeScript
import type { ConfigField, ConfigFieldOption, LocalizedTextMap, PluginProvider } from "$lib/models/plugin_provider";
|
|
|
|
export function localizedText(
|
|
texts: LocalizedTextMap | undefined,
|
|
currentLocale: string | null | undefined,
|
|
fallback = "",
|
|
): string {
|
|
if (!texts) {
|
|
return fallback;
|
|
}
|
|
|
|
const locale = normalizeLocale(currentLocale);
|
|
const language = locale.split("-")[0];
|
|
const candidates = [locale, language, "en"];
|
|
for (const candidate of candidates) {
|
|
const value = texts[candidate]?.trim();
|
|
if (value) {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
const trimmedFallback = fallback.trim();
|
|
if (trimmedFallback) {
|
|
return trimmedFallback;
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
export function pluginTitle(plugin: PluginProvider, currentLocale: string | null | undefined): string {
|
|
return localizedText(plugin.displayNames, currentLocale, plugin.displayName || plugin.name);
|
|
}
|
|
|
|
export function pluginDescription(plugin: PluginProvider, currentLocale: string | null | undefined): string {
|
|
return localizedText(plugin.descriptions, currentLocale, plugin.description ?? "");
|
|
}
|
|
|
|
export function configFieldLabel(
|
|
field: ConfigField,
|
|
currentLocale: string | null | undefined,
|
|
fallback: string,
|
|
): string {
|
|
return localizedText(field.labels, currentLocale, field.label || fallback);
|
|
}
|
|
|
|
export function configFieldDescription(
|
|
field: ConfigField,
|
|
currentLocale: string | null | undefined,
|
|
): string | undefined {
|
|
return localizedText(field.descriptions, currentLocale, field.description ?? "") || undefined;
|
|
}
|
|
|
|
export function configFieldOptionLabel(
|
|
option: ConfigFieldOption,
|
|
currentLocale: string | null | undefined,
|
|
fallback: string,
|
|
): string {
|
|
return localizedText(option.labels, currentLocale, option.label || fallback);
|
|
}
|
|
|
|
export function providerCategoryLabel(
|
|
plugin: PluginProvider,
|
|
providerCategory: string,
|
|
currentLocale: string | null | undefined,
|
|
): string {
|
|
const providerCategories = plugin.metadata?.providerCategories;
|
|
if (!providerCategories || typeof providerCategories !== "object" || Array.isArray(providerCategories)) {
|
|
return providerCategory;
|
|
}
|
|
|
|
const category = (providerCategories as Record<string, unknown>)[providerCategory];
|
|
if (!category || typeof category !== "object" || Array.isArray(category)) {
|
|
return providerCategory;
|
|
}
|
|
|
|
const labels = (category as Record<string, unknown>).labels;
|
|
if (!labels || typeof labels !== "object" || Array.isArray(labels)) {
|
|
return providerCategory;
|
|
}
|
|
|
|
return localizedText(labels as LocalizedTextMap, currentLocale, providerCategory);
|
|
}
|
|
|
|
function normalizeLocale(value: string | null | undefined): string {
|
|
return (value || "en").trim().toLowerCase().replace("_", "-");
|
|
}
|