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 8873145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:23:32+00:00 2026-06-14T18:23:32+00:00

The website I’m currently working on is written into two languages (fr/en). The method

  • 0

The website I’m currently working on is written into two languages (fr/en). The method I’m using to translate the page is quite simple :

HTML

<ul id="switch">
    <li><a href="index.php?lang=en" title="English version">En</a></li>
    <li><a href="index.php?lang=fr" title="Version française">Fr</a></li>
</ul>

PHP (index.php)

<?php      
    // Translation
    if(isset($_GET['lang'])) {
        $lang = $_GET['lang'];
    }
    else {
        $lang = 'en';
    }

    switch($lang) {
        case 'en':
            $content = 'en.php';
            break;

        case 'fr':
            $content = 'fr.php';
            break;
    }

    include_once('lang/'.$content);
?>

Both en.php and fr.php contain an array filled with the actual content of the page in their respective language.

en.php (example)

<?php
    $version = array(
        'mainTitle' => 'Main title test',
        'noscript' => 'Noscript message test',
        'header' => 'Header test'
        // And so on, same thing for the french version
    );
?>

This system works fine and is sufficient for this website, but it implies a page refresh when the user switches from one language to another and that is precisely what I would like to avoid.

I guess I could work this out using a bit of AJAX (jQuery) but I am not exactly sure how to do this. Could you give me a few hint on how to implement this? I’m also open to suggestions on other possible ways of doing this – bearing in mind that it is a small scale project.

Thanks for your help.

  • 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-14T18:23:33+00:00Added an answer on June 14, 2026 at 6:23 pm

    I would suggest the following, keep your language specific stuff in a Javascript dictionary, have a Javascript method to populate data from that dictionary, have a PHP server call which returns you contents for that dictionary (basically your language-specific content) and whenever user switches to a different language, make that PHP server call to populate your Javascript dictionary and call your Javascript method to populate.

    Roughly, it would be something like this

    function js_populate_content(lang)  {
        var content-data = $.get(lang); // Ajax call to your PHP service. You will need to do some parsing here (JSON would be easiest)
        // Populate your HTML elements using data
        document.getElementById('header').innerHTML = content-data['header'];
    }
    

    You could call this method at page load or you could still load it from php at first load

    $(document).ready(function(){
        var default_lang = 'en';
        js_populate_content(default_lang);
    }
    

    You should call this method whenever user changes language e.g.

    $('a#language').on('click', function() {
        var new_lang = $('input#language').val();
        js_populate_content(new_lang);
    }
    

    Note: You should include jquery

    Note2: See jQuery get for proper syntax of $.GET

    However, this is unnecessarily complex for just language switching. Similarly, you could load the entire page in AJAX and set your body to the newly loaded page based on language. Depends on whichever is easier for you to provide as a service call (providing only language dictionary vs. providing entire page in a specific language) For the latter, see jQuery load

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

Sidebar

Related Questions

A website I've been working on will not match data using a PHP (preg_match)
Website test page: http://www.lantiis.com/indexold.html jsFiddle: http://jsfiddle.net/Guhb4/7/ I received help with the jQuery and it
My website is configured to display a custom HTML-page when an error occurs. This
Website using .NET Framework v3.5, SQL Server 2008, written in C# I have a
A website that I've been working on was originally created using XHTML 1.0 Transitional
My website at http://derek.genevievehoward.com/ will not display in Firefox, even though the HTML and
My website has been created with a CSS/HTML frame work that has been integrated
A website I am working on has to use the Facebook Connect Old JavaScript
My website allows visitors to search for homes (using PHP and MySql). After the
My website project includes taking data from the user in the form of two

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.