Luan O'Carroll - 2006-02-09

To load the contents of a file into say the content attribute of a label:

        <Components>
...
            <ScrollPane x="10" y="50" w="600" h="250" style="base/info" border="0" vertical_scrollbar="as needed" horizontal_scrollbar="never">
              <Label x="10" y="50" w="600" h="400" content="${getExtraText(terms)}" style="base/info"/>
            </ScrollPane>
...
        </Components>

the evaluated attribute is then implemented as:

  /**
   * Get the text for a popup from an extra file
   */
  public String getExtraText( String fileName )
  {
    Preferences rsPrefs = Preferences.userNodeForPackage( Welcome.class );
    String defLangCode = rsPrefs.get( "defaultLanguage", "en" );
    String filePath = defLangCode + File.separator + fileName + ".html";
    try {
      Reader r = project.getBufferedReader( filePath );

      StringBuffer text = new StringBuffer();
      int BUF_LEN = 1024;
      int len = -1;
      char buffer[] = new char[ BUF_LEN ];
      while (( len = r.read( buffer, 0, BUF_LEN )) >= 0 )
        text.append( buffer, 0, BUF_LEN );
      return text.toString();
    }
    catch ( Exception e )
    {
      e.printStackTrace();
    }
    return translate( "Missing resource" );
  }

the file "terms.html" is then loaded from the resources/en folder where en is the default language. The content can then be localized by adding separate subfolders for each translation