From d57cec6f80e058337e4f190be486a2b1b968f73c Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 12 Feb 2021 18:00:54 -0800 Subject: [PATCH] WIP: locale --- packages/webapp/lang/en.json | 11 +++- packages/webapp/src/client/index.ts | 5 +- .../webapp/src/client/mock-client/index.ts | 15 ++++-- .../webapp/src/client/rest-client/index.ts | 13 +++-- .../action-dispatcher/export-dialog/index.tsx | 2 +- .../maps-page/language-menu/index.tsx | 54 ++++++++++++++----- 6 files changed, 76 insertions(+), 24 deletions(-) diff --git a/packages/webapp/lang/en.json b/packages/webapp/lang/en.json index f51db7c8..8253f7b6 100644 --- a/packages/webapp/lang/en.json +++ b/packages/webapp/lang/en.json @@ -89,6 +89,9 @@ "export.document": { "defaultMessage": "Mindmap Tools: Export your mindmap in thirdparty mindmap tool formats" }, + "export.document-label": { + "defaultMessage": "Document: Export your mindmap in a self-contained document ready to share" + }, "export.image": { "defaultMessage": "Image: Get a graphic representation of your map including all colors and shapes." }, @@ -96,7 +99,7 @@ "defaultMessage": "Export" }, "export.warning": { - "defaultMessage": "Exporting to Image (SVG,PNG,JPEG )is available only in the editor toolbar." + "defaultMessage": "Exporting to Image (SVG,PNG,JPEG,PDF) is only available in the editor toolbar." }, "footer.aboutus": { "defaultMessage": "About Us" @@ -197,6 +200,12 @@ "info.title": { "defaultMessage": "Info" }, + "language.change": { + "defaultMessage": "Change Language" + }, + "languange.help": { + "defaultMessage": "Help to Translate" + }, "login.desc": { "defaultMessage": "Log into your account" }, diff --git a/packages/webapp/src/client/index.ts b/packages/webapp/src/client/index.ts index 6bc79d89..5364065c 100644 --- a/packages/webapp/src/client/index.ts +++ b/packages/webapp/src/client/index.ts @@ -59,9 +59,11 @@ export type AccountInfo = { firstName: string; lastName: string; email: string; - language: string; + language: LocaleCode; } +export type LocaleCode = 'en' | 'es' | 'fr' | 'de'; + interface Client { importMap(model: ImportMapInfo): Promise createMap(map: BasicMapInfo): Promise; @@ -70,6 +72,7 @@ interface Client { renameMap(id: number, basicInfo: BasicMapInfo): Promise; fetchAllMaps(): Promise; duplicateMap(id: number, basicInfo: BasicMapInfo): Promise; + updateAccountLanguage(locale: LocaleCode): Promise; updateStarred(id: number, starred: boolean): Promise; updateMapToPublic(id: number, starred: boolean): Promise; diff --git a/packages/webapp/src/client/mock-client/index.ts b/packages/webapp/src/client/mock-client/index.ts index f0febd55..518cbc5e 100644 --- a/packages/webapp/src/client/mock-client/index.ts +++ b/packages/webapp/src/client/mock-client/index.ts @@ -1,5 +1,5 @@ import { Language } from '@material-ui/icons'; -import Client, { AccountInfo, BasicMapInfo, ChangeHistory, ImportMapInfo, Label, MapInfo, NewUser} from '..'; +import Client, { AccountInfo, BasicMapInfo, ChangeHistory, ImportMapInfo, Label, LocaleCode, MapInfo, NewUser } from '..'; class MockClient implements Client { private maps: MapInfo[] = []; private labels: Label[] = []; @@ -8,7 +8,7 @@ class MockClient implements Client { // Remove, just for develop .... function createMapInfo( - id: number, + id: number, starred: boolean, title: string, labels: number[], @@ -34,16 +34,23 @@ class MockClient implements Client { ]; } + + updateAccountLanguage(locale: LocaleCode): Promise { + localStorage.setItem('locale', locale); + return Promise.resolve(); + } + importMap(model: ImportMapInfo): Promise { return Promise.resolve(10); } - + fetchAccountInfo(): Promise { + const locale: LocaleCode | null = localStorage.getItem('locale') as LocaleCode; return Promise.resolve({ firstName: 'Costme', lastName: 'Fulanito', email: 'test@example.com', - language: 'en' + language: locale ? locale : 'en' }); } deleteMaps(ids: number[]): Promise { diff --git a/packages/webapp/src/client/rest-client/index.ts b/packages/webapp/src/client/rest-client/index.ts index 07304d8b..68cf3fa9 100644 --- a/packages/webapp/src/client/rest-client/index.ts +++ b/packages/webapp/src/client/rest-client/index.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import Client, { ErrorInfo, MapInfo, BasicMapInfo, NewUser, Label, ChangeHistory, AccountInfo, ImportMapInfo } from '..'; +import Client, { ErrorInfo, MapInfo, BasicMapInfo, NewUser, Label, ChangeHistory, AccountInfo, ImportMapInfo, LocaleCode } from '..'; export default class RestClient implements Client { private baseUrl: string; @@ -9,6 +9,11 @@ export default class RestClient implements Client { this.baseUrl = baseUrl; this.sessionExpired = sessionExpired; } + + updateAccountLanguage(locale: LocaleCode): Promise { + throw "Method not implemented"; + } + importMap(model: ImportMapInfo): Promise { const handler = (success: (mapId: number) => void, reject: (error: ErrorInfo) => void) => { axios.post(this.baseUrl + `/c/restful/maps?title=${model.title}&description=${model.description ? model.description : ''}`, @@ -22,7 +27,8 @@ export default class RestClient implements Client { reject(errorInfo); }); } - return new Promise(handler); } + return new Promise(handler); + } fetchAccountInfo(): Promise { const handler = (success: (account: AccountInfo) => void, reject: (error: ErrorInfo) => void) => { @@ -33,11 +39,12 @@ export default class RestClient implements Client { } ).then(response => { const account = response.data; + const locale: LocaleCode | null = account.locale; success({ lastName: account.lastName ? account.lastName : '', firstName: account.fistName ? account.fistName : '', email: account.email, - language: "en" + language: locale ? locale : 'en' }); }).catch(error => { const errorInfo = this.parseResponseOnError(error.response); diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/export-dialog/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/export-dialog/index.tsx index 250df1b9..121df92d 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/export-dialog/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/export-dialog/index.tsx @@ -115,7 +115,7 @@ const ExportDialog = (props: ExportDialogProps) => { className={classes.label} value="document" control={} - label={intl.formatMessage({ id: "export.document", defaultMessage: "Document: Export your mindmap in a self-contained document ready to share" })} + label={intl.formatMessage({ id: "export.document-label", defaultMessage: "Document: Export your mindmap in a self-contained document ready to share" })} color="secondary" /> {exportGroup == 'document' && (