I have created a WordPress theme that needs to be in German and English. In the navigation I have a button which should change the language depending on what language they are currently using. (If they are viewing the english page it should display “Deutsch” and vice versa.)
I’m using qTranslate Plus and have chosen to display the language code in the url (/de or /en). My main problem lies when I’m on a custom page (WordPress page with a template) (/custom-page) and change the language it doesn’t change to german although in the source code the link displays /de/custom-page. It completely ignores the language code and takes me to /custom-page again. So it seems to be stripping the language code out.
Is this standard WordPress behaviour and if so, how can I disable it?
Also is there a better, more reliable way to change the language? Would storing the language in a session work?
Note: Both “Hide untranslated content” and “Hide URL language information for default language.” are unchecked.
Thanks in advance,
Peter
I had a similar issue on a site I was working on. I installed this extension which seemed to resolve some issues with URLs
https://wordpress.org/plugins/qtranslate-slug/
alternatively, you could target the button with javascript/jQuery using conditional statements to detect the html lang attr. Something like this:
qTranslate is not supported well. If you just started implementing it I think you should give other plugins a shot. Here are few replacements for qTranslate:
mqTranslate and zTranslate. Both are qTranslate forks so you shouldn’t loose anything.
As for your question you can simply hide current language with css using lang selector:
:lang(current languagecode) {
display: none;
/*the other way to hide things*/
text-indent: 9999px;
overflow: hidden;
}
Hope this helps.
Best Regards.
I noticed on 2 of my wordpress installations (3.8.1 updated to 4.0), that mqtranslate (same code) does not translate the content when using url-based routing, similar to your problem.
i installed “qtranslate plus” just now on a fresh wp 4.0 and it worked as expected with url-based routing (But seems to mess up the date format in the post header).
So i think the problem could be the version number not working well together with qtranslate.
maybe the preg_match-code in ppqtranslate_core.php line 173 does not give the right result.
workaround:
i stopped digging at this point and switched to domain-based routing (en.site.com for english and site.com for german). this workes flawlessly. if you can do it, just try. you need to
Add to httpd.conf:
and restart webserver with
after this domain-based translation should work.