Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

java - Clear architecture for implementation translation needs

I need help to choice logic decision for implementing translation some fields of entity.

I have:

  • Entity Product
Product {
 String title;
 String manufacturer;
 String productType;
 // e.t.c.
}
  • Several different DTOs - used for interaction with UI and services
ProductUIDto {  
  String title;  
  //... 
}


NotifyDto {
  String productTitle;
  String someLocalizedField;
  //...
}

PrintDto {
  String productTitle;
  String someLocalizedField;
  //....
}

The existing implementation contains some localization logic. Translations ones fields stored in DB, another (types etc.. - static data) - in resource files, translations of thirds - we compute by own algorithms.

So, for each DTO we have mapper-converter, which our Product Entity converts to it.

ProductUIConverter {

  LocalizationServise l10nService;

  ProductUIDto convert(Product product) {
    ProductUIDto dto = new ProductUIDto();
    dto.title = l10nService.translateTitle(product.title);
    //... for all fields, needs to be translated we get transation from LocalizationServise
  }

}

So, we have tens "smart" converters. When we get a task to localize new property - we implements logic in l10n service (new method) and add execution it in each converter.

Is it a problem or not, that our converters were involved in localization logic? How we can (if should) to distinct this logic from mapping correctly?

Thanks a lot!

question from:https://stackoverflow.com/questions/65949542/clear-architecture-for-implementation-translation-needs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...