Translating a whole panel with a dictionary, not an attribute per element
An admin panel with dozens of screens and hundreds of strings. Done the usual way, going bilingual means touching every element by hand, and you will certainly forget some.
What I did
A dictionary that walks the text nodes in the page and swaps in what it knows. Arabic is the source; on toggle, the dictionary converts each known string to English.
The walk covers text nodes, the placeholder, title and aria-label attributes, and time elements.
The three rules that govern it
data-en marks text written at runtime that the dictionary has no entry for.
data-raw marks stored values: a customer name, text they wrote, an order reference. These are never translated.
Everything else goes through the dictionary.
The rule that prevents the worst bug
Never add a single common word like "order", "offer" or "contract" to the dictionary.
Here is why. A client may write that word in their message. The dictionary then walks the message and translates it, and you end up reading a record that says something other than what was recorded. data-raw protects against this, but relying on it alone is risky.
A trap that cost me time
I used a plain object for the dictionary. When the walk reached the word toString, the lookup found a match inherited from the prototype chain, returned a function, and the text became [object Window]. The word valueOf aborted the whole switch.
The fix is an object with no prototype:
var DICT = Object.create(null);
How I verify the translation is complete
Counting keys proves nothing. I open every screen, switch to English, and collect every Arabic string still showing.
And the bar is not "no Arabic", it is no Arabic chrome. Customer names, their messages and the audit trail must stay Arabic.
The decisive check: switch, switch back, and compare the text nodes one by one. If everything returns exactly as it was, the toggle loses nothing.
Related reading
Tell me what you want to build. Your first 15 minutes of consulting are free.
Book a consultation