[DEPRECATED] Preferred language

Deprecated at least since 4.3

The documentation below is deprecated at least since Datafari 4.3

Starting with Datafari 3.2.0, user's preferred language is now automatically saved and applied when a user connects to Datafari or changes the language.
The language info is stored in the 'lang' table of the Cassandra database. This architecture follows the logic that was implemented by the 'Likes and Favorites' feature.

The 'lang' table is composed of two columns:

  • username : varchar - it is the PRIMARY KEY of the table and represents the username returned by the Tomcat session.

  • lang : varchar - represents the lang code that the user has selected ("en", "fr" ...)

The preferred language is saved/applied in several cases :

1) User connection

When a user successfully authenticates himself through the 'login.jsp' page, he is redirected by the jsp code to the servlet 'applyLang' (GET HTTP method). The servlet class is 'com.francelabs.datafari.servlets.ApplyUserLang'. 
The servlet try to find a corresponding entry in the 'lang' table of the Cassandra database thanks to the username. Two possibilities :

  • No entry is found in Cassandra : the servlet creates a new entry with the default selected language which will be the new preferred language of the user. After this, the servlet redirects to the admin page with the default language.

  • An entry is found for the provided username : In that case the servlet redirects to the admin page and forces the language retrieved in Cassandra.

2) User changes the language

When a user changes the language of Datafari, an ajax call with a HTTP POST method is done to the 'applyLang' servlet with the selected language as POST data. The servlet simply creates/updates the username entry (if the user is authenticated in Datafari) with the provided language in the 'lang' table of Cassandra

3) Language keeper

The 'main.js' script has been updated to ensure that the 'lang' parameter provided by the url corresponds to the preferred user language.
To do so, an ajax call with a HTTP GET method is performed to the 'applyLang' servlet to retrieve the user preferred language. Two possibilities :

  • The returned language corresponds to the one provided as a GET parameter : everything is OK, no further treatments.

  • The returned language does not correspond to the one provided in the url as a GET parameter : the preferred language is forced through a new call to the 'applyLang' servlet which will redirect to the current page with the correct language.