5

Imagine a backend service modeled by a hexagonal architecture, where the domain has a class modeling, let us say, a Step of a creative flow that a mobile app will use:

class Step(
    val stepId: String,
    val description: String
)

The description should come to the client translated according to the User preferences. Nope, the client won't explain it. It expects it told already.

Here is the question: how would you model the translation? There are several ways of course, but I want your opinion on it.

For instance: I could set the description with a default language, and then I could perform a translation on the infrastructure level when returning the Step. But this way, I wouldn't make explicit it on a domain level.

Christophe
  • 74,672
  • 10
  • 115
  • 187
Bertuz
  • 417
  • 4
  • 10

1 Answers1

4

The multilingual aspect is a requirement that should be included in the domain model.

Multilingualism raises a couple of other questions such as for example:

  • are users supposed to maintain data in several languages when they create/update a step ?
  • is one main language mandatory and others optional ?
  • which language to use when the user’s desired language is missing ?
  • are there other areas in which language may matter ? For example, could steps be included in automatic emails to third parties (e.g. subcontractor, customer, ...) who speak another language than the user who is triggering the message ? (i.e. the preferred language would not only have to be managed for the users, but also for other entities).

Typically the multilingual text would be part of an aggregate that includes the step:

  • either the Step would keep the description for the system’s default language and translation in different languages would be maintained in a separate entity.
  • or all the descriptions are extracted from the Step entity and moved into a multilingual StepDescription entity.
  • or you could consider the multilingual descriptions (i.e.language code+text) as a value object owned by the step.
Christophe
  • 74,672
  • 10
  • 115
  • 187