Set Translation in functions.php Theme file
-
Hello everybody,
I’m not sure if I am in the good section of the forum, but here’s the thing: I am developping my own WP theme for a website that needs to be available in 2 languages.
I have read several pages (in the Handbook for Devs, in this forum, in the web…), but I haven’t found what I am looking for. I started with what is written in here:
https://developer.ww.wp.xz.cn/themes/functionality/internationalization/
But, let’s be honest, to set his favourite language, the users of my website won’t be changing the wp-config.php by themselves…
So far, I have been thinking of 2 ways of doing it. Let’s call them “plan A” and “plan B”.
Plan A consist of:
1) the user sets his favourite language thanks to a <select>
2) the page is directly displayed with the good translations (with a javascript function), without reloading
3) the language preference is set in a cookie so when the user comes later, his favourite language is automatically setThis is the best UX I can think of. Yet I haven’t found any documentation about that. So I’ve come to a plan B :
1) the user sets his favourite language thanks to a <select>
2) in a JS file, the preference is set in a cookie, then the page reloads automatically
3) Thanks to the cookie, a PHP function (in the functions.php file of the theme) set the favourite languageIn the best case, I’ll prefer the plan A, but the plan B is totally acceptable. What I need is, for both cases, how to “say” to WordPress “The language to be show is…”, or in another term, which JS (or PHP) function should I use (in my JS file, or functions.php respectively…)?
Thank you in advance for your help.. 🙂
The topic ‘Set Translation in functions.php Theme file’ is closed to new replies.