mirror of
https://github.com/fancive/obsidian-parallel-reader.git
synced 2026-07-22 17:20:24 +00:00
fix(i18n): use translate() for error notices in ui-helpers
addIconButton, addTextButton, and copyToClipboard catch blocks now call translate(null, 'actionFailed'/'copyFailed', ...) so notices respect the user's configured UI language. https://claude.ai/code/session_012cK5rUGQvqkuxUZ59x7dLn
This commit is contained in:
parent
597a6582a9
commit
a20d94ca7e
1 changed files with 6 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import { Notice, setIcon } from 'obsidian';
|
||||
import { translate } from './i18n';
|
||||
|
||||
export function addIconButton(parent: HTMLElement, icon: string, title: string, onClick: () => void | Promise<void>) {
|
||||
const button = parent.createEl('button', {
|
||||
|
|
@ -18,7 +19,9 @@ export function addIconButton(parent: HTMLElement, icon: string, title: string,
|
|||
e.stopPropagation();
|
||||
Promise.resolve(onClick()).catch((err: unknown) => {
|
||||
console.error(err);
|
||||
new Notice(`${title} failed: ${err instanceof Error ? err.message : String(err)}`);
|
||||
new Notice(
|
||||
translate(null, 'actionFailed', { label: title, error: err instanceof Error ? err.message : String(err) }),
|
||||
);
|
||||
});
|
||||
});
|
||||
return button;
|
||||
|
|
@ -42,7 +45,7 @@ export function addTextButton(
|
|||
e.stopPropagation();
|
||||
Promise.resolve(onClick()).catch((err: unknown) => {
|
||||
console.error(err);
|
||||
new Notice(`${label} failed: ${err instanceof Error ? err.message : String(err)}`);
|
||||
new Notice(translate(null, 'actionFailed', { label, error: err instanceof Error ? err.message : String(err) }));
|
||||
});
|
||||
});
|
||||
return button;
|
||||
|
|
@ -53,6 +56,6 @@ export async function copyToClipboard(text: string, successMsg: string) {
|
|||
await navigator.clipboard.writeText(text);
|
||||
new Notice(successMsg);
|
||||
} catch (e: unknown) {
|
||||
new Notice(`Copy failed: ${e instanceof Error ? e.message : String(e)}`);
|
||||
new Notice(translate(null, 'copyFailed', { error: e instanceof Error ? e.message : String(e) }));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue