chinwagsocial/app/javascript/mastodon/features/emoji/locale.ts
2025-07-09 09:55:41 +00:00

23 lines
675 B
TypeScript

import type { Locale } from 'emojibase';
import { SUPPORTED_LOCALES } from 'emojibase';
export type LocaleOrCustom = Locale | 'custom';
export function toSupportedLocale(localeBase: string): Locale {
const locale = localeBase.toLowerCase();
if (isSupportedLocale(locale)) {
return locale;
}
return 'en'; // Default to English if unsupported
}
export function toSupportedLocaleOrCustom(locale: string): LocaleOrCustom {
if (locale.toLowerCase() === 'custom') {
return 'custom';
}
return toSupportedLocale(locale);
}
function isSupportedLocale(locale: string): locale is Locale {
return SUPPORTED_LOCALES.includes(locale.toLowerCase() as Locale);
}