New Landing How can we help? Themeforest Theme Support Dante Polylang plugin integration

Viewing 5 posts - 1 through 5 (of 5 total)
  • Posted in: Dante
  • #138841
    bozomax
    Member
    Post count: 16

    Hi!

    This is not a request for help, but I thought I’d rather share my experience in integrating Polylang langauge plugin with Dante.

    I have already posted a request for small modification in the source code of the parent theme here: …/dante-feature-request/page/21/#post-138835

    In order to make this work, I used child theme’s functions.php and have overriden the original sf_language_flags() function (I had to change the function’s definition to conditional in the parent theme).

    So below is my code for the new sf_language_flags(), which also incorporates the original code:

    if (!function_exists('sf_language_flags')){	
    	function sf_language_flags() {
    		$language_output = "";
    		if (function_exists('pll_the_languages')){
    			$languages = pll_the_languages(array('raw'=>1));
    			if(!empty($languages)){
    				foreach($languages as $l){
    		            $language_output .= '<li>';
    		            if($l['flag']){
    		                if(!$l['current_lang']) {
    		                	$language_output .= '<a href="'.$l['url'].'"><img src="'.$l['flag'].'" height="12" alt="'.$l['slug'].'" width="18" /><span class="language name">'.$l['name'].'</span></a>'."\n";
    		                } else {
    		                	$language_output .= '<div class="current-language"><img src="'.$l['flag'].'" height="12" alt="'.$l['slug'].'" width="18" /><span class="language name">'.$l['name'].'</span></div>'."\n";
    		                }
    		            }
    		            $language_output .= '</li>';
    		         }   
    			}
    		} elseif (function_exists('icl_get_languages')) {
    		    $languages = icl_get_languages('skip_missing=0&orderby=code');
    		    if(!empty($languages)){
    		        foreach($languages as $l){
    		            $language_output .= '<li>';
    		            if($l['country_flag_url']){
    		                if(!$l['active']) {
    		                	$language_output .= '<a href="'.$l['url'].'"><img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" /><span class="language name">'.$l['translated_name'].'</span></a>'."\n";
    		                } else {
    		                	$language_output .= '<div class="current-language"><img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" /><span class="language name">'.$l['translated_name'].'</span></div>'."\n";
    		                }
    		            }
    		            $language_output .= '</li>';
    		        }
    		    }
    	    } else {
    	    	$flags_url = get_template_directory_uri() . '/images/flags';
    	    	$language_output .= '<li><a href="#">DEMO - EXAMPLE PURPOSES</a></li><li><a href="#"><span class="language name">German</span></a></li><li><div class="current-language"><span class="language name">English</span></div></li><li><a href="#"><span class="language name">Spanish</span></a></li><li><a href="#"><span class="language name">French</span></a></li>'."\n";
            }
    	   return $language_output;
    	}
    }

    Note the order, I noticed that somehow (how?!) when I installed Polylang, it still could call the WPML’s function icl_get_languages and even get some data out of it! Such as urls and flag images…

    I hope you will find this helpful.

    #138966
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    Thanks for your contribution.
    Will forward it to the development team.

    -Rui

    #139193
    Swift Ideas – Ed
    Keymaster
    Post count: 15264

    Thanks for the code! Will include that for the next update.

    – Ed

    #139339
    bozomax
    Member
    Post count: 16

    Hi! Thanks for the feedback. I just wanted to mention, that this thing only works for the normal menu, I didn’t change anything in the mobile menu, since, as I mentioned earlier, existing code is able to get the flags and links from the Polylang somehow…

    #139349
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Ok thanks

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register