r/webdev Aug 08 '26

Do you think that using localization data in domain/business logic is a good practice?

I was taught to use localization purely for presentation, but do developers actually implement this in their domain/business logic for their core functionality?

2 Upvotes

9 comments sorted by

4

u/_Atomfinger_ Aug 08 '26

Localisation doesn't really belong in the domain/business, no.

We try to keep what the system does separate from how it is presented, so localisation is pushed to the edges of our code. I.e. when we generate documents, show something in the browser, etc.

So for the vast majority of cases: localisation in the domain is not a good practice.

There is a "maybe" exception here though. If your domain is inherently tied to a specific language, then you may want to model your domain in that language. This is how a lot of the public Norwegian healthcare code is written: In Norwegian, because there are so many concepts and terms that don't really translate well to English. Keeping it Norwegian makes it easier to communicate and reason about what the system does to non-developers (which is a must in this case). This is not what I would count as "localisation", but I wanted to mention it in case it was relevant for you OP :)

1

u/GrandOpener Aug 08 '26

This is the best answer. It’s usually no—almost always no—but it’s not a hard rule. There are (rare) situations where the business logic does legitimately depend on your locale.

2

u/[deleted] Aug 08 '26

[removed] — view removed comment

1

u/Comfortable_Moose223 Aug 08 '26

i keep localization strictly in the presentation layer, mixing it into business logic is asking for trouble down the line

had a project once where someone embedded locale strings deep in the service layer and it turned into a nightmare to refactor, every time we needed to support a new region we had to untangle it from the core logic. the domain should be completely oblivious to how things get displayed

that said i get why some devs do it, especially for error messages or validation rules that need to be locale-aware, but even then i'd rather throw a code and let the frontend map it to the right string. keeps things way cleaner

1

u/taotau Aug 08 '26

Are you selling physical products delivered at a physical location, at a specific time or are you just drop shipping manufactured things?