Skip to content

Commit

Permalink
fix #41, fix undefined found in #42
Browse files Browse the repository at this point in the history
  • Loading branch information
phibr0 committed Aug 17, 2021
1 parent 25a7a37 commit 6b54094
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/l10n/locale/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/l10n/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 15 additions & 10 deletions src/localDictionaryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -31,15 +34,17 @@ export default class LocalDictionaryBuilder {

let phonetics = '';
content.phonetics.forEach((value, i, a) => {
phonetics += '- ' + (value.audio ? `<details><summary>${value.text}</summary><audio controls><source src="${value.audio}"></audio></details>` : value.text);
if (i != a.length - 1) {
phonetics += '\n';
if (value.text) {
phonetics += '- ' + (value.audio ? `<details><summary>${value.text}</summary><audio controls><source src="${value.audio.startsWith("http") ? value.audio : "https://" + value.audio}"></audio></details>` : 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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dictionary/meaningComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="main">
<details>
<summary>{partOfSpeech}</summary>
<summary>{partOfSpeech ?? ""}</summary>

{#each definitions as definition, i}
<div class="definition">
Expand Down

0 comments on commit 6b54094

Please sign in to comment.