Styledent Posted January 9, 2023 Share Posted January 9, 2023 I found this article: https://medium.com/@hardluckcreative/making-better-multi-language-squarespace-sites-e46d24094a7d This is my variation of the code to tailor the website between English and French. <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]; /* Set English designation if there's no language subfolder */ if (langType != 'fr') {langType = 'en'; } 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 == "/") { $('a[href="/"]').attr("href", "https://www.sgtguides.com/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> <div class=”language”><a href=/home class=”lang-en”>English</a> | <a href=/fr/home class=”lang-fr”>Français</a></div> Though, the only issue I am having still, is when I visit the websites of the different language home pages separately (It shows the navigation the way I want it.) Good! 😀👍 https://www.sgtguides.com/fr/homehttps://www.sgtguides.com/home But when I click on the English/French button on the site, the navigation still shows both versions of the navigation menus? Not good. 😪 Can anyone help with the issue? Thank you! Link to comment
Solution paul2009 Posted January 10, 2023 Solution Share Posted January 10, 2023 (edited) 19 hours ago, Styledent said: But when I click on the English/French button on the site, the navigation still shows both versions of the navigation menus? I should probably start by saying that this script was originally written by @bradgood in this article: How to setup multi-language content on any Squarespace Template. As he mentions just after step 6, as you're using a Brine-family template, you'll need to disable 'Ajax Loading' in Site Styles. Did this help? Please give feedback by clicking an icon below ⬇️ Edited January 10, 2023 by paul2009 About me: I've been a SQSP User for 18 yrs. I was invited to join the Circle when it launched in 2016. I have been a Circle Leader since 2017. I don't work for Squarespace. I value honesty, transparency, diversity and good design ♥. Work: I founded and run SF.DIGITAL, building Squarespace Extensions to supercharge your commerce website. Content: Views and opinions are my own. Links in my posts may refer to SF.DIGITAL products or may be affiliate links. Forum advice is free. You can thank me by clicking one of the feedback emojis below. Coffee is optional. Link to comment
Styledent Posted January 10, 2023 Author Share Posted January 10, 2023 21 minutes ago, paul2009 said: I should probably start by saying that this script was originally written by @bradgood in this article: How to setup multi-language content on any Squarespace Template. As he mentions just after step 6, as you're using a Brine-family template, you'll need to disable 'Ajax Loading' in Site Styles. Did this help? Please give feedback by clicking an icon below ⬇️ Thank you so much! That is exactly what I needed! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment