javascript 确认按钮的本地化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13694133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:30:36  来源:igfitidea点击:

Localization for javascript confirmation buttons

javascriptlocalizationinternationalizationconfirm

提问by insomiac

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.

我正在使用 javascript 中的确认框。对于所有浏览器,我发现更改浏览器语言时,确认框中的确认按钮语言不会更改。我通过将语言更改为法语在 chrome、firefox 上进行了测试。但是按钮标签没有翻译。“确定”和“取消”的标签不会更改为其他语言。

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

请注意:我试图在确认框中查看本地化的字符串。

回答by Pawe? Dyda

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 pagelanguage.

没有办法使用confirm()alert()JavaScript 函数并有可靠的结果。它仅取决于网络浏览器的语言,即程序,而不是您的首选语言。
首选语言用于告诉网络服务器您对网页语言的偏好。

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 confirmationand 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.

那么您会问如何本地化确认或消息对话框?
好吧,摆脱他们。相反,请使用jQuery UI Dialog 的模式确认并遵循您对 JavaScript 字符串资源的常规本地化方法。
这是将确认对话框的标题和按钮可靠地翻译成 Web 应用程序语言的唯一方法。