Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1.     function look_up_language() {
  2.  
  3.  
  4.         // Language recognition (STELLA_CURRENT_LANG) for multisite should be in sunrise.php
  5.         if( is_multisite() )
  6.             return;
  7.  
  8.         $use_lang = $this->langs['default']['prefix'];
  9.  
  10.         // Language recognition in rewrite_url function. only for subfolder situation
  11.         if( $this->is_subfolder() && is_permalinks_enabled() ){
  12.             $this->set_current_language($use_lang);
  13.             return;
  14.         }
  15.  
  16.         if ( $this->use_hosts  ):
  17.             foreach ( $this->langs['others'] as $prefix => $lang ) {
  18.                 if ( $_SERVER['HTTP_HOST'] == $lang['host'] || $_SERVER['HTTP_HOST'] == 'www.' . $lang['host'] ) {
  19.                     $use_lang = $lang['prefix'];
  20.                     break;
  21.                 }
  22.             }
  23.         elseif ( ! is_permalinks_enabled() ) :
  24.             // Non-permalinks variant.
  25.             if ( isset($_GET['lang']) ) :
  26.                 foreach ( $this->langs['others'] as $prefix => $lang ) {
  27.                     if ( $_GET['lang'] == $lang['prefix'] ) {
  28.                         $use_lang = $lang['prefix'];
  29.  
  30.                         break;
  31.                     }
  32.                 }
  33.             endif;
  34.         else: // Permalinks no-hosts variant.
  35.             if( ! $this->is_subfolder() ){ //wp is not in subfolder
  36.                 $uri = $_SERVER['REQUEST_URI'];
  37.                 $code = substr( $uri, 0, 4 );
  38.                 if ( '/' != substr( $code, -1 ) )
  39.                     $code = $code . '/';
  40.  
  41.                 foreach ( $this->langs['others'] as $prefix => $lang ) {
  42.                     if ( ! ( false === strpos( $code, '/' . $lang['prefix'] . '/' ) ) ) {
  43.                         $use_lang = $lang['prefix'];
  44.                         break;
  45.                     }
  46.                 }
  47.             }
  48.  
  49.         endif;
  50.  
  51.         $this->set_current_language($use_lang);
  52.     }
  53.  
  54.     /**
  55.      * Sets the current language
  56.      * and also the locale
  57.      * @param string $lang current language
  58.      */
  59.     private function set_current_language($lang){
  60.  
  61.         if( ! defined( 'STELLA_CURRENT_LANG' ) ) {
  62.             define('STELLA_CURRENT_LANG', $lang);
  63.         }
  64.  
  65.  
  66.  
  67.         add_filter('locale', array(&$this,'stella_setlocale'), 10);
  68.  
  69.     }
  70.  
  71.     /**
  72.      * locale hook when load_theme_textdomain is present in functions.php
  73.      *
  74.      *
  75.      * called by locale hook
  76.      */
  77.     public function stella_setlocale( $locale ) {
  78.         //for now we have these
  79.         $locales = array(
  80.             'en' => 'en_US',
  81.             'fr' => 'fr_FR',
  82.             'zh' => 'zh_CN'
  83.         );
  84.  
  85.         return $locales[STELLA_CURRENT_LANG];
  86.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement