From 4a660152581ea3471a741272a054b9288cba417e Mon Sep 17 00:00:00 2001 From: Florian Wathling Date: Sun, 22 Mar 2026 18:07:03 +0100 Subject: [PATCH] feat(i18n): data.js, bookmark-import.js, storage.js auf t() umstellen --- src/js/bookmark-import.js | 38 +++++++++++++++++++------------------- src/js/data.js | 20 ++++++++++---------- src/js/storage.js | 4 ++-- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/js/bookmark-import.js b/src/js/bookmark-import.js index 0057927..541e7f1 100644 --- a/src/js/bookmark-import.js +++ b/src/js/bookmark-import.js @@ -42,8 +42,8 @@ const BrowserBookmarkImport = { tree = await api.getTree(); } catch (err) { await HellionDialog.alert( - 'Zugriff auf Browser-Lesezeichen nicht möglich. Stelle sicher, dass die Extension die nötigen Berechtigungen hat.', - { type: 'warning', title: 'Lesezeichen-Import' } + t('bm_import.no_access'), + { type: 'warning', title: t('bm_import.title') } ); return; } @@ -51,8 +51,8 @@ const BrowserBookmarkImport = { const folders = this._extractFolders(tree[0]); if (folders.length === 0) { await HellionDialog.alert( - 'Keine Lesezeichen-Ordner gefunden.', - { type: 'warning', title: 'Lesezeichen-Import' } + t('bm_import.no_folders'), + { type: 'warning', title: t('bm_import.title') } ); return; } @@ -79,7 +79,7 @@ const BrowserBookmarkImport = { result.push({ id: child.id, - title: child.title || 'Unbenannt', + title: child.title || t('bm_import.unnamed'), depth: depth, bookmarkCount: bookmarkCount, subfolderCount: subfolderCount, @@ -114,7 +114,7 @@ const BrowserBookmarkImport = { header.className = 'bm-import-header'; const title = document.createElement('span'); - title.textContent = 'Browser-Lesezeichen importieren'; + title.textContent = t('bm_import.modal_title'); header.appendChild(title); const closeBtn = document.createElement('button'); @@ -128,7 +128,7 @@ const BrowserBookmarkImport = { // Info const info = document.createElement('div'); info.className = 'bm-import-info'; - info.textContent = 'Wähle die Ordner aus, die als Boards importiert werden sollen. Jeder Ordner wird ein eigenes Board.'; + info.textContent = t('bm_import.info'); modal.appendChild(info); // Ordner-Liste @@ -155,13 +155,13 @@ const BrowserBookmarkImport = { meta.className = 'bm-import-folder-meta'; const parts = []; if (folder.bookmarkCount > 0) { - parts.push(folder.bookmarkCount + ' Link' + (folder.bookmarkCount !== 1 ? 's' : '')); + parts.push(t('bm_import.link_count', { count: folder.bookmarkCount })); } if (folder.subfolderCount > 0) { - parts.push(folder.subfolderCount + ' Ordner'); + parts.push(t('bm_import.folder_count', { count: folder.subfolderCount })); } if (parts.length === 0) { - parts.push('leer'); + parts.push(t('bm_import.empty')); } meta.textContent = parts.join(', '); row.appendChild(meta); @@ -177,18 +177,18 @@ const BrowserBookmarkImport = { const selectAll = document.createElement('button'); selectAll.className = 'btn-secondary'; - selectAll.textContent = 'Alle auswählen'; + selectAll.textContent = t('bm_import.select_all'); selectAll.addEventListener('click', () => { const boxes = list.querySelectorAll('.bm-import-checkbox'); const allChecked = Array.from(boxes).every(function(cb) { return cb.checked; }); boxes.forEach(function(cb) { cb.checked = !allChecked; }); - selectAll.textContent = allChecked ? 'Alle auswählen' : 'Alle abwählen'; + selectAll.textContent = allChecked ? t('bm_import.select_all') : t('bm_import.deselect_all'); }); footer.appendChild(selectAll); const importBtn = document.createElement('button'); importBtn.className = 'btn-primary'; - importBtn.textContent = 'Importieren'; + importBtn.textContent = t('bm_import.import_btn'); importBtn.addEventListener('click', () => this._importSelected(folders)); footer.appendChild(importBtn); @@ -216,8 +216,8 @@ const BrowserBookmarkImport = { const checkboxes = document.querySelectorAll('.bm-import-checkbox:checked'); if (checkboxes.length === 0) { await HellionDialog.alert( - 'Bitte wähle mindestens einen Ordner aus.', - { type: 'warning', title: 'Lesezeichen-Import' } + t('bm_import.no_selection'), + { type: 'warning', title: t('bm_import.title') } ); return; } @@ -289,15 +289,15 @@ const BrowserBookmarkImport = { // Ergebnis-Dialog const lines = []; - lines.push(boardsCreated + ' Board' + (boardsCreated !== 1 ? 's' : '') + ' erstellt'); - lines.push(totalImported + ' Lesezeichen importiert'); + lines.push(t('bm_import.boards_created', { count: boardsCreated })); + lines.push(t('bm_import.bookmarks_imported', { count: totalImported })); if (totalSkipped > 0) { - lines.push(totalSkipped + ' Duplikat' + (totalSkipped !== 1 ? 'e' : '') + ' übersprungen'); + lines.push(t('bm_import.duplicates_skipped', { count: totalSkipped })); } await HellionDialog.alert( lines.join('\n'), - { type: 'success', title: 'Import abgeschlossen' } + { type: 'success', title: t('bm_import.success_title') } ); } }; diff --git a/src/js/data.js b/src/js/data.js index a046ddf..ba8fb03 100644 --- a/src/js/data.js +++ b/src/js/data.js @@ -37,7 +37,7 @@ function initDataButtons() { if (!file) return; try { const data = JSON.parse(await file.text()); - if (!Array.isArray(data.boards)) throw new Error('Ungültiges Format'); + if (!Array.isArray(data.boards)) throw new Error(t('data.invalid_format')); const validBoards = data.boards.filter(b => { if (!b || typeof b.title !== 'string' || !Array.isArray(b.bookmarks)) return false; b.id = b.id || uid(); @@ -50,10 +50,10 @@ function initDataButtons() { }); return true; }); - if (validBoards.length === 0) throw new Error('Keine gültigen Boards gefunden'); + if (validBoards.length === 0) throw new Error(t('data.no_boards')); const ok = await HellionDialog.confirm( - `${validBoards.length} Boards importieren? Bestehende Daten bleiben erhalten.`, - { type: 'info', title: 'JSON Import' } + t('data.import_confirm', { count: validBoards.length }), + { type: 'info', title: t('data.import_confirm.title') } ); if (!ok) return; boards = [...boards, ...validBoards]; @@ -112,15 +112,15 @@ function initDataButtons() { // Gemeinsam speichern await Store.set('widgetStates', existingWidgets); - const noteMsg = notesImported > 0 ? ` + ${notesImported} Note(s)` : ''; - const calcMsg = calcImported ? ' + Calculator-History' : ''; - const timerMsg = timerImported ? ' + Timer-Presets' : ''; + const noteMsg = notesImported > 0 ? t('data.notes_suffix', { count: notesImported }) : ''; + const calcMsg = calcImported ? t('data.calc_suffix') : ''; + const timerMsg = timerImported ? t('data.timer_suffix') : ''; await HellionDialog.alert( - `${validBoards.length} Board(s)${noteMsg}${calcMsg}${timerMsg} erfolgreich importiert.`, - { type: 'success', title: 'Import erfolgreich' } + t('data.import_success', { boards: validBoards.length, notes: noteMsg, calc: calcMsg, timer: timerMsg }), + { type: 'success', title: t('data.import_success.title') } ); } catch (err) { - await HellionDialog.alert('Fehler beim Import: ' + err.message, { type: 'danger', title: 'Import fehlgeschlagen' }); + await HellionDialog.alert(t('data.import_error', { error: err.message }), { type: 'danger', title: t('data.import_error.title') }); } e.target.value = ''; }); diff --git a/src/js/storage.js b/src/js/storage.js index 858b5d9..25725fe 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -23,7 +23,7 @@ const Store = { chrome.storage.local.set({ [key]: value }, () => { if (chrome.runtime.lastError) { console.error('Storage-Fehler:', chrome.runtime.lastError.message); - HellionDialog.alert('Speicher voll! Bitte lösche alte Boards oder das Hintergrundbild, um Platz zu schaffen.', { type: 'danger', title: 'Speicher voll' }); + HellionDialog.alert(t('storage.quota_full'), { type: 'danger', title: t('storage.quota_full.title') }); reject(new Error(chrome.runtime.lastError.message)); return; } @@ -35,7 +35,7 @@ const Store = { resolve(); } catch (e) { console.error('Storage-Fehler:', e.message); - HellionDialog.alert('Speicher voll! Bitte lösche alte Boards oder das Hintergrundbild, um Platz zu schaffen.', { type: 'danger', title: 'Speicher voll' }); + HellionDialog.alert(t('storage.quota_full'), { type: 'danger', title: t('storage.quota_full.title') }); reject(e); } }