From 6b54094e6c59c758e8ecd68503c87633c3bd104c Mon Sep 17 00:00:00 2001 From: phibr0 Date: Tue, 17 Aug 2021 09:20:52 +0200 Subject: [PATCH] fix #41, fix undefined found in #42 --- manifest.json | 2 +- src/l10n/locale/de.ts | 2 +- src/l10n/locale/en.ts | 1 + src/localDictionaryBuilder.ts | 25 ++++++++++++++--------- src/ui/dictionary/meaningComponent.svelte | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/manifest.json b/manifest.json index fde1674..038bb0e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-dictionary-plugin", "name": "Dictionary", - "version": "2.15.1", + "version": "2.15.2", "minAppVersion": "0.12.11", "description": "This is a simple dictionary for the Obsidian Note-Taking Tool.", "author": "phibr0", diff --git a/src/l10n/locale/de.ts b/src/l10n/locale/de.ts index c5263d0..33fd650 100644 --- a/src/l10n/locale/de.ts +++ b/src/l10n/locale/de.ts @@ -70,7 +70,7 @@ export default { "No, keep the old File.": "Nein, behalte die alte Datei", "Yes, overwrite the old File.": "Ja, überschreibe die alte Datei", "A existing File with the same Name was found, do you want to overwrite it?": "Eine bereits existierende Datei mit dem gleichen Namen wurde gefunden, möchtest du diese überschreiben?", - + "Meaning {{i}}": "Bedeutung {{i}}", //infoModal.svelte 'API Information': 'API Informationen', 'Definition API\'s': 'Definitionen APIs', diff --git a/src/l10n/locale/en.ts b/src/l10n/locale/en.ts index 3518d3c..c0bc067 100644 --- a/src/l10n/locale/en.ts +++ b/src/l10n/locale/en.ts @@ -71,6 +71,7 @@ export default { "Yes, overwrite the old File.": "Yes, overwrite the old File.", "A existing File with the same Name was found, do you want to overwrite it?": "A existing File with the same Name was found, do you want to overwrite it?", "No, keep the old File.": "No, keep the old File.", + "Meaning {{i}}": "Meaning {{i}}", //infoModal.svelte diff --git a/src/localDictionaryBuilder.ts b/src/localDictionaryBuilder.ts index 552de35..34a03d7 100644 --- a/src/localDictionaryBuilder.ts +++ b/src/localDictionaryBuilder.ts @@ -18,11 +18,14 @@ export default class LocalDictionaryBuilder { } private cap(string: string): string { - const words = string.split(" "); + if (string) { + const words = string.split(" "); - return words.map((word) => { - return word[0].toUpperCase() + word.substring(1); - }).join(" "); + return words.map((word) => { + return word[0].toUpperCase() + word.substring(1); + }).join(" "); + } + return string; } async newNote(content: DictionaryWord): Promise { @@ -31,15 +34,17 @@ export default class LocalDictionaryBuilder { let phonetics = ''; content.phonetics.forEach((value, i, a) => { - phonetics += '- ' + (value.audio ? `
${value.text}
` : value.text); - if (i != a.length - 1) { - phonetics += '\n'; + if (value.text) { + phonetics += '- ' + (value.audio ? `
${value.text}
` : value.text); + if (i != a.length - 1) { + phonetics += '\n'; + } } }); let meanings = ''; - content.meanings.forEach((value) => { - meanings += '### ' + this.cap(value.partOfSpeech) + '\n\n'; + content.meanings.forEach((value, i) => { + meanings += '### ' + this.cap(value.partOfSpeech ?? t("Meaning {{i}}").replace(/{{i}}/g, (i + 1).toString())) + '\n\n'; value.definitions.forEach((def, j, b) => { meanings += def.definition + '\n\n'; if (def.example) { @@ -73,7 +78,7 @@ export default class LocalDictionaryBuilder { .replace(/{{lang}}/ig, langString); try { - if(!(await plugin.app.vault.adapter.exists(normalizePath(`${settings.folder ? settings.folder + '/' : ''}${settings.languageSpecificSubFolders ? langString + '/' : ''}`)))) { + if (!(await plugin.app.vault.adapter.exists(normalizePath(`${settings.folder ? settings.folder + '/' : ''}${settings.languageSpecificSubFolders ? langString + '/' : ''}`)))) { await plugin.app.vault.createFolder(normalizePath(`${settings.folder ? settings.folder + '/' : ''}${settings.languageSpecificSubFolders ? langString + '/' : ''}`)); } file = await plugin.app.vault.create(normalizePath(path), contents); diff --git a/src/ui/dictionary/meaningComponent.svelte b/src/ui/dictionary/meaningComponent.svelte index 8c5f691..5481b7e 100644 --- a/src/ui/dictionary/meaningComponent.svelte +++ b/src/ui/dictionary/meaningComponent.svelte @@ -9,7 +9,7 @@
- {partOfSpeech} + {partOfSpeech ?? ""} {#each definitions as definition, i}