Fix i18n on default user

This commit is contained in:
Paulo Gustavo Veiga 2022-02-09 16:36:31 -08:00
parent 275f05a41e
commit c77268868d
8 changed files with 14 additions and 17 deletions

View File

@ -37,8 +37,7 @@ const queryClient = new QueryClient({
}); });
const App = (): ReactElement => { const App = (): ReactElement => {
const appi18n = new AppI18n(); const locale = AppI18n.getBrowserLocale();
const locale = appi18n.getBrowserLocale();
// global variables set server-side // global variables set server-side
const istTryMode = global.memoryPersistence; const istTryMode = global.memoryPersistence;

View File

@ -15,13 +15,13 @@ export class Locale {
} }
} }
export default class AppI18n { export default abstract class AppI18n {
public getUserLocale(): Locale { public static getUserLocale(): Locale {
const account = fetchAccount(); const account = fetchAccount();
return account ? account.locale : this.getBrowserLocale(); return account?.locale ? account.locale : this.getBrowserLocale();
} }
public getBrowserLocale(): Locale { public static getBrowserLocale(): Locale {
let localeCode = (navigator.languages && navigator.languages[0]) || navigator.language; let localeCode = (navigator.languages && navigator.languages[0]) || navigator.language;
// Just remove the variant ... // Just remove the variant ...

View File

@ -63,7 +63,7 @@ export type AccountInfo = {
firstname: string; firstname: string;
lastname: string; lastname: string;
email: string; email: string;
locale: Locale; locale?: Locale;
}; };
export type Permission = { export type Permission = {

View File

@ -184,7 +184,7 @@ export default class RestClient implements Client {
`${this.baseUrl}/c/restful/maps?title=${model.title}&description=${model.description ? model.description : '' `${this.baseUrl}/c/restful/maps?title=${model.title}&description=${model.description ? model.description : ''
}`, }`,
model.content, model.content,
{ headers: { 'Content-Type': model.contentType } } { headers: { 'Content-Type': 'application/xml' } }
) )
.then((response) => { .then((response) => {
const mapId = response.headers.resourceid; const mapId = response.headers.resourceid;
@ -214,7 +214,7 @@ export default class RestClient implements Client {
lastname: account.lastname ? account.lastname : '', lastname: account.lastname ? account.lastname : '',
firstname: account.firstname ? account.firstname : '', firstname: account.firstname ? account.firstname : '',
email: account.email, email: account.email,
locale: locale ? localeFromStr(locale) : Locales.EN, locale: locale ? localeFromStr(locale) : undefined,
}); });
}) })
.catch((error) => { .catch((error) => {

View File

@ -13,8 +13,7 @@ const EditorPage = ({ mapId, ...props }: EditorPropsType): React.ReactElement =>
const [activeDialog, setActiveDialog] = React.useState<ActionType | null>(null); const [activeDialog, setActiveDialog] = React.useState<ActionType | null>(null);
// Load user locale ... // Load user locale ...
const appi18n = new AppI18n(); const userLocale = AppI18n.getUserLocale();
const userLocale = appi18n.getUserLocale();
return <> return <>
<Editor {...props} onAction={setActiveDialog} locale={userLocale.code} /> <Editor {...props} onAction={setActiveDialog} locale={userLocale.code} />

View File

@ -105,7 +105,7 @@ const ImportDialog = ({ onClose }: CreateProps): React.ReactElement => {
description={intl.formatMessage({ description={intl.formatMessage({
id: 'import.description', id: 'import.description',
defaultMessage: defaultMessage:
'You can import FreeMind 1.0.1 and WiseMapping maps to your list of maps. Select the file you want to import.', 'You can import WiseMapping maps to your list of maps. Select the file you want to import.',
})} })}
submitButton={intl.formatMessage({ id: 'import.button', defaultMessage: 'Create' })} submitButton={intl.formatMessage({ id: 'import.button', defaultMessage: 'Create' })}
> >

View File

@ -66,8 +66,7 @@ const MapsPage = (): ReactElement => {
const [activeDialog, setActiveDialog] = React.useState<ActionType | undefined>(undefined); const [activeDialog, setActiveDialog] = React.useState<ActionType | undefined>(undefined);
// Reload based on user preference ... // Reload based on user preference ...
const appi18n = new AppI18n(); const userLocale = AppI18n.getUserLocale();
const userLocale = appi18n.getUserLocale();
const cache = createIntlCache(); const cache = createIntlCache();
const intl = createIntl({ const intl = createIntl({

View File

@ -5,7 +5,7 @@ import Client from '../../../classes/client';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { activeInstance, fetchAccount } from '../../../redux/clientSlice'; import { activeInstance, fetchAccount } from '../../../redux/clientSlice';
import { FormattedMessage, useIntl } from 'react-intl'; import { FormattedMessage, useIntl } from 'react-intl';
import { LocaleCode, Locales } from '../../../classes/app-i18n'; import AppI18n, { LocaleCode, Locales } from '../../../classes/app-i18n';
import Tooltip from '@mui/material/Tooltip'; import Tooltip from '@mui/material/Tooltip';
import Button from '@mui/material/Button'; import Button from '@mui/material/Button';
import Menu from '@mui/material/Menu'; import Menu from '@mui/material/Menu';
@ -49,7 +49,7 @@ const LanguageMenu = (): React.ReactElement => {
mutation.mutate(localeCode); mutation.mutate(localeCode);
}; };
const accountInfo = fetchAccount(); const userLocale = AppI18n.getUserLocale();
return ( return (
<span> <span>
<Tooltip <Tooltip
@ -68,7 +68,7 @@ const LanguageMenu = (): React.ReactElement => {
onClick={handleMenu} onClick={handleMenu}
startIcon={<TranslateTwoTone style={{ color: 'inherit' }} />} startIcon={<TranslateTwoTone style={{ color: 'inherit' }} />}
> >
{accountInfo?.locale?.label} {userLocale.label}
</Button> </Button>
</Tooltip> </Tooltip>
<Menu <Menu