How to get client's system “Region and Language” settings on server?

本小妞迷上赌 提交于 2019-12-25 09:47:52

问题


Is there any way to get format settings (country from "Formats" tab on "Region and Language" popup in Windows) in JavaScript so I can pass it to server in cookie? (big target - display dates in correct format on MVC 4 server-side)

In IE9 I can use navigator.UserLanguage (also correct language is passed in Accept-Language http header).

But in Chrome and FF navigator.UserLanguage is undefined, navigator.language and Accept-Language returns browser's interface language.


回答1:


It is not possible for JS or anything else to access this setting, however there is the HTTP_ACCEPT_LANGUAGE language property which can be accessed on the server. For example with PHP you can do:

 echo $_SERVER['HTTP_ACCEPT_LANGUAGE'];

which will echo something like en-US. In most cases this will probably be the users prefered language, so why not use it?



来源:https://stackoverflow.com/questions/14281860/how-to-get-clients-system-region-and-language-settings-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!