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

com.github.gustavovitor.util.MessageUtil Maven / Gradle / Ivy

package com.github.gustavovitor.util;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

import java.text.MessageFormat;
import java.util.Locale;

@Configuration
public class MessageUtil {

    public static String getMessage(String code, String... parameters) {
        return MessageFormat.format(messageSource().getMessage(code, null, Locale.getDefault()), parameters);
    }

    @Bean
    public static MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("messages");
        messageSource.setDefaultEncoding("UTF-8");
        messageSource.setCacheSeconds(1);
        return messageSource;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy