How to change language in the website using javascript

Viewed 141

I am beginner in JavaScript and bootstrap, i have added the navbar but i want to change the navbar titles language (Home,About us,Our Service,Contact us) by clicking the button at the top of navbar. Below is the bootstrap code.

<button type="button" class="btn btn-primary">Spanish</button>

    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <img src="images/logo.png" width="60" height="55" class="d-inline-block align-top" alt="" loading="lazy">
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav ml-auto text-center">
                <li class="nav-item active">
                    <a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="aboutus.html">About Us</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="ourservices.html">Our Services</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="contactus.html">Contact Us</a>
                </li>
            </ul>
            <a class="btn btn-outline-primary" id="fire" href="http://eatxact.com/#">Login</a>
        </div> </nav>

1 Answers

You can create locale for some language, like 'en' or 'uk' and add it to the url of the website and simply redirect to the correct localizated page by clicking on the button.

But it would reload the page. If you want not to do it, Siddharth S.`s answer is the best choice

Related