2024-01-15 05:16:05 -06:00
|
|
|
import { isDevelopment } from 'flavours/glitch/utils/environment';
|
|
|
|
|
2023-06-02 08:00:27 -05:00
|
|
|
export interface LocaleData {
|
|
|
|
locale: string;
|
|
|
|
messages: Record<string, string>;
|
|
|
|
}
|
|
|
|
|
2023-07-13 04:49:16 -05:00
|
|
|
let loadedLocale: LocaleData | undefined;
|
2023-06-02 08:00:27 -05:00
|
|
|
|
|
|
|
export function setLocale(locale: LocaleData) {
|
|
|
|
loadedLocale = locale;
|
|
|
|
}
|
|
|
|
|
2023-07-13 04:49:16 -05:00
|
|
|
export function getLocale(): LocaleData {
|
|
|
|
if (!loadedLocale) {
|
2024-01-15 05:16:05 -06:00
|
|
|
if (isDevelopment()) {
|
2023-07-13 04:49:16 -05:00
|
|
|
throw new Error('getLocale() called before any locale has been set');
|
|
|
|
} else {
|
|
|
|
return { locale: 'unknown', messages: {} };
|
|
|
|
}
|
2023-06-02 08:00:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return loadedLocale;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isLocaleLoaded() {
|
|
|
|
return !!loadedLocale;
|
|
|
|
}
|