tags:

views:

68

answers:

2

Hello,

I want to load a php include file using jquery, ie., should reload. I have the german language loaded below

<div id="lang_files"><? include('lang-de.php'); ?></div>

Now I want to load the french language using

    $('#lang12').bind('click',function(){

        ('#lang_files').load('lang-fr.php');
 });

Thanks Jean

A: 

If you are using the id attribute on every element you need to be multi-lingual, you can use a language file with id-string pairs to replace all texts. To get this language file you could use Ajax (search a bit to get enough examples how that works).

Pseudo code to describe the step to change the language:

response = doAjaxRequest(language);
array = convertResponseToPairs(response);
for each element in array {
  e = getElementById(element.id);
  e.innerText = element.text;
}
Veger
something like a js file?
Jean
Depending on the number of elements on the page, this is possibly slower and more complex than what the OP has now: At the moment, he seems to have monolithic blocks of content. I would tend to stay with that and try to get that working. This solution is good for scenarios where word-for-word translation is needed.
Pekka
@Jean: yes, in JavaScript you have to perform the actions described in the pseudo code block. As Pekka mentioned, it might be slow to replace one element at a time.
Veger
@Pekka, If there is just one block which needs to change its language, I agree. But I was under the impression that the complete page needed the translation.
Veger
A: 

I think that if the lang-xx.php is independent from the containing page, (e.g. it uses no variables defined out of it), we can do this like so:

$('#lang12').click(function(){
    $.get("lang-fr.php",
        function(data){
            $('#lang_files').html(data);
        });
});
semigroups