Skip to content

Commit

Permalink
fix: improper assignment of variable and prevent read of non-existing…
Browse files Browse the repository at this point in the history
… glossary.json
  • Loading branch information
Fevol committed Dec 7, 2022
1 parent a85102b commit 2ec0596
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
15 changes: 10 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/ui/translator-components/Reactivity.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
Expand Down

0 comments on commit 2ec0596

Please sign in to comment.