New plugin: Multisite Auto Language Switcher
Published: – Leave a comment
Multisite Language Switcher is a nice plugin to add multilingualism to a WordPress website. What it lacks is an automatic switch between languages based on the locale of the user. And that’s why I’ve built Multisite Auto Language Switcher.
Multisite Auto Language Switcher checks the language(s) defined in your browser and redirects if there is a matching localized content for your desired language. And that’s basically it – as simple as possible; exactly the behavior you already know from Multisite Language Switcher.
Technical deep dive
Multisite Auto Language Switcher uses the HTTP_ACCEPT_LANGUAGE
, which is part of the $_SERVER
array, to determine the correct language. Since this is a string, which can contain multiple languages with different weight (and not necessarily sorted by that weight), Multisite Auto Language Switcher splits it into an array and sorts it descending by weight. It then checks each language for available translations of the current content. If available, it redirects.
It always redirects to the localized page with an additional URL parameter redirected-locale=1
. On the redirected page, it then adds a cookie if this URL parameter is present for the current session to not redirect again, e.g. if the user explicitly decides to change the locale themself.
What else to say?
It’s completely free and open source, of course. Get it in the WordPress plugin repository or check out the source code at GitHub. Feedback highly appreciated. ❤️