This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2023-06-02 06:00:27 -07:00
|
|
|
export interface LocaleData {
|
|
|
|
locale: string;
|
|
|
|
messages: Record<string, string>;
|
|
|
|
}
|
|
|
|
|
2023-07-13 02:49:16 -07:00
|
|
|
let loadedLocale: LocaleData | undefined;
|
2023-06-02 06:00:27 -07:00
|
|
|
|
|
|
|
export function setLocale(locale: LocaleData) {
|
|
|
|
loadedLocale = locale;
|
|
|
|
}
|
|
|
|
|
2023-07-13 02:49:16 -07:00
|
|
|
export function getLocale(): LocaleData {
|
|
|
|
if (!loadedLocale) {
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
throw new Error('getLocale() called before any locale has been set');
|
|
|
|
} else {
|
|
|
|
return { locale: 'unknown', messages: {} };
|
|
|
|
}
|
2023-06-02 06:00:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return loadedLocale;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isLocaleLoaded() {
|
|
|
|
return !!loadedLocale;
|
|
|
|
}
|