See: Description
Interface | Description |
---|---|
TranslationService |
Provides methods to retrieve translated Messages in a
Messagegroup and to replace Message tokens with values. |
TranslationsReadRequest |
Provides methods to retrieve information about what Messages to read.
|
TranslationsReadRequestBuilder |
Provides methods to build
TranslationsReadRequest objects. |
TranslationsReadResponse |
Provides methods to retrieve translated Messages.
|
public String readMessage(String messageGroupName, String messageName, String languageCode) {
// Locate TranslationService
TranslationService translationService = ServiceLocator.locate(TranslationService.class);
// Build the request
TranslationsReadRequest readRequest = translationService.newTranslationsReadRequestBuilder()
.withMessageGroup(messageGroupName)
.withMessages(VaultCollectionsUtils.getVaultCollections().asList(messageName))
.withLanguage(languageCode)
.build();
// Read the message
return translationService.readTranslations(readRequest)
.getTranslations()
.get(messageName);
}
Messagegroup
:
public Map<String, String> readAllMessages(String messageGroupName, String languageCode) {
// Locate TranslationService
TranslationService translationService = ServiceLocator.locate(TranslationService.class);
// Build the request
TranslationsReadRequest readRequest = translationService.newTranslationsReadRequestBuilder()
.withMessageGroup(messageGroupName)
.withLanguage(languageCode)
.build();
// Read all messages
return translationService.readTranslations(readRequest).getTranslations();
}
public String getInvalidEmailAddressError(String emailAddress, String languageCode) {
// Locate TranslationService
TranslationService translationService = ServiceLocator.locate(TranslationService.class);
// Read the message and assume the message reads "${email_address} is invalid."
String message = readMessage("person_validation__c", "invalid_email_address__c", languageCode);
if (message == null) {
message = "${email_address} is invalid.";
}
// Format the message with token(s)
Map<String, String> map = VaultCollectionsUtils.getVaultCollections().newMap();
map.put("email_address", emailAddress);
return translationService.formatTranslation(message, map);
}
Copyright © Veeva Systems 2017–2021. All rights reserved.