WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: Roych on April 28, 2016, 09:57:24 AM

Title: mod_multilingual call without flags?
Post by: Roych on April 28, 2016, 09:57:24 AM
Hello


I wan't to call the languages in my template but without the Flag images I want it to be the menu_title name. expl: EN, DE, ...
I tried
Code: [Select]
<?php if(function_exists('language_menu')){ language_menu('[menu_title]'); } ?> not working, not realy sure if it's the right place to add this [menu_title].


I always used the flags so not really sure how to achieve this ... :|


Thank you
R
Title: Re: mod_multilingual call without flags?
Post by: Gast on April 28, 2016, 06:20:34 PM
simple Solution: use a non-image-extension in the function-call like
Code: [Select]
<?php if(function_exists('language_menu')) { language_menu('txt'); } ?>it replace only the file extension from the menu code and show's the ALT-Text from the image (not W3C-valide!!)

better solution: replace the function set_language_icon() with the same name in modules / mod_multilingual / lang.functions.php

Code: [Select]
<?php  //for colored code only, dont copy this line
function set_language_icon ($pageId 0$ext='gif' )
{
    if (!
preg_match("/jpg|png|gif|svg|txt|TXT/"$ext)) $ext='gif';
    
$return_value = array();
    
$mod_path dirname(__FILE__);
    
$mod_rel str_replace($_SERVER['DOCUMENT_ROOT'],'',str_replace('\\''/'$mod_path ));
    
$mod_name basename($mod_path);

    
$array get_page_languages();
    
$array2get_pageCode_values$pageId );
    
$langPageArray array_merge($array $array2);

    foreach( 
$langPageArray as $key=>$value )
    {
        
$langKey $key;
        if(
$array[$langKey]['visibility'] == 'hidden') {continue;}
        
$page_title get_languages($langKey);
        
$langUrl get_page_url$value);
        
$class strtoupper($langKey) == LANGUAGE 'class="current"' ' class="default"';
        
$return_value $langKey ] = "\t\t".'<a '.$class.' href ="'$langUrl .'" title="'.$page_title.'" >'.PHP_EOL;
        
$return_value $langKey ] .= "\t\t\t".'<span>';
        if (
$ext=='TXT'){
            
$return_value $langKey ] .=  $page_title " ;
        } else if (
$ext=='txt'){
            
$return_value $langKey ] .=$langKey " ;
        } else {
            
$return_value $langKey ] .= PHP_EOL."\t\t\t\t".'<img src="'.WB_URL.'/modules/'.$mod_name.'/flags/'.strtolower$langKey ).'.'.$ext.'" alt="'.$page_title.'" title="'.$page_title.'" />'.PHP_EOL."\t\t\t";
        }
        
$return_value $langKey ] .= '</span>'.PHP_EOL."\t\t".'</a>'.PHP_EOL;
    }
    return 
$return_value;
}
}

now you have different way's to call the language menu

1. Extension == txt - Result is the language Key like DE EN as your menu
Code: [Select]
<?php if(function_exists('language_menu')) { language_menu('txt'); } ?>
2. Extension == TXT - Result is the page titel of the first page in every avaiable language like  Deutsch English as your menu
Code: [Select]
<?php if(function_exists('language_menu')) { language_menu('TXT'); } ?>
3. Extension == gif - Result are the flags of the first page in every avaiable language like  (https://i.gyazo.com/9b0b6b394fa79c2639a40e0f7b3e9986.png) as your menu with gif-files
Code: [Select]
<?php if(function_exists('language_menu')) { language_menu('gif'); } ?>
3. Extension == png - Result are flags of the first page in every avaiable language like  (https://i.gyazo.com/9b0b6b394fa79c2639a40e0f7b3e9986.png) as your menu, but with png-files
Code: [Select]
<?php if(function_exists('language_menu')) { language_menu('png'); } ?>
the function set_language_icon()  allowed also jpg-files and svg-files. but for this file extension, you have to add a flag-set into folder  modules / mod_multilingual / flags

P.S. Code is part of the next module version
Title: Re: mod_multilingual call without flags?
Post by: Roych on April 28, 2016, 08:52:36 PM
Wow, you are awesome, working exactly how I need it.  (Y)


Thank you very much
R