Search code examples
translationxpagesresourcebundlelotusscript

How to use xPages translation files from Lotusscript and SSJS libraries


I am using resource bundles to translate all my xpages into different languages. this works great for translating labels etc in xPages.

I do however have Lotusscript agents and server side javascript code in the database that send mail to users and I want these emails to also be translated using the translation files.

so my question is simple. is it possible to read the translation files from SSJS scriptlibraries and Lotusscript agents. If so please let me know how?

Image below show all my translation files, one for each language.

string_*.properties

enter image description here


Solution

  • In SSJS you can access the property files with getResourceAsStream method.

    var data = "";
    var ex = facesContext.getExternalContext();
    var io:java.io.InputStream = ex.getResourceAsStream("strings_en.properties");
    
    var i;
    do{
       i = io.read();
       data += @Char(i)
    }while( i != (-1) ) 
    

    The variable data contains now the whole *strings_en.properties file.

    An example to load the properties directly in a java.util.Properties instance can be found here:

    http://openntf.org/XSnippets.nsf/snippet.xsp?id=access-.properties-files

    In LS it is more complicated:

    1. You need a lookup view for the design elements, with the field $FileNames as key
    2. This allows you to search for the property file.
    3. Then you can export the design document with dxl
    4. In the exported DXL, you have to search for the $FileData item
    5. In the item there is the BASE64 encoded property file
    6. Decode it, skip the first 30 characters (header informations like size of the RT)
    7. Parse it line by line