Hi,
you can use the function
CMLLanguage::get_current_slug();
to retrieve current language, and print a string in according to current one.
Otherwise you can use this function:
cml_shortcode_text( array(
'fi' => '<div class='slogan'>
<p class="slogan_main">Puhallus</p>
<p class="slogan_sub">- tehokasta ja hellävaraista</p></div>;,
'en' => 'Your text in english'
)
);
The plugin will chose which one display in according to current language
Hello,
sorry, but it doesn’t work. I forgot to mention that the theme requires this kind of function when adding a new header element. I don’t know if I got it right because I am no php hero 🙂
This is what it looks like now when only the language switcher works ok:
function ava_extra_header_element() { ?>
cml_shortcode_text( array(
‘sv’ => ‘<div class=’slogan’>
<p class=”slogan_main”>Blästring</p>
<p class=”slogan_sub”>- effektivt och skonsamt</p></div>;,
‘fi’ => ‘<div class=’slogan’>
<p class=”slogan_main”>Puhallus</p>
<p class=”slogan_sub”>- tehokasta ja hellävaraista</p></div>;,
)
);
<div class=’language_switch’>
<?php
cml_show_flags( “cml_language”, CMLLanguage::get_current_id(), false, false );
?></div>
<?php }
Should the function come within the slogan div class? Then it would be similar to the language switch.
Br, Rainer
Hello again,
could you please give an example of how I could use the function:
CMLLanguage::get_current_slug();
How to write/order the parameters. Sorry, but I’m no coding pro…
Hi,
This shortcode function comes halfway… it shows the Swedish, but only the Swedish, not the Finnish. When switching to Finnish the Swedish text is still shown.
function ava_cml_shortcode_text(){ ?>
<div class=’slogan’><?php echo “<p class=’slogan_main’>”.do_shortcode(‘[cml_translate string=”Blastring” in=”fi”]’).”</p>”;
echo “<p class=’slogan_sub’>”.do_shortcode(‘[cml_translate string=”Effektivt” in=”fi”]’).”</p>”; ?></div>
<?php}
Any idea/solution for this one?
Hi,
this is an example:
function ava_cml_shortcode_text(){ ?>
<div class='slogan'><?php echo "<p class='slogan_main'>".( CMLLanguage::get_current_slug() == "sv" ) ? "Blastring" : "Finnish text here" . </p>";
echo "<p class='slogan_sub'>".( CMLLanguage::get_current_slug() == "sv" ) ? "Blastring" : "Finnish text here" ."</p>"; ?></div>
<?php}
change
Hi,
Well, this did not work either. When I used the example it only shows the word Blastring two times and without any p-class styling, just plain text, regardless of switching languages. It seems to me that the template/theme does not recognize the language slugs or does not know what to do. This is strange because everything else works fine with the translated versions.
Is there a way to “register” the cml language slugs so that the theme recognizes them?
What should I do? My client is asking me what is taking so long and I feel a bit of pressure building up…
If you have solutions, please help.
Heureka!
I finally managed to get it to work. So for anyone using the Enfold theme here is what worked for me. To insert in the functions.php and modify according to your own language slugs and divs and css styles:
// Adds extra element to the header
add_action(‘ava_main_header’, ‘ava_cml_shortcode_text’);
function ava_cml_shortcode_text(){
if(CMLLanguage::get_current_slug() == “sv”){
?>
<div class=’slogan’>
<p class=”slogan_main”>Your own text</p>
<p class=”slogan_sub”>Your own subtext</p>
</div><?php
}elseif(CMLLanguage::get_current_slug() == “fi”){
?>
<div class=’slogan’>
<p class=”slogan_main”>Your own text</p>
<p class=”slogan_sub”>Your own subtext</p>
</div><?php
}
}