Files

30 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2026-11-23 14:16:00 +00:00
import i18next from 'i18next';
2026-10-05 18:10:18 -04:00
import type { AdminLanguages } from '@/api/admin/languages/queries';
import type { SelectOption } from '@/components/ui/Select';
2026-10-27 11:42:22 +00:00
import { getBootstrapSiteSettings } from '@/bootstrap';
2026-10-05 18:10:18 -04:00
2026-10-27 11:42:22 +00:00
export const PANEL_DEFAULT_LANGUAGE = '';
export const languageOptions = (
languages: AdminLanguages | undefined,
current?: string | null,
withPanelDefault = false
): SelectOption[] => {
2026-10-05 18:10:18 -04:00
const options = Object.entries(languages ?? {}).map(([value, label]) => ({ value, label }));
2026-10-27 11:42:22 +00:00
const panelDefault = getBootstrapSiteSettings()?.locale ?? 'en';
const defaults = withPanelDefault
2026-11-23 14:16:00 +00:00
? [
{
value: PANEL_DEFAULT_LANGUAGE,
label: i18next.t('Panel default ({{name}})', { name: languages?.[panelDefault] ?? panelDefault }),
},
]
2026-10-27 11:42:22 +00:00
: [];
2026-10-05 18:10:18 -04:00
if (current && !options.some((option) => option.value === current)) {
2026-10-27 11:42:22 +00:00
return [...defaults, { value: current, label: current }, ...options];
2026-10-05 18:10:18 -04:00
}
2026-10-27 11:42:22 +00:00
return [...defaults, ...options];
2026-10-05 18:10:18 -04:00
};