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
packages/webapp/src
app.tsx
classes
app-i18n
client
index.ts
rest-client
components
editor-page
maps-page
action-dispatcher/import-dialog
index.tsx
language-menu

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

@ -15,13 +15,13 @@ export class Locale {
}
}
export default class AppI18n {
public getUserLocale(): Locale {
export default abstract class AppI18n {
public static getUserLocale(): Locale {
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;
// Just remove the variant ...

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

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

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

@ -105,7 +105,7 @@ const ImportDialog = ({ onClose }: CreateProps): React.ReactElement => {
description={intl.formatMessage({
id: 'import.description',
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' })}
>

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

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