How to define an entity with translations using DDD

Viewed 1655

I have a small application using Domain Driven Design and now I would like to have an entity with translations.

I have read on the internet that the best practices in Domain Driven Design is to separate the translations from the model but I don't know how to do it.

Here an example of what I have:

@Entity
class Product {
    @Id
    private String id;
    private String name;
    private String description;
    private BigDecimal price;
    private BigDecimal originalPrice;

    ...
}

@Service
class ProductService {

    @Autowired
    private ProductRepository productRepository;

    public List<Product> getAll() {
        return productRepository.findAll();
    }

    public List<Product> getById(String id) {
        return productRepository.findById(id);
    }

    public List<Product> create(ProductDto productDto) {
        Product product = new Product(
            productDto.getName(),
            productDto.getDescription(),
            productDto.getPrice(),
            productDto.getOriginalPrice()
        );
        return productRepository.save(product);
    }
}

Then my questions are:

Imagine I am receiving the translations in the product DTO and I would like to know how to do it.

Thanks and appreciate your help.

2 Answers
Related