Search code examples
scalaplayframeworkinternationalizationplay-framework-2.7

What's the preferred choice for data(base) i18n?


I'm working on a Scala Play 2.7 project and have a use-case for saving in the database data that needs i18n.

I have two design choices:

  1. Saving the data in the database using the language e.g. en as part of the key and do so for every supported language.
  2. Saving in the database keys that map to the Play messages and then have the corresponding supported translation for each key.

Downsides are e.g. for choice #1 the database needs to be updated for every new language supported; for choice #2 queries to the database need to be "decorated" looking up the corresponding translation for each key in messages.x


Solution

  • I would go with a 3rd option, store the translation key with the arguments required to render the message, it's up to you how to store those, it could be an array or a JSON.

    The database is updated only once per message, adding new languages only requires to update the messages files, and for rendering a message, you only need to do a single query which you would have done anyway, it just retrieves a bit more data.