We're using stack of Angular 8, Spring 5, PostgresDB to build a web app which is available in multiple languages.
Our app is highly data based - all the forms fields definitions, dropdowns dictionaries values and so on are kept in a database.
So far in our data tables we've been using only the sorting on the client side, now we're moving it to the backend side as we're implementing the data pagination.
All the translations we keep in a json file - so that the translation values are available under keys like x.y.z.en
/ x.y.z.fr
etc.
The act of translation is done on the client side.
The table has such translation keys as one of its columns values.
So until now, we were sorting the translated values on the client side - it was easy. However, on the server side we don't have the values, only the keys. And we can't sort by keys, as for each language the translated values alphabetical order would be different.
We're thinking about what kind of approach shall we take. So far we've come up with:
1) Add translations to DB records - new column for each supported language.
Although this is the simplest solution, this creates a redundancy of data (as the translations are both in the json file and DB). This also means some additional work for each table that we've developed so far (with the client side sorting) - so let's assume we're looking for a better solution.
2) (Dirty and complicated) Pass the list of sorted keys with the query
- on the client side sort the keys according to their values in a currently used language In a form of a map [translation key => order no.]
{
'x.y.a': 2,
'x.y.b': 3,
'x.y.c': 1,
}
- pass the sorted list with other request parameters
- using JPA Formula and HibernateInterceptor substitute the keys with order no. in the onPrepareStatement https://stackoverflow.com/a/43636689/1913596
This is quite complicated and rather inefficient approach.
What other solutions would you recommend ? We'd be very grateful for your opinions.