Site icon Hip-Hop Website Design and Development

How do I change a plugin language of only one page?

My WordPress blog is set up as nl_NL. This means that my bookly plugin is also displayed in nl_NL.

In the Plugin directory there is a folder languages with loads of other languages.

I have one page in three different languages nl_NL, de_DE, en_EN, on this page I would like the booking plugin to be displayed in the correct language.

I changed the page language via page id from nl_NL to de_DE

Via the function.php, but this had no effect.

function get_top_parent_page_id() { 
    global $post; 

    if ($post->ancestors) { 
        return end($post->ancestors); 
    } else { 
        return $post->ID; 
    } 
}

function addLangMetaTag (){
    $postLanguage = "nl_NL";
    if (is_page()) {
    $svPageID = get_top_parent_page_id(); // ID of parent page
            if ($svPageID == "13040") { // ID of the "på svenska" page
                $postLanguage = "de_DE";    
            }
        echo "<meta http-equiv="content-language" content="" . $postLanguage . "">";
    }
}
add_filter( 'wp_head', 'addLangMetaTag' );

function language_tagger_change_html_lang_tag() {
    return "dir="ltr" lang="" . 
language_tagger_determin_lang_tag() . """;
}

function language_tagger_determin_lang_tag() {
    $postLanguage = 'nl_NL'; // default language
    if (is_page()) {
    $svPageID = get_top_parent_page_id(); // ID of parent page
    if ($svPageID == "13040") { // ID of the "på svenska" page
                $postLanguage = "de_DE";    
            }
    }
    return $postLanguage;
}

add_filter('language_attributes', 
'language_tagger_change_html_lang_tag');

I think it will only look at the WordPress config.php define('WPLANG', 'nl_NL');
I have also been reading this post maybe I could combine something?