mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-09 16:53:36 -05:00
Fix: Handle defaults before transforming languages.
Remove Hardcore Mode.
This commit is contained in:
parent
49e49f3952
commit
098e28113b
1 changed files with 9 additions and 16 deletions
|
@ -43,7 +43,6 @@ export enum Language {
|
||||||
PIRATE = "pr",
|
PIRATE = "pr",
|
||||||
BOTTOM = "bottom",
|
BOTTOM = "bottom",
|
||||||
PIGLATIN = "piglatin",
|
PIGLATIN = "piglatin",
|
||||||
HARDCORE = "hardcore",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LanguageEntry {
|
export interface LanguageEntry {
|
||||||
|
@ -107,13 +106,6 @@ export const Languages: { [key in Language]: LanguageEntry } = {
|
||||||
dayjs: "en-gb",
|
dayjs: "en-gb",
|
||||||
alt: true
|
alt: true
|
||||||
},
|
},
|
||||||
hardcore: {
|
|
||||||
display: "Hardcore Mode",
|
|
||||||
emoji: "🔥",
|
|
||||||
i18n: "hardcore",
|
|
||||||
dayjs: "en-gb",
|
|
||||||
alt: true
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
@ -125,9 +117,11 @@ function Locale({ children, locale }: Props) {
|
||||||
const [defns, setDefinition] = useState(definition);
|
const [defns, setDefinition] = useState(definition);
|
||||||
const lang = Languages[locale];
|
const lang = Languages[locale];
|
||||||
|
|
||||||
function transformLanguage(obj: { [key: string]: any }) {
|
function transformLanguage(source: { [key: string]: any }) {
|
||||||
|
const obj = defaultsDeep(source, definition);
|
||||||
|
|
||||||
const dayjs = obj.dayjs;
|
const dayjs = obj.dayjs;
|
||||||
const defaults = dayjs?.defaults;
|
const defaults = dayjs.defaults;
|
||||||
|
|
||||||
const twelvehour = defaults?.twelvehour === 'yes' || true;
|
const twelvehour = defaults?.twelvehour === 'yes' || true;
|
||||||
const separator: '/' | '-' | '.' = defaults?.date_separator ?? '/';
|
const separator: '/' | '-' | '.' = defaults?.date_separator ?? '/';
|
||||||
|
@ -149,10 +143,10 @@ function Locale({ children, locale }: Props) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (locale === "en") {
|
if (locale === "en") {
|
||||||
transformLanguage(definition);
|
const defn = transformLanguage(definition);
|
||||||
setDefinition(definition);
|
setDefinition(defn);
|
||||||
dayjs.locale("en");
|
dayjs.locale("en");
|
||||||
dayjs.updateLocale('en', { calendar: definition.dayjs });
|
dayjs.updateLocale('en', { calendar: defn.dayjs });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +158,7 @@ function Locale({ children, locale }: Props) {
|
||||||
|
|
||||||
import(`../../external/lang/${lang.i18n}.json`).then(
|
import(`../../external/lang/${lang.i18n}.json`).then(
|
||||||
async (lang_file) => {
|
async (lang_file) => {
|
||||||
const defn = lang_file.default;
|
const defn = transformLanguage(lang_file.default);
|
||||||
transformLanguage(defn);
|
|
||||||
const target = lang.dayjs ?? lang.i18n;
|
const target = lang.dayjs ?? lang.i18n;
|
||||||
const dayjs_locale = await import(`../../node_modules/dayjs/esm/locale/${target}.js`);
|
const dayjs_locale = await import(`../../node_modules/dayjs/esm/locale/${target}.js`);
|
||||||
|
|
||||||
|
@ -174,7 +167,7 @@ function Locale({ children, locale }: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dayjs.locale(dayjs_locale.default);
|
dayjs.locale(dayjs_locale.default);
|
||||||
setDefinition(defaultsDeep(defn, definition));
|
setDefinition(defn);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, [locale, lang]);
|
}, [locale, lang]);
|
||||||
|
|
Loading…
Reference in a new issue