Skip to content

Add a translation switcher for localized content pages - #55

Merged
xprees merged 3 commits into
masterfrom
ccr-f27f9a8d-ohbasu-translations
Nov 17, 2026
Merged

xprees merged 3 commits into
masterfrom
ccr-f27f9a8d-ohbasu-translations

Conversation

@xprees

@xprees xprees commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

What and why

Requested: a quick way to compare or switch between translations when content is localized in per-locale folders (content/pages/en/, content/pages/cs/). The request covered a floating button in the top-right corner of the editor with a drop-down of the translated pages, plus Open side by side, Create missing translation, a missing-translation warning, and settings.

How a page's translations are found (ComarkTranslations)

  • Locale directory: a directory whose name is a locale code (ISO 639-1, optionally with a region or script: en, pt-br, zh-hant). It counts if either:

    • the locales are known and include it (from the Locales setting, else i18n.locales in nuxt.config.*); or
    • a sibling directory is a locale code too.

    A lone id/ or it/ folder is not a locale. The nearest locale directory above a page defines its locale, and that directory's parent is the group. Known locales without a directory still count, so the page is reported missing there.

  • Counterpart in another locale: checked in this order, with no fuzzy guessing (several matches are all listed):

    1. the same path below that locale's directory (threats/en/01.phishing.md ↔ threats/cs/01.phishing.md);
    2. a front matter key naming the page, counterpart by default and configurable. The value can be a stem, slug or path, compared without ordering prefixes, and the link works in either direction;
    3. a string map in content.config.* such as { about: 'o-nas', terms: 'podminky' }, used only when both sides name pages.
  • Caching: results are cached per group and invalidated on file structure changes, Comark edits, settings changes, and changes to the content or Nuxt config. Front matter is cached per file stamp.

UI

  • Floating toolbar (editorFloatingToolbarProvider):
    • the button shows the page's locale (EN) and opens a drop-down;
    • it is shown only in editors of localized pages, decided in register();
    • the drop-down lists the current page (ticked), then CS · o-nas.md to switch, Open CS side by side · o-nas.md (EditorWindow.split), and Create CS translation… for each missing locale.
  • Navigate › Switch to Translation: opens the page directly when there is a single translation, otherwise shows the same list in a popup. Translations also appear in Navigate › Related Symbol.
  • Create translation (ComarkTranslationCreator): asks for the path below the locale's directory, prefilled with the same path. It creates missing directories and copies the page as one undoable command, then opens it. When the new name differs, it writes counterpart: <stem or slug> into the front matter.
  • Missing translation inspection (weak warning, on by default): reported on the first line, with a Create … translation fix per locale.
  • Settings › Languages & Frameworks › Comark › Translations: Show translation switcher, Locales, Front matter keys. Changing them re-runs highlighting.

Safety

  • The change is additive: parsing, formatting and highlighting are untouched.
  • Both new extension points are dynamic, so the plugin still installs and removes without a restart.
  • Plugin Verifier on IDEA 2026.3: "Compatible. 8 usages of experimental API", the same baseline as before this PR. No deprecated, internal or scheduled-for-removal usages.
    • These calls are deprecated in 2026.3, so the PR avoids them:
      • FloatingToolbarProvider.isApplicable and priority: the switcher is shown from register() instead;
      • FileEditorManager.openFile(...): translations open with OpenFileDescriptor.navigate;
      • DaemonCodeAnalyzer.restart(): replaced by restart(reason).
    • The experimental onHiddenByEsc is not overridden.

How it was tested

  • ComarkTranslationsTest (10 tests), on the reporter's layout: pages in en/cs with translated slugs, numbered threats, a pagePairs map in content.config.ts, and a lone id/ folder. It covers:
    • locales, groups and the id/ negative case;
    • same-path, counterpart (both directions) and config-map pairing;
    • known locales adding missing directories, and limiting the locales;
    • i18n.locales from nuxt.config;
    • creating a translation (same name; other name with counterpart; a new locale directory; validation);
    • front matter editing;
    • the inspection (reported once; complete pages not reported; the fix creates the page);
    • the switcher items, toolbar applicability and the setting, the switch action, Go to Related, and the parsers.
  • ./gradlew test: 913 tests, 0 failures.
  • CI passes: build, tests, and the verifier against IDEA 2026.3, WebStorm 2026.3 and Rider 2026.2.3.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KGGeqcwjamvMDTrazMJWkz

Localized content kept in one directory per locale (content/pages/en/
next to content/pages/cs/) gets a drop-down in the editor's floating
toolbar: switch to a translation, open it side by side, or create a
missing one. Pages pair by the same path below the locale directory,
else by a front matter key (counterpart by default, stem/slug/path,
either direction), else by a string map in content.config.ts.
Locales come from the settings, the i18n.locales of nuxt.config, or
sibling directories named like locale codes.

Also Navigate > Switch to Translation, Related Symbol items, and a
Missing translation weak warning whose fix creates the page (with
counterpart set when its name differs). Settings: show the switcher,
locales, front matter keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KGGeqcwjamvMDTrazMJWkz
Show the floating switcher from register() instead of overriding
isApplicable, open translations with openFile(file), and restart the
daemon with a reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KGGeqcwjamvMDTrazMJWkz
FileEditorManager.openFile(VirtualFile) is deprecated in 2026.3 too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KGGeqcwjamvMDTrazMJWkz
@xprees
xprees merged commit 335b0e0 into master Nov 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants