21

I'm storing some nodes in Neo4j graph database and each node has property values that can be localized to various language. Is there any best practice for storing multi-language property values?

Stanley
  • 5,057
  • 4
  • 34
  • 44

1 Answers1

18

There are couple of ways to model this. Which one is the best, depends on your use case and the way you want to use i18n-ized properties. I'm sketching some examples below assuming n is a node that should have it's productName and color property translated in various languages. Gonna use Cypher-like notation below.

1) storing all translations with the node.

CREATE (n {
productName:'default', color:'default',
productName_en:'engl.prod.name', color_en:'red',
productName_fr:'fr.prod.name', color_fr:'rouge',
})

You apply a naming convention and use <propertyName>_<lang> for the i18n-ized variants. This approach is simplistic and not really graphy.

2) have a subnode per language and entity, indicate the language by relationship type:

CREATE (n {productName:'default', color:'default'}),
(n)-[:TRANSLATION_EN]->({productName: 'engl.prod.name', color:'red'}),
(n)-[:TRANSLATION_FR]->({productName: 'fr.prod.name', color:'rouge'})

So you have 1 additional node and 1 additional rel per language. In Neo4j 2.0 you might additionally indicate the translation nodes with a label indicating the language. By this you can easy extract a list of all text in language xyz.

3) just like 2) but use a generic relationship type TRANSLATION with a property on it indicating the language.

There are couple of more approaches, e.g. you can theoretically use array properties as well. As said, there is no silver bullet, it depends on your use case and requirements.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97