mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 12:25:44 -05:00
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import i18next from 'i18next';
|
|
import type { AdminLanguages } from '@/api/admin/languages/queries';
|
|
import type { SelectOption } from '@/components/ui/Select';
|
|
import { getBootstrapSiteSettings } from '@/bootstrap';
|
|
|
|
export const PANEL_DEFAULT_LANGUAGE = '';
|
|
|
|
export const languageOptions = (
|
|
languages: AdminLanguages | undefined,
|
|
current?: string | null,
|
|
withPanelDefault = false
|
|
): SelectOption[] => {
|
|
const options = Object.entries(languages ?? {}).map(([value, label]) => ({ value, label }));
|
|
const panelDefault = getBootstrapSiteSettings()?.locale ?? 'en';
|
|
const defaults = withPanelDefault
|
|
? [
|
|
{
|
|
value: PANEL_DEFAULT_LANGUAGE,
|
|
label: i18next.t('Panel default ({{name}})', { name: languages?.[panelDefault] ?? panelDefault }),
|
|
},
|
|
]
|
|
: [];
|
|
|
|
if (current && !options.some((option) => option.value === current)) {
|
|
return [...defaults, { value: current, label: current }, ...options];
|
|
}
|
|
|
|
return [...defaults, ...options];
|
|
};
|