From c78237a0d9f822928ed5bfdc49437560d45ff075 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Fri, 14 Jul 2023 10:47:52 +0530 Subject: [PATCH] fix: translations in setup wiz - maintain translations on reload --- fyo/utils/translation.ts | 2 +- src/App.vue | 2 +- src/pages/DatabaseSelector.vue | 3 +++ src/pages/SetupWizard/SetupWizard.vue | 4 +++- src/utils/misc.ts | 14 +++++++++++--- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/fyo/utils/translation.ts b/fyo/utils/translation.ts index 598ba41c..f20ae057 100644 --- a/fyo/utils/translation.ts +++ b/fyo/utils/translation.ts @@ -10,7 +10,7 @@ import { ValueError } from './errors'; export type TranslationArgs = boolean | number | string; export type TranslationLiteral = TemplateStringsArray | TranslationArgs; -class TranslationString { +export class TranslationString { args: TranslationLiteral[]; argList?: TranslationArgs[]; strList?: string[]; diff --git a/src/App.vue b/src/App.vue index c40b1b27..0fd679aa 100644 --- a/src/App.vue +++ b/src/App.vue @@ -144,11 +144,11 @@ export default defineComponent({ await this.searcher.initializeKeywords(); }, async setDesk(filePath: string): Promise { + await setLanguageMap(); this.activeScreen = Screen.Desk; await this.setDeskRoute(); await fyo.telemetry.start(true); await ipc.checkForUpdates(); - await setLanguageMap(); this.dbPath = filePath; this.companyName = (await fyo.getValue( ModelNameEnum.AccountingSettings, diff --git a/src/pages/DatabaseSelector.vue b/src/pages/DatabaseSelector.vue index f4e76bd6..0a33ffb9 100644 --- a/src/pages/DatabaseSelector.vue +++ b/src/pages/DatabaseSelector.vue @@ -176,6 +176,9 @@ py-1.5 w-28 h-8 + no-scrollbar + overflow-x-auto + whitespace-nowrap " :disabled="creatingDemo" @click="createDemo" diff --git a/src/pages/SetupWizard/SetupWizard.vue b/src/pages/SetupWizard/SetupWizard.vue index 33292d8a..d9aaf62e 100644 --- a/src/pages/SetupWizard/SetupWizard.vue +++ b/src/pages/SetupWizard/SetupWizard.vue @@ -73,6 +73,7 @@ import { DocValue } from 'fyo/core/types'; import { Doc } from 'fyo/model/doc'; import { Verb } from 'fyo/telemetry/types'; +import { TranslationString } from 'fyo/utils/translation'; import { ModelNameEnum } from 'models/types'; import { Field } from 'schemas/types'; import Button from 'src/components/Button.vue'; @@ -146,7 +147,8 @@ export default defineComponent({ }, }, async mounted() { - this.docOrNull = getSetupWizardDoc(); + const languageMap = TranslationString.prototype.languageMap; + this.docOrNull = getSetupWizardDoc(languageMap); if (!this.fyo.db.isConnected) { await this.fyo.db.init(); } diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 421889cf..11434093 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -1,14 +1,18 @@ import { Fyo } from 'fyo'; import { ConfigFile } from 'fyo/core/types'; +import { translateSchema } from 'fyo/utils/translation'; +import { cloneDeep } from 'lodash'; import { DateTime } from 'luxon'; import { SetupWizard } from 'models/baseModels/SetupWizard/SetupWizard'; import { ModelNameEnum } from 'models/types'; +import { reports } from 'reports/index'; import SetupWizardSchema from 'schemas/app/SetupWizard.json'; import { Schema } from 'schemas/types'; import { fyo } from 'src/initFyo'; import { QueryFilter } from 'utils/db/types'; +import { schemaTranslateables } from 'utils/translationHelpers'; +import type { LanguageMap } from 'utils/types'; import { PeriodKey } from './types'; -import { reports } from 'reports/index'; export function getDatesAndPeriodList(period: PeriodKey): { periodList: DateTime[]; @@ -49,16 +53,20 @@ export function getDatesAndPeriodList(period: PeriodKey): { }; } -export function getSetupWizardDoc() { +export function getSetupWizardDoc(languageMap?: LanguageMap) { /** * This is used cause when setup wizard is running * the database isn't yet initialized. */ + const schema = cloneDeep(SetupWizardSchema); + if (languageMap) { + translateSchema(schema, languageMap, schemaTranslateables); + } return fyo.doc.getNewDoc( 'SetupWizard', {}, false, - SetupWizardSchema as Schema, + schema as Schema, SetupWizard ); }