To achieve a multilingual website I have the idea of using xml and jquery. One xml file for every language which acts as holder for all website labels. I have created a test xml file with the name ‘nl.xml’ :
<?xml version="1.0" encoding="UTF-8"?>
<resource>
<language name="nl">
<label id="yes">ja</label>
<label id="no">nee</label>
</language>
</resource>
I have created a html file with the following javascript :
<html>
<head>
<title></title>
<script src="jquery-1.4.4.min.js"></script>
<script type="text/javascript" language="javascript">
$(function() {
var language = 'nl';
$.ajax({
url: 'nl.xml',
success: function(xml) {
$(xml).find('label').each(function(){
var id = $(this).attr('id');
var text = $(this).find(label).text();
$("." + id).html(text);
});
}
});
});
</script>
</head>
and would like to see the values:
'div class="no">no</div>'
'div class="yes">yes</div>'
for each div which are also spread over two different files changed but need
some advice to get this done better because this current code doesnt work. The idea is that visitor downloads xml file which holds all labels for the website and webpages.
What do you mean by wanting ‘to see the values for each div which are also spread over two different files changed’? I don’t really know what you mean.
This will find every
<label id="">in your XML and convert it to a<div class="">in your document by appending it to a particular element.