
442 Data Translators
Finding bugs in your translator
If the translateMarkup() function contains certain types of errors, the translator loads
properly, but it fails without an error message when you invoke it. Although failing silently
prevents Dreamweaver from becoming unstable, it can hinder development, especially when
you need to find one small syntax error in multiple lines of code.
If your translator fails, one effective debugging method is to turn the translator into a
command, as described in the following steps:
1. Copy the entire contents of the translator file to a new document, and save it in the
Configuration/Commands folder inside the Dreamweaver application folder.
2. At the top of the document, between the SCRIPT tags, add the following function:
function commandButtons(){
return new Array( "OK","translateMarkup(dreamweaver.¬
getDocumentPath('document'), dreamweaver.getSiteRoot(), ¬
dreamweaver.getDocumentDOM().documentElement.outerHTML); ¬
window.close()", "Cancel", "window.close()");
}
3.
At the end of the translateMarkup() function, comment out the return
whateverTheReturnValueIs line, and replace it with
dreamweaver.getDocumentDOM().documentElement.outerHTML =
whateverTheReturnValueIs
, as shown in the following example:
// return theCode;
dreamweaver.getDocumentDOM().documentElement.outerHTML = ¬
theCode;
}
/* end of translateMarkup() */
4.
In the BODY of the document, add the following form with no text boxes:
<body>
<form>
Hello.
</form>
</body>
5.
Restart Dreamweaver, and select your translator command from the Commands menu.
When you click OK, the
translateMarkup() function is called, which simulates
translation.
If no error message appears and translation still fails, you probably have a logic error in
your code.
Kommentare zu diesen Handbüchern