What's best method to detect language? [closed]

回眸只為那壹抹淺笑 提交于 2019-12-31 07:32:42

问题


im making a website (wordpress multisite) which is supported by 2 languages for users, there 2 methods we will use it one:

-Detect language by Geo IP

-Detect Language by Internet Browser

Which is the best method to use it?

Thanks in Advance!


回答1:


If I were you I'd follow this list:

  1. If the user is a registered user, set the language according to his/her preferences

  2. If the user has been on the site before, using language X, use that (store the language option in a cookie).

  3. If the http header Accept-Language is present, try to make use of it (you obviously don't support all the languages in the world). In PHP you can get a hold of this value through $_SERVER['ACCEPT_LANGUAGE'].

    I have seen people make use of Accept-Charset as well, trying to narrow it down if the languages specified (in Accept-Language) can't be used, that is kind of a long shot though.

  4. Final option is to use Geo IP to try and figure out where in the world the user might be, and what language is spoken there. This is a tough one though since the official language in a country might not be the one preferably used by the end user.


As long as the user can easily change language and isn't bound to any of the above presets there shouldn't be any problem.

.. and please; try to keep track of what language a user has been using before so that he or she doesn't have to change language every time he/she visits your site.



来源:https://stackoverflow.com/questions/8582405/whats-best-method-to-detect-language

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