$(document).ready(function() { // Initially hide the navigation bar until everything is loaded $('nav').css('visibility', 'hidden'); }); $(window).on('load', function() { // Correctly position and display navigation items based on language processNavigation(); // Reveal the navigation bar after all styles are applied $('nav').css('visibility', 'visible'); }); function processNavigation() { var defaultLanguage = 'en'; // Set the default language var path = window.location.pathname.split('/')[1]; // Extract language from URL var language = (path && path.length == 2) ? path : defaultLanguage; $('nav a').each(function () { var link = $(this); var href = link.attr('href'); var langCode = href.split('/')[1]; // Assumes language code is the first path segment if (langCode != language) { link.hide(); // Hide non-matching language links } else { link.show(); // Show matching language links } }); }