Jump to content

URL mapping for switcher of multilanguage site

Go to solution Solved by creedon,

Recommended Posts

Posted

Heyhey,

I set up a multilingual site with the Brad Good method. Worked all well but when I tried to implement his code for URL mapping of the language switcher (i.e., switching language and arriving at the corresponding site in the other language), I got stuck. It just doesn't want to work and I can't figure out why. Can anybody help?

https://www.bieleit-medicus.com/

This is the code for the URL mapping:

Quote

<script>
  $(function() {
    switch (window.location.pathname) {
    case '/en/about':
      $(".language a.lang-en").attr("href", "/en/about");
      $(".language a.lang-de").attr("href", "/de/uebersicht");
      break;
    case '/de/uebersicht':
      $(".language a.lang-en").attr("href", "/en/about");
      $(".language a.lang-de").attr("href", "/de/uebersicht");
      break;
    case '/en/services':
      $(".language a.lang-en").attr("href", "/en/services");
      $(".language a.lang-de").attr("href", "/de/leistungen");
      break;
    case '/de/leistungen':
      $(".language a.lang-en").attr("href", "/en/services");
      $(".language a.lang-de").attr("href", "/de/leistungen");
      break;
    case '/en/bio-contact':
      $(".language a.lang-en").attr("href", "/en/bio-contact");
      $(".language a.lang-de").attr("href", "/de/ueber-mich-kontakt");
      break;
    case '/de/ueber-mich-kontakt':
      $(".language a.lang-en").attr("href", "/en/bio-contact");
      $(".language a.lang-de").attr("href", "/de/ueber-mich-kontakt");
      break;
                                  }
});
</script>

 

  • Solution
Posted

The issue is the code is using jQuery but you've put the code before jQuery has had a change to run, so it breaks.

Move the code after jQuery and the BG code.

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.