Skip to content

fix(i18n): keep lang/labels/dict function-scoped to fix Anki redeclaration crash#18

Merged
SKOHscripts merged 3 commits into
mainfrom
claude/tender-clarke-88XbU
May 27, 2026
Merged

fix(i18n): keep lang/labels/dict function-scoped to fix Anki redeclaration crash#18
SKOHscripts merged 3 commits into
mainfrom
claude/tender-clarke-88XbU

Conversation

@SKOHscripts

Copy link
Copy Markdown
Owner

Problème

Le PR #17 a cassé tout l'affichage en déplaçant lang, labels et dict au niveau module (const hors de toute fonction).

Anki réutilise le même contexte JavaScript pour les deux faces d'une carte. Quand le script du template back s'exécute après celui du front, les déclarations const lang, const labels, const dict au niveau module déclenchent :

SyntaxError: Identifier 'lang' has already been declared

Ce crash interrompt tout le script — le plateau d'échecs ne se rend plus, aucune traduction n'est appliquée.

Fix

  • Remettre lang, labels, dict à l'intérieur de applyFenToBoard() (portée fonction → ré-évaluable sans conflit).
  • Le label du bouton coords est appliqué à l'étape 7 de cette même fonction — pas besoin de dépendance i18n dans initCoordsToggle().
  • Toutes les traductions du bouton coords (ajoutées dans fix(i18n): move lang/dict to module scope and translate coords button #17) sont conservées.

Test plan

  • Afficher la face avant d'une carte → plateau rendu, "Trait aux blancs/noirs" en fr, bouton "Coords"
  • Retourner la carte → face arrière rendue correctement, pas de JS error en console
  • Vérifier avec plusieurs langues (de, ja…) que les labels s'affichent bien
  • Toggle coords fonctionne et persiste

https://claude.ai/code/session_01W4q82SG7ivHr15HiowDczK


Generated by Claude Code

claude added 3 commits May 27, 2026 14:08
…aration crash

Anki reuses the same WebView JS context for both card faces, so module-level
`const` declarations in the front template throw "Identifier already declared"
when the back template script runs, breaking all rendering.

Revert to declaring lang/labels/dict inside applyFenToBoard() (function scope,
safe to re-evaluate). The coords button label is now set from step 7 of that
same function, so no second lang lookup is needed and initCoordsToggle() stays
free of any i18n dependency.

https://claude.ai/code/session_01W4q82SG7ivHr15HiowDczK
…n; pin coords button top-right

Language detection: prefer navigator.languages[0] (ordered preference array,
more reliable in Chromium/Qt WebEngine WebViews used by Anki) over
navigator.language, keeping the existing fallback chain for older runtimes.

Layout: #coords-toggle is now position:fixed top:8px right:8px z-index:100,
so it is pinned to the viewport corner and removed from the normal flow.
The puzzle-meta and puzzle-actions flex containers reflow without the button,
keeping all other elements centered.

https://claude.ai/code/session_01W4q82SG7ivHr15HiowDczK
"Coords" → "Coord." for French so the translated value visibly differs
from the hardcoded HTML default, making it possible to confirm the
i18n code path is actually executing on the card.

https://claude.ai/code/session_01W4q82SG7ivHr15HiowDczK
@SKOHscripts SKOHscripts marked this pull request as ready for review May 27, 2026 14:37
@SKOHscripts SKOHscripts merged commit c4f257c into main May 27, 2026
14 checks passed
@SKOHscripts SKOHscripts deleted the claude/tender-clarke-88XbU branch May 27, 2026 14:37
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