swissspidy/preferred-languages

Incompatibility with Polylang Pro plugin

Closed this issue · 4 comments

When I use date_i18n or get_the_date when Polylang (Pro) and the Preferred Languages plugin are in use, and the user-preferred languages are set to Deutsch (Schweiz) and fallback Deutsch (Sie), the date is always returned in the default site language. e.g. 17. Februar 2021 instead of 17. février 2021 for a Post translated to French.

Steps to reproduce the issue

  1. Install the plugins detailed above and configure the site with German and French as Polylang languages.
  2. Set the WordPress languages as Deutsch (Schweiz) and fallback Deutsch (Sie) using the Preferred Languages plugin.
  3. Load a French Post and review the date_i18n output.

Expected behavior and actual behavior

When I follow those steps, I see the date in German.
I was expecting the date in French.

See also polylang/polylang#776.

Odd that this happens, since the plugin should be bailing early if a plugin like Polylang is already filtering the current locale:

// Locale has been filtered by something else.
if ( ! in_array( $current_locale, $preferred_locales, true ) ) {
return $mofile;
}

// Locale has been filtered by something else.
if ( ! in_array( get_locale(), $preferred_locales, true ) ) {
return $translation;
}

I'll try to see whether I can reproduce this with the free version.

I am not able to reproduce this, with the free version at least.

Preferred Languages

Screenshot 2021-03-09 at 17 04 20

Polylang Languages:

Screenshot 2021-03-09 at 17 02 41

Posts (one in each language);

Screenshot 2021-03-09 at 17 03 31

Output

Output of date_i18n( 'j F Y') and get_the_date( 'j F Y') for each post:

  • French: 9 mars 2021
  • English: 9 March 2021
  • German: 9 März 2021

So everything in order there.

@markhowellsmead could you try to see if it works for your with the free version?

Closing for now as this is an unconfirmed issue.

I cannot replicate this problem in a clean install with the free version of Polylang.