Devlog #7 — Fixing the Language That Forgot to Switch
Project: Moksha
Version: v0.0.9 (pre-release)
Date: August 2026
Author: Weired Codes
The Bug
When English was selected as the game language, Hindi text was still appearing in several places during gameplay.
Timers above the player still said "पुण्य +" and "प्रारब्ध शेष". The final phase header still read "अंतिम चरण" on the canvas. The rebirth notification still appeared as "♻️ पवित्र पुनर्जन्म". Even the end screen restart prompt stayed in Hindi.
The language toggle looked like it worked — the Shastra scroll, alerts, and UI panels would switch — but the deeper gameplay layer stayed Hindi regardless of what the player chose.
This was Issue #58.
Finding the Root Causes
After auditing the codebase, two separate problems were found.
1. A Broken Regex in the Translation System
The t() function in i18n.js is responsible for replacing {n}, {punya}, {paap} and similar placeholders in translated strings. The regex it used was:
/\{(w+)}/g
w+ matches the literal letter w one or more times — not word characters. The correct regex is \w+ (with a backslash). Because of this single missing backslash, every parameterized translation in the entire game was silently broken. Strings like "अधिकतम {n} — नया बोझ असंभव।" were being returned with {n} still inside them, untranslated.
This was a quiet bug — no console error, no crash. The string just came back wrong.
2. Hardcoded Hindi Strings Bypassing the i18n System
Several places across the codebase were writing Hindi text directly instead of going through t():
-
karma.js— rebirthnotifyTextand the MokshasamayaVallabel -
engine.js—notifyTextin the constructor andreset(), and the Prārabdha liberation floating text ("📜🔥 मुक्त!") -
render.js— three canvasfillText()calls for the final phase header, Puṇya timer label, and Prārabdha countdown label -
index.html— the end screen restart hint paragraph
None of these consulted the language system. They were relics from before the i18n module existed.
The Fix
Six files changed.
i18n.js got the regex corrected (\{(\w+)\}) and six new translation keys were added — one each for the final phase canvas header, the Puṇya timer label, the Prārabdha timer label, the liberation floating text, the Moksha samaya display, and the end screen restart hint — in both Hindi and English.
karma.js was given an import { t } and its three hardcoded strings were replaced with t() calls. Two of them reuse existing alert title keys rather than duplicating strings.
engine.js had its constructor notifyText cleared to an empty string (it is never displayed before the first rebirth anyway) and the reset() call updated to use t(). The "📜🔥 मुक्त!" floating text was moved to the new notify.prarabdhaMukta key.
render.js received t in its import and the three canvas text literals were replaced.
index.html got an id="restart-hint-text" on the restart hint paragraph.
main.js updates that element inside applyStartScreenLanguage(), so it switches correctly whenever the player toggles the language — even before starting the game.
What English Players See Now
- The canvas timer labels read "Puṇya +" and "Prārabdha {n} remaining"
- The final phase header reads "Final Phase"
- Rebirth notifications read "♻️ Pure Punarjanma" and "♻️ Impure Punarjanma"
- The Moksha samaya display reads "Moksha 🌿"
- The liberation floating text reads "📜🔥 Freed!"
- The end screen restart prompt reads "Press 'R' to restart the life chariot"
- All parameterized alerts (karma counts, Prārabdha limits, etc.) now correctly interpolate their values
A Note on Shloka Text
By design, Sanskrit ślokas — in the Shastra scroll, the tutorial cards, and floating Devanagari symbols like ॐ — remain in Devanagari regardless of language. This is Rule E-1 of the project: sacred text is never translated. "ॐ", "राधा", and the ślokas are not bugs. They are intentional.
Closing
A small audit, two distinct bugs, and six files. The language system now does what it promises.
— Weired Codes
Moksha is an open-source browser game rooted in Sanatan Shastra.
*Play on itch.io · GitHub
Top comments (0)