use of de.metas.ui.web.view.descriptor.annotation.ViewColumn.TranslationSource in project metasfresh-webui-api by metasfresh.
the class ViewColumnHelper method extractCaption.
private static ITranslatableString extractCaption(@NonNull final Field field) {
final ViewColumn viewColumnAnn = field.getAnnotation(ViewColumn.class);
final String captionKey = !Check.isEmpty(viewColumnAnn.captionKey()) ? viewColumnAnn.captionKey() : extractFieldName(field);
final TranslationSource captionTranslationSource = viewColumnAnn.captionTranslationSource();
if (captionTranslationSource == TranslationSource.DEFAULT) {
final IMsgBL msgBL = Services.get(IMsgBL.class);
return msgBL.translatable(captionKey);
} else if (captionTranslationSource == TranslationSource.ATTRIBUTE_NAME) {
final IAttributeDAO attributesRepo = Services.get(IAttributeDAO.class);
return attributesRepo.getAttributeDisplayNameByValue(captionKey).orElseGet(() -> TranslatableStrings.anyLanguage(captionKey));
} else {
logger.warn("Unknown TranslationSource={} for {}. Returning the captionKey={}", captionTranslationSource, field, captionKey);
return TranslatableStrings.anyLanguage(captionKey);
}
}
Aggregations