Localization for javascript confirmation buttons

insomiac picture insomiac · Dec 4, 2012 · Viewed 12.1k times · Source

I am working with Confirm box in javascript. For all browsers i found that when change the language of the browser, the confirmation button language in Confirm box doesn't change. I tested on chrome, firefox by changing the language to french. But the buttons label is not translated. Label of "OK" and "Cancel" doesn't change to other language.

Please Note : I am trying to see the localized string on confirmation box.

Answer

Paweł Dyda picture Paweł Dyda · Dec 4, 2012

There is no way to use confirm() and alert() JavaScript functions and have reliable results. It simply depends on the language of web browser, that is the program, not your preferred language.
The preferred language is used to tell the web server what is your preference in reference to the web page language.

So how to localize the confirmation or message dialogs, you would ask?
Well, get rid of them. Instead, please use jQuery UI Dialog's modal confirmation and follow your regular localization method for JavaScript string resources.
It is the only way to have confirmation dialog's titles and buttons translated reliably to the language of your web application.