diff --git a/src/main.ts b/src/main.ts index 93f8e8e8..7ad1ed0f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -93,11 +93,16 @@ export default class TranslatorPlugin extends Plugin { if (models_data) { localStorage.removeItem(`${app.appId}-models`); const models = JSON.parse(models_data) || {}; - if (models.fasttext) - fasttext_data.set(models.fasttext); - if (models.bergamot) - bergamot_data.set(models.bergamot); - + fasttext_data.set(models.fasttext || { + binary: undefined, + models: undefined, + version: undefined + }); + bergamot_data.set(models.bergamot || { + binary: undefined, + models: undefined, + version: undefined + }); } else { fasttext_data.set(JSON.parse(app.loadLocalStorage('fasttext')) || { binary: undefined, diff --git a/src/ui/translator-components/Reactivity.svelte b/src/ui/translator-components/Reactivity.svelte index 74c02821..e6f2a9f2 100644 --- a/src/ui/translator-components/Reactivity.svelte +++ b/src/ui/translator-components/Reactivity.svelte @@ -382,7 +382,9 @@ } if ($settings.apply_glossary || $settings.local_glossary) { - let loaded_glossaries: any = await app.vault.adapter.read(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`); + let loaded_glossaries = null; + if (await app.vault.adapter.exists(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`)) + loaded_glossaries = await app.vault.adapter.read(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`); if (loaded_glossaries) { glossary.dicts = JSON.parse(loaded_glossaries); for (let key in glossary.dicts) { diff --git a/src/ui/translator-components/settings-tabs/FunctionalitySettings.svelte b/src/ui/translator-components/settings-tabs/FunctionalitySettings.svelte index 79054797..1ebb4cbf 100644 --- a/src/ui/translator-components/settings-tabs/FunctionalitySettings.svelte +++ b/src/ui/translator-components/settings-tabs/FunctionalitySettings.svelte @@ -46,7 +46,9 @@ onChange={ async () => { $settings.local_glossary = !$settings.local_glossary; if ($settings.local_glossary && !Object.keys(glossary.dicts).length) { - let loaded_glossaries = await app.vault.adapter.read(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`); + let loaded_glossaries = null; + if (await app.vault.adapter.exists(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`)) + loaded_glossaries = await app.vault.adapter.read(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`); if (loaded_glossaries) { glossary.dicts = JSON.parse(loaded_glossaries); for (let key in glossary.dicts) diff --git a/src/ui/translator-components/settings-tabs/GlossarySettings.svelte b/src/ui/translator-components/settings-tabs/GlossarySettings.svelte index 7a261b31..6579ed19 100644 --- a/src/ui/translator-components/settings-tabs/GlossarySettings.svelte +++ b/src/ui/translator-components/settings-tabs/GlossarySettings.svelte @@ -105,12 +105,12 @@ onMount(async () => { if (!$settings.local_glossary && !Object.keys(glossary.dicts).length) { - if (await app.vault.adapter.exists(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`)) { - let loaded_glossaries = await app.vault.adapter.read(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`); - if (loaded_glossaries) { - glossaries = new DefaultDict(JSON.parse(loaded_glossaries), []); - glossary_pair = glossaries[language_pair] - } + let loaded_glossaries = null; + if (await app.vault.adapter.exists(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`)) + loaded_glossaries = await app.vault.adapter.read(`${app.vault.configDir}/plugins/obsidian-translate/glossary.json`); + if (loaded_glossaries) { + glossaries = new DefaultDict(JSON.parse(loaded_glossaries), []); + glossary_pair = glossaries[language_pair] } }