2021-01-05 15:25:09 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2019-2021 Carl Kittelberger <icedream@icedream.pw>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-01-05 15:25:43 +00:00
|
|
|
// import { shouldPolyfill } from '@formatjs/intl-numberformat/should-polyfill';
|
2020-08-22 20:25:57 +00:00
|
|
|
import '@formatjs/intl-numberformat/polyfill';
|
|
|
|
import '@formatjs/intl-numberformat/locale-data/de';
|
|
|
|
import '@formatjs/intl-numberformat/locale-data/en';
|
|
|
|
import { UnboxPromise } from './types';
|
|
|
|
|
|
|
|
export const defaultLocale = 'en';
|
|
|
|
export const defaultLocaleDescription = 'English';
|
|
|
|
|
|
|
|
export const availableLocales: Array<string> = [
|
|
|
|
defaultLocale,
|
|
|
|
'de',
|
|
|
|
];
|
|
|
|
|
|
|
|
export const localeDescriptions: Record<string, string> = {
|
|
|
|
[defaultLocale]: defaultLocaleDescription,
|
|
|
|
de: 'German',
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function loadLocalePolyfill(
|
|
|
|
locale: string,
|
|
|
|
): Promise<void> {
|
|
|
|
// if (shouldPolyfill()) {
|
|
|
|
// // Load the polyfill 1st BEFORE loading data
|
|
|
|
// console.log('Loading intl-numberformat polyfill');
|
|
|
|
// await import('@formatjs/intl-numberformat/polyfill');
|
|
|
|
// } else {
|
|
|
|
// console.log('Skipping intl-numberformat polyfill');
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (Object.keys(Intl.NumberFormat).includes('polyfilled')) {
|
|
|
|
// console.log('Intl.NumberFormat is polyfilled, let\'s load intl-numberformat locale data');
|
|
|
|
// switch (locale) {
|
|
|
|
// case 'de':
|
|
|
|
// await import('@formatjs/intl-numberformat/locale-data/de');
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// await import('@formatjs/intl-numberformat/locale-data/en');
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// console.log('intl-numberformat locale data loaded');
|
|
|
|
// } else {
|
|
|
|
// console.log('Intl.NumberFormat is native');
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function loadLocaleData(
|
|
|
|
locale: string,
|
|
|
|
) {
|
|
|
|
let localeData;
|
|
|
|
|
|
|
|
switch (locale) {
|
|
|
|
case 'de':
|
|
|
|
localeData = await import('../compiled-lang/de.json');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
localeData = await import('../compiled-lang/en.json');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return localeData.default;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isPolyfilled(): boolean {
|
|
|
|
return !Object.keys(Intl.NumberFormat).includes('polyfilled');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isPolyfillPhaseDone(): boolean {
|
|
|
|
// return shouldPolyfill() && isPolyfilled();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type LocaleData = UnboxPromise<ReturnType<typeof loadLocaleData>>;
|