1
votes

I am xpages enabling an old Notes application which is using profile documents to store translated labels. The translated lables in the notes form are read from the profile document using @GetProfileField depending on which language the user have selected in their profile.

I have read that profile documents are not recommended to use with xpages so I need a better solution for my xpages users. but it is important that users using Notes client still use the "old" profile document solution.

How can I provide these translation lables to my xpages users?

Thanks Thomas

3

3 Answers

1
votes

You can use profile documents for this use case as the content gets changed only with new versions of your project probably. So, you can easily live with profile document's caching.

You get the label translation from a profile document with

var doc = database.getProfileDocument("LabelsEnglish", "");
var label = doc.getItemValueString("label1");
doc.recycle();
return label; 

You could read all labels in an application scope variable Map too and do your own caching. This way profile documents would get read only once.

if (!applicationScope.labels) {
    var map = new java.util.HashMap();
    var doc = database.getProfileDocument("LabelsEnglish", "");
    var allItems = doc.getItems();
    for (var i = 0; i < allItems.size(); i++) {
        var item = allItems.elementAt(i);
        item.getName();
        map.put(item.getName(), item.getValueString());
        item.recycle();
    }
    doc.recycle();
    applicationScope.labels = map;
}

Execute the SSJS code above in a custom control which is included in every XPage (e.g. application layout custom control) in before page load event so you can be sure application scope variable "labels" is initialized when you want to use it. You can access the labels easily with EL

 applicationScope.labels.label1
2
votes

In addition to Knut's answer there is also the option to "double" your translated labels via the way to prefer in XPages dev by using the localization options as described here: http://www-10.lotus.com/ldd/ddwiki.nsf/dx/UsingLocalizationOptions.htm

2
votes

You need to split the task into two. First have a function that is called inside the XPage to get the label you are looking for, secondly have a way to provide that value inside the function.

Making a direct call to the profile isn't a good idea since it fixes the way you provide the data (besides potentially creating a memory leak if you don't recycle dilligently). I would see 4 potential solutions:

  1. Define your profile document as additional data source and simply bind the labels to items in the document. Saves you most of the recycling work, but couples tight

  2. Use a SsJS function: getLabel(name). It would check for a scope variable (a Map) and if not found load it - currently from your profile. If application scope is good enough, you touch the profile once only- speed. If you change the loader later on - you don't need to change anything in the XPage.

  3. Use a managed bean. Same approach as #2, only now you can use el data binding. Your bean needs to implement Map

  4. If the labels hardly change do a design time conversion and write the profile doc out into properties files (works nicely with ODP) and use XPages internal mechanism for internationalization

Let us know how it goes