There are many options for adding multi-language support through Spring Data Neo4j.
One approach, outlined in https://graphaware.com/neo4j/2016/09/29/internationalization-with-spring-neo4j.html (and authored by me), may give you a head start on implementing your solution.
After following the blog’s set up and configuration for your SDN project, for each of your Value
objects you could use Cypher to define two MessageDefinitions
, one with a code that matches the Value.value
and another who’s code matches the Value.description
. Going this route, you are essentially adding extra nodes (i.e.: MessageDefinition
nodes) that are associated with a Value
node that represent the value and description with an internationalized and localized message. In other words, the Value
’s value and description properties serve as keys to corresponding MessageDefinition
nodes.
With your project configured and desired MessageDefinitions
defined in your Neo4j, you could use the following code in a controller or service to obtain your internationalized and localized values:
Value value = valueRepository.findOne(id);
Object arguments[] = new Object[] {};
Locale locale = LocaleContextHolder.getLocale();
String valueMessageKey = value.getValue();
String i18Value = messageSource.getMessage(valueMessageKey, arguments, "defaultValue", locale);
String descriptionMessageKey = value.getDescription();
String i18Description = messageSource.getMessage(descriptionMessageKey, arguments, "defaultDescription", locale);
System.out.println("i18Value: " + i18Value);
System.out.println("i18Description: " + i18Description);
It’s worth noting that a weakness of this approach is that the MessageDefinition
and Value
objects are related through a matching node property, rather than an underlying Neo4j relationship, which is less efficient as it doesn’t take advantage of Neo4j’s core strength (ie: relationships). While this is something to be aware of, if it’s an actual issue or not is dependent on your use cases. If it is a deal breaker, the CypherMessageSource project could be modified to more closely match your requirements.
Looking at your sample code, please note that you may want to change the type of your Value.value property from Object to String so as to ensure that it is a reliable key.