Merge branch 'master' into cleanup

This commit is contained in:
bree
2021-07-04 21:06:30 -04:00
50 changed files with 686 additions and 278 deletions

View File

@@ -43,7 +43,6 @@ export enum Language {
PIRATE = "pr",
BOTTOM = "bottom",
PIGLATIN = "piglatin",
HARDCORE = "hardcore",
}
export interface LanguageEntry {
@@ -107,13 +106,6 @@ export const Languages: { [key in Language]: LanguageEntry } = {
dayjs: "en-gb",
alt: true
},
hardcore: {
display: "Hardcore Mode",
emoji: "🔥",
i18n: "hardcore",
dayjs: "en-gb",
alt: true
},
};
interface Props {
@@ -126,8 +118,10 @@ function Locale({ children, locale }: Props) {
const [defns, setDefinition] = useState<Record<string, unknown>>(definition);
const lang = Languages[locale];
// TOOD: clean this up and use the built in Intl API
function transformLanguage(obj: { [key: string]: any }) {
// TODO: clean this up and use the built in Intl API
function transformLanguage(source: { [key: string]: any }) {
const obj = defaultsDeep(source, definition);
const dayjs = obj.dayjs;
const defaults = dayjs.defaults;
@@ -151,23 +145,16 @@ function Locale({ children, locale }: Props) {
useEffect(() => {
if (locale === "en") {
transformLanguage(definition);
setDefinition(definition);
const defn = transformLanguage(definition);
setDefinition(defn);
dayjs.locale("en");
dayjs.updateLocale('en', { calendar: definition.dayjs });
return;
}
if (lang.i18n === "hardcore") {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setDefinition({});
dayjs.updateLocale('en', { calendar: defn.dayjs });
return;
}
import(`../../external/lang/${lang.i18n}.json`).then(
async (lang_file) => {
const defn = lang_file.default;
transformLanguage(defn);
const defn = transformLanguage(lang_file.default);
const target = lang.dayjs ?? lang.i18n;
const dayjs_locale = await import(`../../node_modules/dayjs/esm/locale/${target}.js`);
@@ -176,7 +163,7 @@ function Locale({ children, locale }: Props) {
}
dayjs.locale(dayjs_locale.default);
setDefinition(defaultsDeep(defn, definition));
setDefinition(defn);
}
);
}, [locale, lang]);