Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching language Wordpress with language button in navigation

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

like image 757
Peter Avatar asked Nov 27 '25 04:11

Peter


2 Answers

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:

   var lang = document.documentElement.lang;
 if (lang == 'en-US'){
    $('button').html('your button text')
 }
like image 70
James Avatar answered Nov 28 '25 16:11

James


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.

like image 36
sirBlond Avatar answered Nov 28 '25 16:11

sirBlond