Site icon Hip-Hop Website Design and Development

Multiple languages menus problem

I’m trying to add language option to my website. I’ve coded my theme and I need to show the web in three different languages. I’ve got the little flags and I’ve managed to pass a php variable with the language it’s selected. With that variable I’ve made a if for the wp_nav_menu assignment in the header.php. It works actually. When I change the language the correct menu in the correct language comes up. The problem is that when I hit in a menu item and the selected page opens the menu is gone. Disappears. Can anybody help me, plase? Here is the code I use.

In header.php

if ($language == 'en') {
   wp_nav_menu(array(
          'theme_location' => 'eng',
      'container_class' => 'main-nav', 
      'container' => 'nav'
));
} else if ($language == 'de') {
wp_nav_menu(array(
    'theme_location' => 'ger',
    'container_class' => 'main-nav', 
    'container' => 'nav'
));

} else {

wp_nav_menu(array(
    'theme_location' => 'esp',
    'container_class' => 'main-nav', 
    'container' => 'nav'
));

}

And in the functions.php

add_theme_support ('menus');
//Create Nav Menu
if (function_exists ('register_nav_menus')) {
register_nav_menus (array(
                            'esp' => 'Spanish menu',
            'eng' => 'English menu',
            'ger' => 'Deutsch menu'
    ));
}

And the html for the flag link in header.php

<li><a href="http://localhost/wordpress/inicio?language=es" ><img src="http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espflag.PNG" width="18" height="12" onmouseover="this.src='http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espH.PNG'" onmouseout="this.src='http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espflag.PNG'"></a></li>