mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-26 04:16:44 +00:00
24 lines
674 B
TypeScript
24 lines
674 B
TypeScript
import type { Locale } from 'emojibase';
|
|
import { SUPPORTED_LOCALES } from 'emojibase';
|
|
|
|
import type { LocaleOrCustom } from './types';
|
|
|
|
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);
|
|
}
|