Need to set facebook locale in multilingual site. (3 posts)

  1. tsachev
    Posted 3 years ago #

    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;
    // 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?


  2. Niall Kennedy
    Plugin Author

    Posted 3 years ago #

    tsachev: will this pull request provide the functionality you would like to reference in your code?

  3. tsachev
    Posted 3 years ago #

    Yeah, looks exactly what I need.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Facebook
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic