feat(i18n): wire t() into main.ts

This commit is contained in:
svemagie
2026-04-14 12:42:54 +02:00
parent 85c1b5ba51
commit 86fd568d96
+12 -11
View File
@@ -22,6 +22,7 @@ import { Publisher } from "./Publisher";
import { MicropubClient } from "./MicropubClient"; import { MicropubClient } from "./MicropubClient";
import { SyndicationDialog } from "./SyndicationDialog"; import { SyndicationDialog } from "./SyndicationDialog";
import { handleProtocolCallback } from "./IndieAuth"; import { handleProtocolCallback } from "./IndieAuth";
import { t } from "./i18n";
export default class MicropubPlugin extends Plugin { export default class MicropubPlugin extends Plugin {
settings!: MicropubSettings; settings!: MicropubSettings;
@@ -33,7 +34,7 @@ export default class MicropubPlugin extends Plugin {
this.addCommand({ this.addCommand({
id: "publish-to-micropub", id: "publish-to-micropub",
name: "Publish to Micropub", name: t("cmdPublish"),
checkCallback: (checking: boolean) => { checkCallback: (checking: boolean) => {
const file = this.app.workspace.getActiveFile(); const file = this.app.workspace.getActiveFile();
if (!file || file.extension !== "md") return false; if (!file || file.extension !== "md") return false;
@@ -46,7 +47,7 @@ export default class MicropubPlugin extends Plugin {
this.addCommand({ this.addCommand({
id: "publish-to-micropub-update", id: "publish-to-micropub-update",
name: "Update existing Micropub post", name: t("cmdUpdate"),
checkCallback: (checking: boolean) => { checkCallback: (checking: boolean) => {
const file = this.app.workspace.getActiveFile(); const file = this.app.workspace.getActiveFile();
if (!file || file.extension !== "md") return false; if (!file || file.extension !== "md") return false;
@@ -72,10 +73,10 @@ export default class MicropubPlugin extends Plugin {
// ── Ribbon icon ────────────────────────────────────────────────────── // ── Ribbon icon ──────────────────────────────────────────────────────
this.addRibbonIcon("send", "Publish to Micropub", () => { this.addRibbonIcon("send", t("cmdPublish"), () => {
const file = this.app.workspace.getActiveFile(); const file = this.app.workspace.getActiveFile();
if (!file || file.extension !== "md") { if (!file || file.extension !== "md") {
new Notice("Open a Markdown note to publish."); new Notice(t("noticeOpenNote"));
return; return;
} }
this.publishActiveNote(file); this.publishActiveNote(file);
@@ -91,14 +92,14 @@ export default class MicropubPlugin extends Plugin {
private async publishActiveNote(file: TFile): Promise<void> { private async publishActiveNote(file: TFile): Promise<void> {
if (!this.settings.micropubEndpoint) { if (!this.settings.micropubEndpoint) {
new Notice( new Notice(
"⚠️ Micropub endpoint not configured. Open plugin settings to add it.", t("noticeNoEndpoint"),
); );
return; return;
} }
if (!this.settings.accessToken) { if (!this.settings.accessToken) {
new Notice( new Notice(
"⚠️ Access token not configured. Open plugin settings to add it.", t("noticeNoToken"),
); );
return; return;
} }
@@ -111,7 +112,7 @@ export default class MicropubPlugin extends Plugin {
return; return;
} }
const notice = new Notice("Publishing", 0 /* persist until dismissed */); const notice = new Notice(t("noticePublishing"), 0 /* persist until dismissed */);
try { try {
const publisher = new Publisher(this.app, this.settings); const publisher = new Publisher(this.app, this.settings);
@@ -123,15 +124,15 @@ export default class MicropubPlugin extends Plugin {
const urlDisplay = result.url const urlDisplay = result.url
? `\n${result.url}` ? `\n${result.url}`
: ""; : "";
new Notice(`Published!${urlDisplay}`, 8000); new Notice(`${t("noticePublished")}${urlDisplay}`, 8000);
} else { } else {
new Notice(`Publish failed: ${result.error}`, 10000); new Notice(t("noticePublishFailed", { error: result.error ?? "" }), 10000);
console.error("[micropub] Publish failed:", result.error); console.error("[micropub] Publish failed:", result.error);
} }
} catch (err: unknown) { } catch (err: unknown) {
notice.hide(); notice.hide();
const msg = err instanceof Error ? err.message : String(err); const msg = err instanceof Error ? err.message : String(err);
new Notice(`❌ Error: ${msg}`, 10000); new Notice(t("noticeError", { error: msg }), 10000);
console.error("[micropub] Unexpected error:", err); console.error("[micropub] Unexpected error:", err);
} }
} }
@@ -165,7 +166,7 @@ export default class MicropubPlugin extends Plugin {
} catch { } catch {
// Config fetch failed — fall back to normal publish without dialog // Config fetch failed — fall back to normal publish without dialog
new Notice( new Notice(
"⚠️ Could not fetch syndication targets. Publishing without dialog.", t("noticeNoSyndTargets"),
4000, 4000,
); );
return undefined; return undefined;