Quantcast
Channel: polylang – WordPress.org Forums
Viewing all articles
Browse latest Browse all 11471

tsachev on "Need to set facebook locale in multilingual site."

$
0
0

Hi I have a multilingual site using the Polylang plugin. I also want to use facebook's commenting system and like/send buttons. When I show content in a language I want facebook sdk to be localized using current locale.

The problem is that the facebook plugin assumes that the whole site is in a single locale and thus stores it as an option.
But this is not the case when using Polylang.
I looked at the Facebook_Loader and saw the set_locale() function.
I found that a can hook using a filter for 'transient_facebook_locale' and return the current locale decided by Polylang.
I also wanted to do the same sanitizing (just in case) as the get_locale() function does for the locale returned by get_locale().

So my question is can this code

$locale = str_replace( '-', '_', get_locale() );

// convert locales like "es" to "es_ES"
if ( strlen( $locale ) === 2 ) {
	$locale = strtolower( $locale );
	foreach( self::$locales as $facebook_locale => $exists ) {
		if ( substr_compare( $facebook_locale, $locale, 0, 2 ) === 0 ) {
			$locale = $facebook_locale;
			break;
		}
	}
}

// check to see if the locale is a valid FB one, if not, use en_US as a fallback
if ( ! isset( self::$locales[$locale] ) ) {
	$locale = 'en_US';
}

be extracted in a helper static method so I can reuse it without copy/paste?

http://wordpress.org/extend/plugins/facebook/


Viewing all articles
Browse latest Browse all 11471

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>