admin管理员组

文章数量:1122832

I am coming from a multi-linguo country, and viewers may speak different language.

I am writing a theme and I noticed that the language of my theme only changed based on the setting of my admin panel, which mean only logged-in user or admin can do so.

What if I wanted to do it automatically by detecting user browser preference? I am using Jquery to achieve some of this function but thinking it not the right way.

What I was doing is use jquery to set initial language by browser locale, and allow user to change it with press of a button, then save the setting to cookie.

I also tried using PHP to detect browser language, but what is the API to tell wordpress to show the correct language (e.g. screen-reader-text)? or allow a site visitor to change the language on-the-fly?

is there a "cleaner" way of doing it in wordpress using i18n on server side(while detecting browser setup and then letting viewers to change the language preference)?

I am coming from a multi-linguo country, and viewers may speak different language.

I am writing a theme and I noticed that the language of my theme only changed based on the setting of my admin panel, which mean only logged-in user or admin can do so.

What if I wanted to do it automatically by detecting user browser preference? I am using Jquery to achieve some of this function but thinking it not the right way.

What I was doing is use jquery to set initial language by browser locale, and allow user to change it with press of a button, then save the setting to cookie.

I also tried using PHP to detect browser language, but what is the API to tell wordpress to show the correct language (e.g. screen-reader-text)? or allow a site visitor to change the language on-the-fly?

is there a "cleaner" way of doing it in wordpress using i18n on server side(while detecting browser setup and then letting viewers to change the language preference)?

Share Improve this question edited Jul 13, 2018 at 11:44 adrian li asked Jul 13, 2018 at 10:33 adrian liadrian li 1431 silver badge7 bronze badges 3
  • 1 you can use a plugin like polylang which install several languages in wordpress and detect the language the first time an user comes : wordpress.org/plugins/polylang – mmm Commented Jul 13, 2018 at 10:44
  • Can I make manual translations to the menu items with this plugin? cuz I don't want some auto translate that might make weird translations. – adrian li Commented Jul 13, 2018 at 12:45
  • Pretty amazing how little attention this question has gotten - seems like a very common need. – Isaac Lubow Commented Oct 9, 2019 at 19:16
Add a comment  | 

1 Answer 1

Reset to default 0

You can get the browser language from the PHP global $_SERVER['HTTP_ACCEPT_LANGUAGE'] )

本文标签: