Changeset 8435


Ignore:
Timestamp:
01/02/11 00:29:40 (9 years ago)
Author:
rub
Message:

Fix language set/detect on Facebook connect

Location:
extensions/FacebookPlug/Plugin
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/FacebookPlug/Plugin/include/header.inc.php

    r8425 r8435  
    2424} 
    2525 
     26function fbp_get_fb_language() 
     27{ 
     28  global $user; 
     29 
     30  // Array compute by plugins/FacebookPlug/tools/check_language.php script 
     31  $valid_fb_languages = array ( 0 => 'ca_ES', 1 => 'cs_CZ', 2 => 'da_DK', 3 => 'de_DE', 4 => 'es_ES', 5 => 'fa_IR', 6 => 'fr_CA', 7 => 'fr_FR', 8 => 'he_IL', 9 => 'hr_HR', 10 => 'hu_HU', 11 => 'it_IT', 12 => 'ja_JP', 13 => 'ka_GE', 14 => 'lv_LV', 15 => 'mk_MK', 16 => 'nl_NL', 17 => 'pl_PL', 18 => 'pt_BR', 19 => 'pt_PT', 20 => 'ro_RO', 21 => 'ru_RU', 22 => 'sk_SK', 23 => 'sr_RS', 24 => 'sv_SE', 25 => 'tr_TR', 26 => 'vi_VN', 27 => 'zh_CN', ); 
     32 
     33  // User language 
     34  $language = $user['language']; 
     35  if (! in_array($language, $valid_fb_languages)) 
     36  { 
     37    $code_lang = substr($language, 0, 2); 
     38    // Compose a language 
     39    $language = $code_lang.'_'.strtoupper($code_lang); 
     40    if (! in_array($language, $valid_fb_languages)) 
     41    { 
     42      // Search a language 
     43      foreach ($valid_fb_languages as $valid_fb_language) 
     44      { 
     45        if ($code_lang == substr($valid_fb_language, 0, 2)) 
     46        { 
     47          return $valid_fb_language; 
     48        } 
     49      } 
     50      // default language 
     51      $language = 'en_US'; 
     52    } 
     53  } 
     54 
     55  return $language; 
     56} 
     57 
    2658function fbp_header($content, &$smarty) 
    2759{ 
     
    4981    $template->assign('FACEBOOK_APP_ID', (is_numeric($conf['fbp']['facebook_app_id']) ? $conf['fbp']['facebook_app_id'] : FACEBOOK_APP_ID)); 
    5082    // define language 
    51     $template->assign('LANGUAGE', $user['language']); 
     83    $template->assign('FACEBOOK_LANGUAGE', fbp_get_fb_language()); 
    5284    $template->assign('fbp', $conf['fbp']); 
    5385    //~ $template->smarty->register_modifier('boolean_to_string', 'boolean_to_string'); 
  • extensions/FacebookPlug/Plugin/tpl/init.fb.tpl

    r8402 r8435  
    3838  (function() {ldelim} 
    3939    var e = document.createElement(script); 
    40     e.src = document.location.protocol + //connect.facebook.net/{$LANGUAGE}/all.js#appId={$FACEBOOK_APP_ID}&xfbml=1; 
     40    e.src = document.location.protocol + //connect.facebook.net/{$FACEBOOK_LANGUAGE}/all.js#appId={$FACEBOOK_APP_ID}&xfbml=1; 
    4141    e.async = true; 
    4242    document.getElementById(fb-root).appendChild(e); 
     
    4545{else} 
    4646<div id="fb-root"></div> 
    47 <script src="http://connect.facebook.net/{$LANGUAGE}/all.js#appId={$FACEBOOK_APP_ID}&amp;xfbml=1"></script> 
     47<script src="http://connect.facebook.net/{$FACEBOOK_LANGUAGE}/all.js#appId={$FACEBOOK_APP_ID}&amp;xfbml=1"></script> 
    4848<script> 
    4949  FB.init({ldelim} 
Note: See TracChangeset for help on using the changeset viewer.