Home / Articles / Adobe Dreamweaver / Customize Dreamweaver Using Extensions

Customize Dreamweaver Using Extensions

Chapter Description

As a Web developer, you might want to write an extension for Dreamweaver to handle a commonly used, and therefore repetitive, task. Or, you might have a unique requirement that you can satisfy only by writing an extension for the specific situation. In both cases, Dreamweaver provides an extensive set of tools that you can use to add to or to customize its functionality. This sample chapter discusses a number of ways you can extend Dreamweaver to suit your Web development needs.

Localizing an extension

Use the following techniques to make it easier to translate your extensions into local languages.

  • Separate extensions into HTML and JavaScript files. The HTML files can be replicated and localized; the JavaScript files are not localized.
  • Do not define display strings in the JavaScript files (check for alerts and UI code). Extract all localizable strings into separate XML files in the Dreamweaver Configuration/Strings folder.
  • Do not write JavaScript code in the HTML files except for required event handlers. This eliminates the need to fix a bug multiple times for multiple translations after the HTML files are replicated and translated into other languages.

XML String files

Store all strings in XML files in the Dreamweaver Configuration/Strings folder. If you install many related extension files, this lets you share all strings in a single XML file. If applicable, this also lets you refer to the same string from both C++ and JavaScript extensions.

You could create a file called myExtensionStrings.xml. The following example shows the format of the file:

<strings>

  <!-- errors for feature X -->
  <string id="featureX/subProblemY" value="There was a with X when you did Y. Try not to do Y!"/>
   <string id="featureX/subProblemZ" value="There was another problem with X, regarding Z. Don't ever do Z!"/>
   
   </strings>
   

Now your JavaScript files can refer to these translatable strings by calling the dw.loadString() function, as shown in the following example:

function initializeUI() 
{
   ... 
   if (problemYhasOccured)
   {
     alert(dw.loadString("featureX/subProblemY");
   }
}

You can use slash (/) characters in your string identifiers, but do not use spaces. Using slashes, you can create a hierarchy to suit your needs, and include all the strings in a single XML file.

Localizable Strings with Embedded Values

Some display strings have values embedded in them. You can use the errMsg() function to display these strings. You can find the errMsg() function, which is similar to the printf() function in C, in the string.js file in the Configuration/Shared/MM/Scripts/CMN folder. Use the placeholder characters percent sign (%) and s to indicate where values should appear in the string and then pass the string and variable names as arguments to errMsg(). For example:

<string id="featureX/fileNotFoundInFolder" value="File %s could not be found in folder %s."/>

The following example shows how the string, along with any variables to embed, is passed to the alert() function.

if (fileMissing) 
{
  alert( errMsg(dw.loadString("featureX/fileNotFoundInFolder"),fileName, folderName) );
}
5. Working with the Extension Manager | Next Section Previous Section