refactor(llm): proper translation use for element interpolation

This commit is contained in:
Elian Doran
2026-04-01 15:01:31 +03:00
parent ab2467b074
commit bb72b0cdfc
4 changed files with 14 additions and 7 deletions

View File

@@ -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 Conventions

View File

@@ -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 sessions

View File

@@ -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/>"
}
}
}

View File

@@ -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>
)}