I'm looking for a part-time remote job.

Hire me


I'm the author of:

Mastering Redmine is a comprehensive guide with tips, tricks and best practices, and an easy-to-learn structure.

Check the book's project or

Buy the book

Social pages of the book:

By buying this book you also donate to Redmine (see this page).


Follow me:

The Language Mix plugin for WordPress

The Language Mix plugin for WordPress is a kind of assistant for the Polylang plugin of Chouby. As you might know, the Polylang is one of the best plugins, that implement support of multiple languages in WordPress. Thus, using this plugin you can create translations of your blog, which will be available under special URL paths like /en for English. Each such translation will show only articles written in the appropriate language. Additionally, Polylang supports the concept of the default language, which is assumed when no special path is used. The Language Mix plugin is aimed to extend this concept...

In the case, when you don’t have all you articles translated into all other supported languages, you may want to show some articles untranslated, when you are sure, that the visitor can read the appropriate language. That’s what the Language Mix plugin changes! Certainly, this can be done, only when no language is specified explicitly – i.e., only for the default language view. This way your blog can still provide one-language-only areas.

User languages configuration

As a webmaster and a WordPress administrator you don’t have to care, contents in which languages a user wants to see – the Language Mix plugin takes care of this by itself, it’s between the plugin and the user! Anyway, to get the idea, how does the plugin do this check this page (well, it worth checking it anyway). Yet still you can help users by allowing them to tweak language settings through a widget on your blog...

The Languages widget

To determine, which languages the user can read the plugin inspects the Accept-Language HTTP header (check more details here). But before this it checks the special pllx_languages cookie. I.e., if this cookie is available, its content has a higher priority than the content of the Accept-Language header! This way you can let your users configure, which languages they want to see. That’s what the Languages widget allows to do!

You can find this widget in Appearance → Widgets:

The Languages widget (back-end)

As it’s seen the widget supports only the “Title” option.

On the front-end the widget gets rendered as follows:

The Languages widget (front-end)

You can also see it live, e.g., here.

Its behavior is simple: Users just check, contents in which languages they want to see, and click “Apply”. The specified settings get saved into cookies of the user’s browser.

The widget does not allow to uncheck all languages! In such cases and on the first load the widget takes languages settings from the Accept-Language HTTP header.
It’s recommended to put this widget on index (archive) pages.

The Translations widget

The Polylang plugin comes with the Language Switcher widget, that lets you switch the language on any page. After selecting the language you get redirected either to the translation of the current page or to the index page of the language... There is no way to hide a language on this widget, if the appropriate translation is not available! To fix this the Language Mix comes with the Translations widget.

This widget (along with many others, actually) can be found in Appearance → Widgets:

The Translations widget (back-end)

Like the Languages widget this one has only the “Title” option.

On the front-end the widget looks like:

The Translations widget (front-end)

You can also check the widget live here.

If no translations are available for the content, the widget is not shown!

Install

  • Start from installing the Polylang plugin (check these instructions on how to do this).
    Of course, if you don’t have the Polylang plugin installed yet...
  • Copy the language-mix directory to the wp-content/plugins directory of your WordPress installation.
  • Activate the Language Mix plugin using the Plugins menu in WordPress.
  • Optionally (but recommended) put the Languages widget on index pages using Appearance → Widgets.
  • Optionally (but recommended) put the Translations widget on single post pages.

screenshot-1.png View - The Languages widget (front-end) (9.5 KB) Andriy Lesyuk, 14 Jan 2014 23:34

screenshot-2.png View - The Translations widget (front-end) (4.47 KB) Andriy Lesyuk, 14 Jan 2014 23:34

Languages.png View - The Languages widget (back-end) (5.35 KB) Andriy Lesyuk, 14 Jan 2014 23:44

Translations.png View - The Translations widget (back-end) (5.48 KB) Andriy Lesyuk, 14 Jan 2014 23:44

Terms of use | Privacy policy