From c77268868d388e9655dd34476b0ceef2a0e11e71 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 9 Feb 2022 16:36:31 -0800 Subject: [PATCH] Fix i18n on default user --- packages/webapp/src/app.tsx | 3 +-- packages/webapp/src/classes/app-i18n/index.ts | 8 ++++---- packages/webapp/src/classes/client/index.ts | 2 +- packages/webapp/src/classes/client/rest-client/index.ts | 4 ++-- packages/webapp/src/components/editor-page/index.tsx | 3 +-- .../maps-page/action-dispatcher/import-dialog/index.tsx | 2 +- packages/webapp/src/components/maps-page/index.tsx | 3 +-- .../src/components/maps-page/language-menu/index.tsx | 6 +++--- 8 files changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/webapp/src/app.tsx b/packages/webapp/src/app.tsx index f0f6c91b..34f84ab7 100644 --- a/packages/webapp/src/app.tsx +++ b/packages/webapp/src/app.tsx @@ -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; diff --git a/packages/webapp/src/classes/app-i18n/index.ts b/packages/webapp/src/classes/app-i18n/index.ts index e4663c05..b361721a 100644 --- a/packages/webapp/src/classes/app-i18n/index.ts +++ b/packages/webapp/src/classes/app-i18n/index.ts @@ -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 ... diff --git a/packages/webapp/src/classes/client/index.ts b/packages/webapp/src/classes/client/index.ts index 6a0a3971..711f9e49 100644 --- a/packages/webapp/src/classes/client/index.ts +++ b/packages/webapp/src/classes/client/index.ts @@ -63,7 +63,7 @@ export type AccountInfo = { firstname: string; lastname: string; email: string; - locale: Locale; + locale?: Locale; }; export type Permission = { diff --git a/packages/webapp/src/classes/client/rest-client/index.ts b/packages/webapp/src/classes/client/rest-client/index.ts index 37ab6c85..0fefd4c8 100644 --- a/packages/webapp/src/classes/client/rest-client/index.ts +++ b/packages/webapp/src/classes/client/rest-client/index.ts @@ -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) => { diff --git a/packages/webapp/src/components/editor-page/index.tsx b/packages/webapp/src/components/editor-page/index.tsx index 56a7082a..055ccb49 100644 --- a/packages/webapp/src/components/editor-page/index.tsx +++ b/packages/webapp/src/components/editor-page/index.tsx @@ -13,8 +13,7 @@ const EditorPage = ({ mapId, ...props }: EditorPropsType): React.ReactElement => const [activeDialog, setActiveDialog] = React.useState(null); // Load user locale ... - const appi18n = new AppI18n(); - const userLocale = appi18n.getUserLocale(); + const userLocale = AppI18n.getUserLocale(); return <> diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/import-dialog/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/import-dialog/index.tsx index 8e381495..61fd9948 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/import-dialog/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/import-dialog/index.tsx @@ -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' })} > diff --git a/packages/webapp/src/components/maps-page/index.tsx b/packages/webapp/src/components/maps-page/index.tsx index 8fc8fa73..949ae30f 100644 --- a/packages/webapp/src/components/maps-page/index.tsx +++ b/packages/webapp/src/components/maps-page/index.tsx @@ -66,8 +66,7 @@ const MapsPage = (): ReactElement => { const [activeDialog, setActiveDialog] = React.useState(undefined); // Reload based on user preference ... - const appi18n = new AppI18n(); - const userLocale = appi18n.getUserLocale(); + const userLocale = AppI18n.getUserLocale(); const cache = createIntlCache(); const intl = createIntl({ diff --git a/packages/webapp/src/components/maps-page/language-menu/index.tsx b/packages/webapp/src/components/maps-page/language-menu/index.tsx index 0a47c94b..b89ea31b 100644 --- a/packages/webapp/src/components/maps-page/language-menu/index.tsx +++ b/packages/webapp/src/components/maps-page/language-menu/index.tsx @@ -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 ( { onClick={handleMenu} startIcon={} > - {accountInfo?.locale?.label} + {userLocale.label}