All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.it.commons.nls.NlsTools Maven / Gradle / Ivy

package com.sap.it.commons.nls;

public class NlsTools {

    private NlsTools() {
    }

    public static NlsResourceBundle createNlsResourceBundle(final String baseName, final Class hostClass) {
        return NlsResourceBundleImpl.createAndInitialize(baseName, hostClass);
    }

    public static TranslatableText getAnnotatedTranslatebleText(Enum instance) {
        try {
            return instance.getDeclaringClass().getField(instance.name()).getAnnotation(TranslatableText.class);
        } catch (Exception e) {
            return null;
        }
    }

    public static String getAnnotatedTranslatebleTextValue(Enum instance) {
        TranslatableText tt = getAnnotatedTranslatebleText(instance);
        return tt != null ? tt.value() : null;
    }

    public static TranslatableText getAnnotatedTranslatebleText(Object instance) {
        if (instance instanceof Enum) {
            return getAnnotatedTranslatebleText((Enum) instance);
        } else {
            return instance.getClass().getAnnotation(TranslatableText.class);
        }
    }

    public static String getAnnotatedTranslatebleTextValue(Object instance) {
        TranslatableText tt = getAnnotatedTranslatebleText(instance);
        return tt != null ? tt.value() : null;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy