Search in sources :

Example 1 with TranslationSource

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);
    }
}
Also used : IMsgBL(de.metas.i18n.IMsgBL) TranslationSource(de.metas.ui.web.view.descriptor.annotation.ViewColumn.TranslationSource) ToString(lombok.ToString) ITranslatableString(de.metas.i18n.ITranslatableString) IAttributeDAO(org.adempiere.mm.attributes.api.IAttributeDAO)

Aggregations

IMsgBL (de.metas.i18n.IMsgBL)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 TranslationSource (de.metas.ui.web.view.descriptor.annotation.ViewColumn.TranslationSource)1 ToString (lombok.ToString)1 IAttributeDAO (org.adempiere.mm.attributes.api.IAttributeDAO)1