Fix default i18n load

This commit is contained in:
Paulo Gustavo Veiga 2022-02-09 16:48:33 -08:00
parent 67fb3bbc35
commit be727e3c4b
3 changed files with 17 additions and 17 deletions

View File

@ -37,7 +37,7 @@ declare global {
} }
export type EditorPropsType = { export type EditorPropsType = {
initCallback?: () => void; initCallback?: (locale: string) => void;
mapId?: number; mapId?: number;
isTryMode: boolean; isTryMode: boolean;
readOnlyMode: boolean; readOnlyMode: boolean;
@ -60,7 +60,7 @@ const loadLocaleData = (locale: string) => {
} }
} }
const initMindplot = () => { const initMindplot = (locale: string) => {
// Change page title ... // Change page title ...
document.title = `${global.mapTitle} | WiseMapping `; document.title = `${global.mapTitle} | WiseMapping `;
@ -95,7 +95,7 @@ const initMindplot = () => {
(global.userOptions?.zoom != undefined (global.userOptions?.zoom != undefined
? Number.parseFloat(global.userOptions.zoom as string) ? Number.parseFloat(global.userOptions.zoom as string)
: 0.8), : 0.8),
locale: global.locale, locale: locale,
}); });
// Build designer ... // Build designer ...
@ -119,11 +119,11 @@ const Editor = ({
onAction, onAction,
}: EditorPropsType): React.ReactElement => { }: EditorPropsType): React.ReactElement => {
React.useEffect(() => { React.useEffect(() => {
initCallback(); initCallback(locale);
}, []); }, []);
return ( return (
<IntlProvider locale={locale} defaultLocale="en" messages={loadLocaleData(locale)}> <IntlProvider locale={locale} messages={loadLocaleData(locale)}>
<Toolbar <Toolbar
isTryMode={isTryMode} isTryMode={isTryMode}
onAction={onAction} onAction={onAction}

View File

@ -14,6 +14,7 @@ const EditorPage = ({ mapId, ...props }: EditorPropsType): React.ReactElement =>
// Load user locale ... // Load user locale ...
const userLocale = AppI18n.getUserLocale(); const userLocale = AppI18n.getUserLocale();
console.log("Locale:" + userLocale.code);
return <> return <>
<Editor {...props} onAction={setActiveDialog} locale={userLocale.code} /> <Editor {...props} onAction={setActiveDialog} locale={userLocale.code} />

View File

@ -2,7 +2,7 @@ import React, { useEffect, CSSProperties } from 'react';
import { useStyles } from './styled'; import { useStyles } from './styled';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { activeInstance, fetchAccount } from '../../../redux/clientSlice'; import { activeInstance } from '../../../redux/clientSlice';
import { useMutation, useQuery, useQueryClient } from 'react-query'; import { useMutation, useQuery, useQueryClient } from 'react-query';
import Client, { ErrorInfo, Label, MapInfo } from '../../../classes/client'; import Client, { ErrorInfo, Label, MapInfo } from '../../../classes/client';
import ActionChooser, { ActionType } from '../action-chooser'; import ActionChooser, { ActionType } from '../action-chooser';
@ -37,6 +37,7 @@ import { AddLabelButton } from './add-label-button';
import relativeTime from 'dayjs/plugin/relativeTime'; import relativeTime from 'dayjs/plugin/relativeTime';
import { LabelsCell } from './labels-cell'; import { LabelsCell } from './labels-cell';
import LocalizedFormat from 'dayjs/plugin/localizedFormat'; import LocalizedFormat from 'dayjs/plugin/localizedFormat';
import AppI18n from '../../../classes/app-i18n';
dayjs.extend(LocalizedFormat) dayjs.extend(LocalizedFormat)
dayjs.extend(relativeTime); dayjs.extend(relativeTime);
@ -251,10 +252,8 @@ export const MapsList = (props: MapsListProps): React.ReactElement => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
// Configure locale ... // Configure locale ...
const account = fetchAccount(); const userLocale = AppI18n.getUserLocale();
if (account) { dayjs.locale(userLocale.code);
dayjs.locale(account.locale.code);
}
useEffect(() => { useEffect(() => {
setSelected([]); setSelected([]);