Deutsche-Digitale-Bibliothek/ddblabs-publicdomaincalculator

Problem with i18n implementation and MongoDB

Closed this issue · 5 comments

There is a problem with the i18n implementation and the DataBase. The DataBase (if enabled) stores the trace of a result. But if the DB stores a trace in englisch-language for a specific ID and later the PDCController gets a request for the same ID, but for a different language (i.e german language), then it will be returned the result from the DB in the wrong language.
So one solution is to implement the "translastion" in the PDCController and not in the answerer-classes, like the suggestion from phil-fuber in #72 .

Is there any other suggestions to solve this problem ?

The easiest way is to store only the language keys in the db and transform it in the PDCController. In this case the anserers return only the keys not plain text.

Thats a good approach.
But I have noticed that there is an extra problem when the "translation" takes place in the PDCController. A few answerer classes return a note as string, which is composed of multiple strings with multiple values, for example: https://github.com/DenniJensen/ddb-pdc/blob/master/src/main/java/de/ddb/pdc/core/answerers/AuthorFromTriptisAnswerer.java .
That means the "translation" or "transformation" in the PDCController is even more complicated than expected.
This can be solved by using pattern matching or by define flags to separate which part is a key and which is a value. Both approaches dont sound good for me.

This problem can solve with the MessageFormat of Java, because in your example you only need the author name and nationality is saved in db.
Your save your strings with parameters and format the String with the author and nationality with the Java MessageFormat http://docs.oracle.com/javase/6/docs/api/java/text/MessageFormat.html

String str = "Author {0} is from {1} which is not part of the Berne Triptis WCT. ";
String result = MessageFormat.format( str ,author.getName() , author.getNationality());

If you implement this, create a new class which the PDCControler call for transformation :-)

This is definitely a better solution.
But the DB-Model have to change, because unfortunately data like author, nationality or year are not stored. Only the title, subtitle, category, institution, the trace (questions and answers) and a boolean (isPublicdomain) are stored in the DB.

Obsolete