Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8899809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:56:55+00:00 2026-06-15T00:56:55+00:00

I want to build a website having its content in two languages. I want

  • 0

I want to build a website having its content in two languages. I want to use jQuery for the language switching. My idea is this:

instead of having actual content in the HTML page:

<div>Hello there</div>

I want to use classes:

HTML:

<div class="hello_EN"></div>

JS(I’m not good at JS; i’ve combined it with some PHP so I can make myself understood):

var EN = new array('hello_EN' => 'Hello there');
foreach($EN as $class => $content)
$(".$class").text("$content"); //this should populate all my HTML classes with its content

Then, I must have my second language array:

var RO = new array('hello_RO' => 'Salut');

Now, the switching:

$("#change_to_RO").click(function() {
       $(EN).replaceWith(RO);
});

How should I approach this?
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:56:56+00:00Added an answer on June 15, 2026 at 12:56 am

    It’s probably best to not approach this from JavaScript. That being said, as an academic and learning exercise, here is just a crude idea of how you could go about something like this:

    <select id="lang">
        <option>English</option>
        <option>Portuguese</option>
        <option>Russian</option>
    </select>
    <span data-translate="_hello">Hello</span>, 
    <span data-translate="_january">January</span>!​
    
    // Some variables for later
    var dictionary, set_lang;
    
    // Object literal behaving as multi-dictionary
    dictionary = {
        "english": {
            "_hello": "Hello",
            "_january": "January"
        },
        "portuguese": {
            "_hello": "Oie",
            "_january": "Janeiro"
        },
        "russian": {
            "_hello": "привет",
            "_january": "январь"
        }
    };
    
    $(function () {
    
        // Lets be professional, shall we?
        "use strict";
    
        // Function for swapping dictionaries
        set_lang = function (dictionary) {
            $("[data-translate]").text(function () {
                var key = $(this).data("translate");
                if (dictionary.hasOwnProperty(key)) {
                    return dictionary[key];
                }
            });
        };
    
        // Swap languages when menu changes
        $("#lang").on("change", function () {
            var language = $(this).val().toLowerCase();
            if (dictionary.hasOwnProperty(language)) {
                set_lang(dictionary[language]);
            }
        });
    
        // Set initial language to English
        set_lang(dictionary.english);
    
    });​
    

    Fiddle: http://jsfiddle.net/MBRG4/5/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I want to build a website based on some original content, the content
I want to build a website having these things PHP5 or above Zend Framework
I want to build a website that uses Flex/Flash as the GUI, and Java
I want to build a website that respond both to normal browser request, and
I want to build a community website with videoconferencing functionality integrated. I would prefer
I want to a build a website that show the user all videos that
I have a website project that I want to build using CruiseControl.net. On one
I want build a sketch pad app on iPhone, I assume that this type
I want to build a website where i can define the location of my
I want to build a website with PHP where my users can host their

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.