Zenocavallari Posted June 7, 2023 Posted June 7, 2023 Site url: http://cantinalepietre.com Hi guys, I've recently installed a language switch on my website, all the page are set into /en or /it for English or Italian, and the language switch operates on that. The only thing is that the langue switch redirects every time its pressed to the home page, ex: I'm navigating the "contact" page, I press the switch and I get redirected on the home page. Is there a way to make the switch operate in every singe page? thank
tuanphan Posted June 11, 2023 Posted June 11, 2023 Hi, How did you add language switch feature? Zenocavallari 1 Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)
Zenocavallari Posted June 14, 2023 Author Posted June 14, 2023 On 6/11/2023 at 8:58 AM, tuanphan said: Hi, How did you add language switch feature? hi, this is the code I used: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(function() { /* SETUP MULTI-LANGUAGE */ var defaultLanguage = 'en'; var lang = location.pathname.split("/")[1]; var defaultClass = 'lang-'+defaultLanguage+''; var itemParent = "nav [class*='collection'],nav [class*='folder'],nav [class*='index'],nav [class*='group']"; if (lang == "" || lang.length > 2 ){ var lang = defaultLanguage; } /* ADD LANGUAGE CLASSES */ $('a[href="/"]').addClass('lang-'+defaultLanguage+'').parents(itemParent).addClass('lang-'+defaultLanguage+''); $('nav a:link:not([href^="http://"]):not([href^="https://"])').each(function () { var langType = $(this).attr('href').split("/")[1]; var multiLanguageClass = 'multilanguage lang-' + langType + ''; if (undefined !== langType && langType.length <= 2) $(this).addClass(multiLanguageClass).parents(itemParent).addClass(multiLanguageClass); }); $('nav button').each(function () { var langTypeFolder = $(this).attr('data-controller-folder-toggle').split("/")[0]; var multiLanguageClass = 'multilanguage lang-' + langTypeFolder + ''; if (undefined !== langTypeFolder && langTypeFolder.length <= 2) $(this).addClass(multiLanguageClass); }); /* HOMEPAGE-LOGO LINKS TO PROPER LANGUAGE HOMEPAGE */ if (lang == "it") { $('a[href="/"]').attr("href", "/it/home/"); } /* ADD EXCLUSION NAV ITEMS */ $('.exclude-me,.exclude-me a').addClass('exclude'); $('.sqs-svg-icon--list a,.SocialLinks-link').addClass('exclude'); /* REMOVE OTHER LANGUAGES AND KEEP EXCLUDED ITEMS */ $('.multilanguage:not(".lang-'+lang+',.exclude")').remove(); }); </script>
tuanphan Posted June 16, 2023 Posted June 16, 2023 On 6/14/2023 at 7:32 PM, Zenocavallari said: hi, this is the code I used: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(function() { /* SETUP MULTI-LANGUAGE */ var defaultLanguage = 'en'; var lang = location.pathname.split("/")[1]; var defaultClass = 'lang-'+defaultLanguage+''; var itemParent = "nav [class*='collection'],nav [class*='folder'],nav [class*='index'],nav [class*='group']"; if (lang == "" || lang.length > 2 ){ var lang = defaultLanguage; } /* ADD LANGUAGE CLASSES */ $('a[href="/"]').addClass('lang-'+defaultLanguage+'').parents(itemParent).addClass('lang-'+defaultLanguage+''); $('nav a:link:not([href^="http://"]):not([href^="https://"])').each(function () { var langType = $(this).attr('href').split("/")[1]; var multiLanguageClass = 'multilanguage lang-' + langType + ''; if (undefined !== langType && langType.length <= 2) $(this).addClass(multiLanguageClass).parents(itemParent).addClass(multiLanguageClass); }); $('nav button').each(function () { var langTypeFolder = $(this).attr('data-controller-folder-toggle').split("/")[0]; var multiLanguageClass = 'multilanguage lang-' + langTypeFolder + ''; if (undefined !== langTypeFolder && langTypeFolder.length <= 2) $(this).addClass(multiLanguageClass); }); /* HOMEPAGE-LOGO LINKS TO PROPER LANGUAGE HOMEPAGE */ if (lang == "it") { $('a[href="/"]').attr("href", "/it/home/"); } /* ADD EXCLUSION NAV ITEMS */ $('.exclude-me,.exclude-me a').addClass('exclude'); $('.sqs-svg-icon--list a,.SocialLinks-link').addClass('exclude'); /* REMOVE OTHER LANGUAGES AND KEEP EXCLUDED ITEMS */ $('.multilanguage:not(".lang-'+lang+',.exclude")').remove(); }); </script> Step 6 - Related Articles https://www.bradgood.net/articles/multi-language-content-on-any-squarespace-template Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)
Zenocavallari Posted June 20, 2023 Author Posted June 20, 2023 On 6/16/2023 at 11:54 AM, tuanphan said: Step 6 - Related Articles https://www.bradgood.net/articles/multi-language-content-on-any-squarespace-template Thanks! Will try that asap and let you know!
Zenocavallari Posted June 23, 2023 Author Posted June 23, 2023 On 6/16/2023 at 11:54 AM, tuanphan said: Step 6 - Related Articles https://www.bradgood.net/articles/multi-language-content-on-any-squarespace-template Tried that solution, the only thing is that I didn’t used an htlm switch, but two simple pages that are link to the en/home and it/home. Is there a way to set it this way? thanks
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment