Introduction:
If you need to support multiple languages within your SDK error dialogs or your object record creation/detail or list pages then you will find the Translation Service, Message Catalog and the new PicklistRequestBuilder Interface to be useful. The Translation Service along with the Message Catalog can be used to retrieve translated message text to use in your SDK error dialogs or to better localize the object record creation, detail and list pages. Additionally, starting in 20R2.4, the new PicklistRequestBuilder Interface can be used to fetch picklist labels in the user’s language. These labels can then be used to accomplish various tasks such as displayed in error messages, used with SDK services etc.
To get started with multiple language support, message groups must be created in the Message Catalog which can be found under Admin --> Configuration --> Vault Java SDK. The translations must then be loaded into the vault using the Bulk Translation tool in the desired language(s). This tool allows the user to import and export translations and can be found in Admin --> Settings --> Language & Region Settings.
In the following example, we will demonstrate how to use the new Picklist Service methods and the PicklistRequestBuilder Interface to fetch translated Picklist labels. For this example, we will create an object called ‘Picklist Sample Object’ with a field called Colour picklist. This can be done by going to Admin --> Configuration --> Objects and clicking on the Create button in the top right corner. The Colour picklist should have the following three options: Red, Green and Blue. The translated picklist labels will be displayed in error dialog along with a translated error message. Next, we will load the translations using the Bulk Translation tool. To do this, the export translation file of field labels must be exported and updated. The translation for our picklist values must be added to the column for Translated Label(Column F) as shown in the following screenshots.
Next, to fetch the picklist values in our record trigger, we must use the new PicklistRequest.Builder interface to build the Picklist Request, this new interface allows developers to fetch the translated picklist values. If no translation is available, then the value will be returned in the language that the vault is configured in.
TranslationService translationService = ServiceLocator.locate(TranslationService.class);
// Build the request to fetch our message group
TranslationsReadRequest readRequest = translationService.newTranslationsReadRequestBuilder()
.withMessageGroup("picklist_error__c")
.build();
// Read all messages in the group
Map<String, String> allErrorMessages = translationService.readTranslations(readRequest).getTranslations();
// Used to fetch picklist values
PicklistService picklistService = ServiceLocator.locate(PicklistService.class);
PicklistRequest.Builder requestBuilder = picklistService.newPicklistRequestBuilder();
PicklistRequest request = requestBuilder.withName("colour__c").build();
Picklist coloursPicklist = picklistService.getPicklist(request);
recordTriggerContext.getRecordChanges().forEach(recordChange -> {
// Get list of colour values
List colourValues = recordChange.getNew().getValue("colour__c", ValueType.PICKLIST_VALUES);
....
// Get single-picklist value name selected by user
String colourPicklistValueName = colourValues.get(0);
// Get picklist value label in user's language
colourLabel = coloursPicklist.getPicklistValue(colourPicklistValueName).getLabel();
String errorTitleTranslation = allErrorMessages.get("error_title__c");
String errorTranslation = allErrorMessages.get("error__c");
recordChange.setError(errorTitleTranslation, errorTranslation + colourLabel);
}
}
As can be seen in the above code snippet, the name of the desired picklist is specified using the withName method of the PicklistRequest.Builder interface. When a specific value’s label is fetched from the picklist using the getPicklistValue or the picklist’s label is fetched using getLabel, they will be fetched in the user’s language. In this case that happens to be French. For example, if the user selects the Red option(Rouge in French) when creating a record, the following will be displayed in the error dialog as shown below.
In summary, the Message Catalog, Translation Service and the new PicklistRequest.Builder interface will help you better localize Vault to your user’s needs. The new PicklistService features are available as new methods so as to not affect existing SDK extension code that interacts with picklists. If developers do not update their existing code to use these new methods or add the translations, the labels will be fetched in the vault’s base language. However, these new methods can be useful to help developers localize their vault error messages and improve their user experience for the end-users. Additionally, you may find the Translation Service Sample Project to be useful.
Vault Help Documentation:
Send us your feedback: We are always looking for feedback to help improve our Knowledge Base! Please let us know if this article is helpful or provide feedback on how we can improve your experience by clicking here.