The browser's default UI for the onbeforeunload dialog currently cannot be changed because it'd be very easy to abuse it:
- Customizing the browser's dialog would allow developers to fool users into staying in the page (e.g. changing the buttons' text content or hiding them).
- You cannot replace the
onbeforeunload dialog with your own code as then the developer would decide when it is ok to close a window, and that is not how browsers work.
The user is in control of the browser, not the developer. Hence these restrictions.
Just assume that the user's browser is in a language which s/he can understand, and s/he can figure out from there. That's the best we have at the moment.
See related thread
This may change in the future with Shadow DOM and new APIs, but I cannot think of any way that wouldn't be easily abused (except by requesting a "prevent closing" API similarly to how browsers handle getUserMedia). Feel free to suggest it to WHATWG if you feel like this is an important feature which will help other developers.