I was working with language translation in phone gap. In that case I was in need of 120 labels for translation. Out of 120, 60 are English and remaining are of other language. I was inserting all values in database ones on the very first start of application, because of that it was taking much time to start for first time. After that when I was using those labels in my app, there was much delay. Means all elements on page like button, text boxes were coming first and then labels. Because of that buttons were remaining empty first and then after some time text was appearing on that.
In order to solve this problem I am using XML database for fast access. Now I created simple XML file as given below,
english_translation_test.xml
<xml>
<lbl1>Label - 1</ lbl1 >
<lbl2>Label - 2</ lbl2 >
<lbl3>Label - 3</ lbl3 >
</xml>
In this way I designed simple XML file, one for English and another for different language. I placed this file at place www => xml => english_translation_test.xml
In order to access this file I am using following code. In this code remember one thing that path must be relative to www folder. Path is in red color.
$.get('xml/english_translation_test.xml ', function(rawXml) {
getPlainXml(rawXml);
});
function getPlainXml(xml)
{
$('#label_1').html($(xml).find("lbl1").text());
$('#label_2').html($(xml).find("lbl2").text());
$('#label_3').html($(xml).find("lbl3").text());
}
Now in this case if language is different then use another language that's it. And you will get fast access to all your labels. You may need this process while code optimization and performance issues.
In order to solve this problem I am using XML database for fast access. Now I created simple XML file as given below,
english_translation_test.xml
<xml>
<lbl1>Label - 1</ lbl1 >
<lbl2>Label - 2</ lbl2 >
<lbl3>Label - 3</ lbl3 >
</xml>
In this way I designed simple XML file, one for English and another for different language. I placed this file at place www => xml => english_translation_test.xml
In order to access this file I am using following code. In this code remember one thing that path must be relative to www folder. Path is in red color.
$.get('xml/english_translation_test.xml ', function(rawXml) {
getPlainXml(rawXml);
});
function getPlainXml(xml)
{
$('#label_1').html($(xml).find("lbl1").text());
$('#label_2').html($(xml).find("lbl2").text());
$('#label_3').html($(xml).find("lbl3").text());
}
Now in this case if language is different then use another language that's it. And you will get fast access to all your labels. You may need this process while code optimization and performance issues.