shemona Posted August 14, 2023 Share Posted August 14, 2023 I am trying to make a site for both German and English readers, but don't have the budget to pay for a translation extension. So, we are thinking about doing each page in German and English, and based on the user's language preferences set in the browser, direct to the corresponding page. For this logic, I put the following in my Header section of the code injection: <script> const userLanguage = window.navigator.language.slice(0, 2); const requested = window.location.pathname; if(userLanguage !== 'de') { location.href = `https://effektiver-altruismus-germany.squarespace.com/en/${requested}`; } else { location.href = `https://effektiver-altruismus-germany.squarespace.com/${requested}`; } </script> But when I do this, the site glitches and keeps refreshing over and over again while adding 'en' to the url upon every refresh. Does anyone know what's happening? Link to comment
creedon Posted August 14, 2023 Share Posted August 14, 2023 I suggest a different technique. Please see Brad Good's How to setup multi-language content on any Squarespace Template? Let us know how it goes. Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects. Link to comment
shemona Posted August 20, 2023 Author Share Posted August 20, 2023 Thank you! This worked for the switcher part, but loading the correct text in the navigation and footer seems to be another slightly more complicated problem. Link to comment
creedon Posted August 20, 2023 Share Posted August 20, 2023 I don't have any specific solutions just some general comments. For the footer. If you are on v7.1 you make two sections, in the footer, and then you add code to the appropriate section of Brad's code to hide/show the sections based on the language. For the header. I assume you must mean there are elements in the header that aren't being translated? I assume the navigation elements are. That is the point of Brad's code. For the header you use the same method of tying into Brad's code to hide/show elements based on language. Use of Brad's code is common. Some of these particular issues may have been touched on in this forum. I have no specific pointers. Try the forum search function. Try search terms like brad, good, language, switcher, and etc. Let us know how it goes. Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects. 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