Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(llm): proper translation use for element interpolation
Elian Doranbb72b0cdfcc4
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.mdindex 25595b95b6..7184420945 100644--- a/.github/copilot-instructions.md+++ b/.github/copilot-instructions.md@@ -313,6 +313,7 @@ Trilium provides powerful user scripting capabilities:- Translation files in `apps/client/src/translations/`- Use translation system via `t()` function- Automatic pluralization: Add `_other` suffix to translation keys (e.g., `item` and `item_other` for singular/plural)+- When a translated string contains **interpolated components** (e.g. links, note references) whose order may vary across languages, use `<Trans>` from `react-i18next` instead of `t()`. This lets translators reorder components freely (e.g. `"<Note/> in <Parent/>"` vs `"in <Parent/>, <Note/>"`)## Testing Conventionsdiff --git a/CLAUDE.md b/CLAUDE.mdindex b0573cea0c..a135324789 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -120,6 +120,7 @@ Trilium provides powerful user scripting capabilities:- Supported languages: English, German, Spanish, French, Romanian, Chinese- **Only add new translation keys to `en/translation.json`** — translations for other languages are managed via Weblate and will be contributed by the community- Third-party components (e.g., mind-map context menu) should use i18next `t()` for their labels, with the English strings added to `en/translation.json` under a dedicated namespace (e.g., `"mind-map"`)+- When a translated string contains **interpolated components** (e.g. links, note references) whose order may vary across languages, use `<Trans>` from `react-i18next` instead of `t()`. This lets translators reorder components freely (e.g. `"<Note/> in <Parent/>"` vs `"in <Parent/>, <Note/>"`)### Security Considerations- Per-note encryption with granular protected sessionsdiff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex ba62c449da..867e041b27 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2323,7 +2323,7 @@"get_child_notes": "Get child notes","get_subtree": "Get subtree","load_skill": "Load skill",- "in_parent": "in"+ "note_in_parent": "<Note/> in <Parent/>"}}}diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsxindex 0a424f89f4..6d806dff38 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx@@ -3,6 +3,7 @@ import "./LlmChat.css";import { Marked } from "marked";import { useMemo } from "preact/hooks";+import { Trans } from "react-i18next";import { t } from "../../../services/i18n.js";import utils from "../../../services/utils.js";import { NewNoteLink } from "../../react/NoteLink.js";@@ -79,12 +80,16 @@ function ToolCallCard({ toolCall }: { toolCall: ToolCall }) {{t(`llm.tools.${toolCall.toolName}`, { defaultValue: toolCall.toolName })}{refNoteId && (<span className="llm-chat-tool-call-note-ref">- <NewNoteLink notePath={refNoteId} showNoteIcon noPreview />- {refParentId && (- <>- {" "}{t("llm.tools.in_parent")}{" "}- <NewNoteLink notePath={refParentId} showNoteIcon noPreview />- </>+ {refParentId ? (+ <Trans+ i18nKey="llm.tools.note_in_parent"+ components={{+ Note: <NewNoteLink notePath={refNoteId} showNoteIcon noPreview />,+ Parent: <NewNoteLink notePath={refParentId} showNoteIcon noPreview />+ } as any}+ />+ ) : (+ <NewNoteLink notePath={refNoteId} showNoteIcon noPreview />)}</span>)}