• CrackInfoTante

    (@crackinfotante)


    Hi,

    great Plugin!!
    I’ve following question: I try to create an if/else php statement through the plugin “easy code placement”. I put some content in the header through this “code placement plugin” and it’s not translated automatically when I click on the language switch button.
    That’s why I want to write an if/else code in order to translate this header part.
    I tried following solutions to add into the code placement plugin:

    <?php
    global $sublanguage;
    $name = echo $sublanguage->current_language->post_name;
    if($name == 'en'){
    
           print "english text";
        }
          print "german text";
    } ?> 

    OR

    
    <?php
    $Id = echo get_permalink($post->ID);
        if ($Id == 'eng') {
    
            return 'english text';
        }
        return 'german text';
    
    } ?> 

    OR

    <?php
    function my_custom_translation($original_text, $current_language, $optional_arg) {
    
        if ($current_language->post_name == 'eng') {
    
            return 'english test';
        }
        return $original_text;
    
    } ?>

    Unfortunately nothing works – what do I wrong? I tried to follow the FAQ supports…

    I would be very very greatful if someone could help me.

    Thank you!!

Viewing 1 replies (of 1 total)
  • maxime

    (@max345)

    Hello,

    I think you’re almost there:

    #1:

    
    <?php
    global $sublanguage;
    $name = $sublanguage->current_language->post_name;
    if($name == 'en'){
    
           print "english text";
        }
          print "german text";
    } ?> 
    

    #3:

    
    <?php
    function my_custom_translation($original_text, $current_language) {
    
        if ($current_language->post_name == 'eng') {
    
            return 'english test';
        }
        return $original_text;
    
    } 
    
    echo apply_filters('sublanguage_custom_translate', 'text to translate', 'my_custom_translation');
    
    ?>
    

    Forget about the #2. I think the #3 is better, even if it looks a bit more complex, because it will still work if you uninstall Sublanguage. The solution #1 will crash as soon as you remove sublanguage.

Viewing 1 replies (of 1 total)
  • The topic ‘Translating header part with code placement plugin’ is closed to new replies.