through the last couple of years the web got more and more dynamic, nowadays websites and web based applications often provide a quite "rich" user interface. today it's quite easy to improve the gui of the own application/website by using one of the popular javascript frameworks. those frameworks ease the dynamic modification of the dom model, the usage of "dhtml"-features and the integration of ajax based features.
the following article gives a good overview of the most important js-frameworks:
http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks
Given Chickenfoot as a JavaScript based Web Data Extraction tool, one can use JavaScript methods in the Chickenfoot script as well. For the given problem with the method find() it is useful to use the native JavaScript method document.evaluate() instead for retrieving data and going through the DOM tree.
My basic idea on this problem was, to make a similar handling than it is done for multilanguage on serverside. So basically what we need is a file which contains the translations for constants which should be accessible for javascript.
I then created following JavaScript file named "translation.js", which contains the constants for the specific languages and a function which will retrieve them and return a translated String for the constant.
var ML_en_US = [];
ML_en_US['SPACE_PROVIDING']= 'Space providing';
ML_en_US['DEFENSE_STRENGTH']= 'Shieldstrength';
ML_en_US['RESS_STORAGE']= 'Ressource-Storage';
ML_en_US['RESSOURCE']= 'Ressource';
var ML_de_DE = [];
ML_de_DE['SPACE_PROVIDING']= 'Platz';
ML_de_DE['DEFENSE_STRENGTH']= 'Verteidigungsstärke';
ML_de_DE['RESS_STORAGE']= 'Rohstoffkap.';
ML_de_DE['RESSOURCE']= 'Rohstoff';
function ML(tag, language){
try {
var result = eval('ML_' + language + '["' + tag + '"]');
if (result == undefined) return "e:"+tag;return result;}
catch (err) {
return "e:"+tag
}
}
Now arrays can be defined, which have the respective language code in their variable name, and the index is the constant used for translation. By an "eval" command the script looks for the translated version. If there is no translation available the script will catch the error and put "e:" in front of the constant and return that, so it is clearly visible to the designer, that there is no translation available for the constant at the moment.