Multiple language site and 404 page

Hi!

I’m already finishing my portfolio and I want to have it in two languages: spanish and english. I already have all the texts for both languages and I’ve thought to copy all the pages from spanish and change the texts to english. Then, add all this pages into an english folder called /en.

Is this a good practice?

Another problem I have, is with the 404 error page. Since my website has two languages, I need two 404 error pages. One working for the regular URL which is in spanish (www.mywebsite.com/aksdaskd) and one working for the english version (www.mywebsite.com/en/aksdaskd). So my question is: How can I achieve this?

Thank you,
Jonathan

It should be possible to detect the URL of the current request and show the respective language div in the 404 page.

1 Like

Really nice idea Sam, I had not fallen in that.

If someone is interested in the code I have used to achieve this, here it is:

<script>
        var win = window.location;

        var webPath = win.pathname;

//Add the var for each one of the language divs

        var x = document.getElementById("404-spanish");

        var y = document.getElementById("404-english");


//Divide the url in segments with the "/" character

        var splittedPath = webPath.split("/");

//As the main link structure would be: jonathancenteno.com/en we need to select the first part of the url. In this case the parameter is 1. 

        switch(splittedPath[1]) {

 //For the english language we display the english div and hide the spanish one

          case "en": 
            x.style.display = "none";
            y.style.display = "block";
            break;

//Since the default version of my website is in spanish, I haven't added any more values. But, if you have more languages, you can add more values as the "en" one.

          default:
           y.style.display = "none";
          break;
        }
        </script>

Hope this can help anyone else. :slight_smile:

And thanks for your help once again @samliew :slight_smile:

3 Likes

Hi Jonatan

I know this thread is a bit old but hope you are still there to help me :slight_smile:
Do know anything about code…

What classes should I give my two 404 language div’s?
And/or where should I add the “var x” and “var y”?

Have I completely misunderstood it?

Thanks in advance…

it works, awesome!! thank you~