From 68712166497bf134467b1d5a1034681bba47502e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 11 Aug 2024 07:36:00 +0300 Subject: [PATCH 01/14] server: Set up a locale option --- src/services/options_init.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/services/options_init.ts b/src/services/options_init.ts index b07300150..111e78cd4 100644 --- a/src/services/options_init.ts +++ b/src/services/options_init.ts @@ -16,6 +16,12 @@ interface NotSyncedOpts { syncProxy?: string; } +interface DefaultOption { + name: string; + value: string; + isSynced: boolean; +} + async function initNotSyncedOptions(initialized: boolean, theme: string, opts: NotSyncedOpts = {}) { optionService.createOption('openNoteContexts', JSON.stringify([ { @@ -35,13 +41,13 @@ async function initNotSyncedOptions(initialized: boolean, theme: string, opts: N optionService.createOption('lastSyncedPush', '0', false); optionService.createOption('theme', theme, false); - + optionService.createOption('syncServerHost', opts.syncServerHost || '', false); optionService.createOption('syncServerTimeout', '120000', false); optionService.createOption('syncProxy', opts.syncProxy || '', false); } -const defaultOptions = [ +const defaultOptions: DefaultOption[] = [ { name: 'revisionSnapshotTimeInterval', value: '600', isSynced: true }, { name: 'protectedSessionTimeout', value: '600', isSynced: true }, { name: 'zoomFactor', value: process.platform === "win32" ? '0.9' : '1.0', isSynced: false }, @@ -88,7 +94,8 @@ const defaultOptions = [ { name: 'customSearchEngineName', value: 'DuckDuckGo', isSynced: true }, { name: 'customSearchEngineUrl', value: 'https://duckduckgo.com/?q={keyword}', isSynced: true }, { name: 'promotedAttributesOpenInRibbon', value: 'true', isSynced: true }, - { name: 'editedNotesOpenInRibbon', value: 'true', isSynced: true } + { name: 'editedNotesOpenInRibbon', value: 'true', isSynced: true }, + { name: 'locale', value: 'en', isSynced: true } ]; function initStartupOptions() { From 51afb63e25b489249cadf1e2006d1b1fe41b59b8 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 11 Aug 2024 07:36:09 +0300 Subject: [PATCH 02/14] server: Add endpoint to get list of locales --- src/routes/api/options.ts | 17 ++++++++++++++++- src/routes/routes.ts | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/routes/api/options.ts b/src/routes/api/options.ts index 2113746ba..d7ea7520a 100644 --- a/src/routes/api/options.ts +++ b/src/routes/api/options.ts @@ -129,6 +129,20 @@ function getUserThemes() { return ret; } +function getSupportedLocales() { + // TODO: Currently hardcoded, needs to read the lits of available languages. + return [ + { + "id": "en", + "name": "English" + }, + { + "id": "cn", + "name": "Chinese" + } + ]; +} + function isAllowed(name: string) { return ALLOWED_OPTIONS.has(name) || name.startsWith("keyboardShortcuts") @@ -140,5 +154,6 @@ export default { getOptions, updateOption, updateOptions, - getUserThemes + getUserThemes, + getSupportedLocales }; diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 5a3e181c5..e808c1e0d 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -217,6 +217,7 @@ function register(app: express.Application) { apiRoute(PUT, '/api/options/:name/:value*', optionsApiRoute.updateOption); apiRoute(PUT, '/api/options', optionsApiRoute.updateOptions); apiRoute(GET, '/api/options/user-themes', optionsApiRoute.getUserThemes); + apiRoute(GET, '/api/options/locales', optionsApiRoute.getSupportedLocales); apiRoute(PST, '/api/password/change', passwordApiRoute.changePassword); apiRoute(PST, '/api/password/reset', passwordApiRoute.resetPassword); From bc648e981eb534d274a09ad03b9268a62eca862b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 11 Aug 2024 07:46:27 +0300 Subject: [PATCH 03/14] client: Add language switcher in settings --- .../widgets/type_widgets/content_widget.js | 2 + .../type_widgets/options/appearance/i18n.js | 39 +++++++++++++++++++ src/routes/api/options.ts | 3 +- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/public/app/widgets/type_widgets/options/appearance/i18n.js diff --git a/src/public/app/widgets/type_widgets/content_widget.js b/src/public/app/widgets/type_widgets/content_widget.js index fe7f105af..6c2ddc0cb 100644 --- a/src/public/app/widgets/type_widgets/content_widget.js +++ b/src/public/app/widgets/type_widgets/content_widget.js @@ -32,6 +32,7 @@ import DatabaseAnonymizationOptions from "./options/advanced/database_anonymizat import BackendLogWidget from "./content/backend_log.js"; import AttachmentErasureTimeoutOptions from "./options/other/attachment_erasure_timeout.js"; import RibbonOptions from "./options/appearance/ribbon.js"; +import LocalizationOptions from "./options/appearance/i18n.js"; const TPL = `