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
1 Answer
Reset to default 0You can get the browser language from the PHP global $_SERVER['HTTP_ACCEPT_LANGUAGE'] )
本文标签:
版权声明:本文标题:theme development - Change locale by detecting viewer's browser language setting and let them choose prefered language a 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736288586a1928124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论