/** * Copyright (C) 2019-2021 Carl Kittelberger * * 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 . */ import { shouldPolyfill } from '@formatjs/intl-numberformat/should-polyfill'; 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 = [ defaultLocale, 'de', ]; export const localeDescriptions: Record = { [defaultLocale]: defaultLocaleDescription, de: 'German', }; export async function loadLocalePolyfill( locale: string, ): Promise { // 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>;