package com.fzm.mall.customer.service.config.i18n;

import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;

/**
 * @author lyz
 * @mail lyz@disanbo.com
 * @create 2021/1/25 17:12
 * @description
 */
@Component
public class MallMessage implements MessageSourceAware {

    private static MessageSource messageSource;

    @Override
    public void setMessageSource(@NotNull MessageSource messageSource) {
        MallMessage.messageSource = messageSource;
    }

    public static String getMsg(String msgKey){
        return messageSource.getMessage(msgKey, null, LocaleContextHolder.getLocale());
    }
}
